-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_val.py
176 lines (154 loc) · 6.15 KB
/
check_val.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import rclone
import re
from os.path import expanduser
import subprocess
import glob
import os, sys
import argparse
# nastavi poti do izvornih in odobrenih posnetkov na lokalnem disku in na strežniku nas.cjvt.si
izvorni_bkp = '/storage/rsdo/cjvt/BraniGovor/BraniGovor-04-FE-IzvorniPosnetki-bkp'
izvorni_nas_bkp = ':ASR/BraniGovor/BraniGovor-04-FE-IzvorniPosnetki-bkp'
odobreni = '/storage/rsdo/cjvt/BraniGovor/BraniGovor-05-FE-OdobreniPosnetki'
odobreni_nas = ':ASR/BraniGovor/BraniGovor-05-FE-OdobreniPosnetki'
odobreni_bkp = '/storage/rsdo/cjvt/BraniGovor/BraniGovor-05-FE-OdobreniPosnetki-bkp'
odobreni_nas_bkp = ':ASR/BraniGovor/BraniGovor-05-FE-OdobreniPosnetki-bkp'
class HiddenPrints:
def __enter__(self):
self._original_stdout = sys.stdout
sys.stdout = open(os.devnull, 'w')
def __exit__(self, exc_type, exc_val, exc_tb):
sys.stdout.close()
sys.stdout = self._original_stdout
ap = argparse.ArgumentParser(description = """
Primer klica funkcije:
python check_val.py -s FE-B-S0049 -g Artur-B-G0382 Artur-B-G0383 Artur-B-G0384 Artur-B-G0385 Artur-B-G0386 -n nas_cjvt -r
""")
ap._action_groups.pop()
required = ap.add_argument_group('required arguments')
optional = ap.add_argument_group('optional arguments')
required.add_argument('-s', '--snemalec',
type = str,
# ~ default = 'FE-B-S0049',
metavar = 'SNEMALEC',
help = "Snemalec (e.g. FE-B-S0049)."
)
required.add_argument('-g', '--govorci',
type = str,
nargs = '+',
# ~ default = ['Artur-B-G0382'],
metavar = 'GOVOREC',
help = "Lista govorcev (npr. 'Artur-B-G0382 Artur-B-G0383 Artur-B-G0384 Artur-B-G0385 Artur-B-G0386')."
)
optional.add_argument('-c', '--rclone_config',
type = str,
default = '~/.config/rclone/rclone.conf',
help = "Konfiguracijska datoteka za rclone ('/root/.config/rclone/rclone.conf' v primeru sudo rclone)."
)
optional.add_argument('-n', '--remote_name',
type = str,
default = 'CJVT',
help = "Ime rclone remote-a."
)
optional.add_argument('-r',
action='store_true',
help = "Argument s katerim vključimo preverjanje tudi na strežniku."
)
args = ap.parse_args()
snemalec = args.snemalec
govorci = args.govorci
with open(expanduser(args.rclone_config), 'r') as config_file:
config = config_file.read()
print('Snemalec %s:'%snemalec)
for g in govorci:
print('\tGovorec %s:'%g)
print('\t\tLokalni računalnik:')
sou_bkp_dir = os.path.join(izvorni_bkp, snemalec, g)
if os.path.isdir(sou_bkp_dir):
sou_bkp = len(glob.glob(os.path.join(sou_bkp_dir, '*')))
print('\t\t\t#%s: %d'%(sou_bkp_dir, sou_bkp))
else:
print("\t\t\tMapa %s ne obstaja."%sou_bkp_dir)
sou_bkp = -1
acc_dir = os.path.join(odobreni, snemalec, g)
if os.path.isdir(acc_dir):
acc = len(glob.glob(os.path.join(acc_dir,'*')))
print('\t\t\t#%s: %d'%(acc_dir, acc))
else:
print("\t\t\tMapa %s ne obstaja."%acc_dir)
acc = -2
acc_bkp_dir = os.path.join(odobreni_bkp,snemalec,g)
if os.path.isdir(acc_bkp_dir):
acc_bkp = len(glob.glob(os.path.join(acc_bkp_dir,'*')))
print('\t\t\t#%s: %d'%(acc_bkp_dir, acc_bkp))
else:
print("\t\t\tMapa %s ne obstaja."%acc_bkp_dir)
acc_bkp = -3
rej_dir = os.path.join(izvorni_bkp,snemalec,'ZavrnjeniPosnetki',g)
if os.path.isdir(rej_dir):
rej = len(glob.glob(os.path.join(rej_dir,'*')))
print('\t\t\t#%s: %d'%(rej_dir, rej))
else:
print("\t\t\tMapa %s ne obstaja."%rej_dir)
rej = -4
if acc == acc_bkp:
chk = 'OK'
else:
chk = 'ERR'
print('\t\t\t#odobreni = #odobreni_bkp ... %s'%chk)
if sou_bkp - acc == rej:
chk_bkp = 'OK'
else:
chk_bkp = 'ERR'
print('\t\t\t#izvorni_bkp - #odobreni = #zavrnjeni ... %s'%chk_bkp)
if args.r:
print('\t\tStrežnik %s:'%args.remote_name)
sou_nas_bkp_dir = os.path.join(args.remote_name+izvorni_nas_bkp,snemalec,g)
with HiddenPrints():
sou_nas_bkp = rclone.with_config(config).run_cmd(command='size', extra_args=[sou_nas_bkp_dir])
if not sou_nas_bkp['error']:
sou_nas_bkp = sou_nas_bkp['out'].decode('utf-8')
sou_nas_bkp = int(re.search(r'\d+', sou_nas_bkp).group())
print('\t\t\t#%s: %d'%(sou_nas_bkp_dir, sou_nas_bkp))
else:
print('\t\t\tNapaka pri branju %s: %s.'%(sou_nas_bkp_dir, str(sou_nas_bkp['error']).split('last error was:')[-1]))
sou_nas_bkp = -1
acc_nas_dir = os.path.join(args.remote_name+odobreni_nas,snemalec,g)
with HiddenPrints():
acc_nas = rclone.with_config(config).run_cmd(command='size', extra_args=[acc_nas_dir])
if not acc_nas['error']:
acc_nas = acc_nas['out'].decode('utf-8')
acc_nas = int(re.search(r'\d+', acc_nas).group())
print('\t\t\t#%s: %d'%(acc_nas_dir, acc_nas))
else:
print('\t\t\tNapaka pri branju %s: %s.'%(acc_nas_dir, str(acc_nas['error']).split('last error was:')[-1]))
acc_nas = -2
acc_nas_bkp_dir = os.path.join(args.remote_name+odobreni_nas_bkp,snemalec,g)
with HiddenPrints():
acc_nas_bkp = rclone.with_config(config).run_cmd(command='size', extra_args=[acc_nas_bkp_dir])
if not acc_nas_bkp['error']:
acc_nas_bkp = acc_nas_bkp['out'].decode('utf-8')
acc_nas_bkp = int(re.search(r'\d+', acc_nas_bkp).group())
print('\t\t\t#%s: %d'%(acc_nas_bkp_dir, acc_nas_bkp))
else:
print('\t\t\tNapaka pri branju %s: %s.'%(acc_nas_bkp_dir, str(acc_nas_bkp['error']).split('last error was:')[-1]))
acc_nas_bkp = -3
rej_nas_dir = os.path.join(args.remote_name+izvorni_nas_bkp,snemalec,'ZavrnjeniPosnetki',g)
with HiddenPrints():
rej_nas = rclone.with_config(config).run_cmd(command='size', extra_args=[rej_nas_dir])
if not rej_nas['error']:
rej_nas = rej_nas['out'].decode('utf-8')
rej_nas = int(re.search(r'\d+', rej_nas).group())
print('\t\t\t#%s: %d'%(rej_nas_dir, rej_nas))
else:
print('\t\t\tNapaka pri branju %s: %s.'%(rej_nas_dir, str(rej_nas['error']).split('last error was:')[-1]))
rej_nas = -4
if acc_nas == acc_nas_bkp:
chk_nas = 'OK'
else:
chk_nas = 'ERR'
print('\t\t\t#odobreni_nas = #odobreni_nas_bkp ... %s'%chk_nas)
if sou_nas_bkp - acc_nas == rej_nas:
chk_nas_bkp = 'OK'
else:
chk_nas_bkp = 'ERR'
print('\t\t\t#izvorni_nas_bkp - #odobreni_nas = #zavrnjeni_nas ... %s'%chk_nas_bkp)