-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcallconfig.py
141 lines (109 loc) · 3.45 KB
/
callconfig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# F8ASB 2020
import configparser, os
import json
import sys
import getopt
svxlinkcfg='/etc/spotnik/svxlink.cfg'
Json="/etc/spotnik/config.json"
version="1.00"
call = " "
dept= " "
band = " "
usage=""
# lancement avec argument
def main(argv):
global dept
global call
global band
try:
options, remainder = getopt.getopt(argv, '', ['help', 'version', 'dept=', 'call=', 'band='])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in options:
if opt == '--help':
usage()
sys.exit()
elif opt == '--version':
print(version)
sys.exit()
elif opt in ('--dept'):
if arg != "":
dept=str(arg)
elif opt in ('--call'):
if arg != "":
call=(arg)
elif opt in ('--band'):
if arg != "":
band=str(arg)
Input_control(dept,call,band)
def Input_control(dept,call,band):
if dept==" " or call==" " or band==" ":
print(dept+call+band)
usage()
else:
#Mise en forme des calls
upcallsignSVX=(call)
upcallsignEL=( "EL-" +call)
upcallsignRRF=("(" +dept+ ") " +call+" "+band)
#Impression des calls
print(call)
print( call + "-EL")
print("(" +dept+ ") " +call+" "+band)
#MAJ dans les fichiers
updatecall(upcallsignSVX,upcallsignEL,upcallsignRRF)
updatecall_json()
def usage():
print('Usage: callconfig.py [options ...]')
print()
print('--help Cette aide')
print('--version Numéro de version')
print()
print('Parametrages:')
print()
print(' --dept nombre Entrer le numero de departement ex:88')
print(' --call texte Entrer votre indicatif ex:F1ABC')
print(' --band nombre Entrer la type acces (H,V,U,10M,R,T,T10M,S)')
print()
print('73 de F8ASB Juan')
#Fonction ecriture dans svxlink.cfg
def updatecall(callsignSVX,callsignEL,callsignRRF):
try:
from configparser import ConfigParser
except ImportError:
from ConfigParser import ConfigParser # ver. < 3.0
# instantiate
config = ConfigParser()
config.optionxform = str
# parse existing file
config.read(svxlinkcfg)
# lecture et maj
string_val = config.get('SimplexLogic', 'CALLSIGN')
config.set('SimplexLogic', 'CALLSIGN', callsignSVX)
# lecture et maj
string_val = config.get('LocationInfo', 'CALLSIGN')
config.set('LocationInfo', 'CALLSIGN', callsignEL)
# lecture et maj
string_val = config.get('ReflectorLogic', 'CALLSIGN')
config.set('ReflectorLogic', 'CALLSIGN', callsignRRF)
# Enregistrement
with open(svxlinkcfg, 'w') as configfile:
config.write(configfile, space_around_delimiters=False)
#Fonction ecriture dans config.json
def updatecall_json():
#lecture de donnees JSON
with open(Json, 'r') as f:
config = json.load(f)
config['callsign'] = call
config['Departement'] = dept
config['band_type'] = band
#ecriture de donnees JSON
with open(Json, 'w') as f:
json.dump(config, f)
if __name__ == '__main__':
try:
main(sys.argv[1:])
except KeyboardInterrupt:
pass