-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
95 lines (78 loc) · 2.87 KB
/
utils.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
import os
import glob
import shutil
import logging
import subprocess
from re import search
from tqdm import tqdm
from re import fullmatch
logger = logging.getLogger('sccscript.utils')
def go_path(path):
proc = r'explorer.exe /n, {}'.format(path)
subprocess.run(proc, shell=True)
def check_input_date(func):
def wrapper(*args, **kwargs):
if kwargs['inp_date']:
if fullmatch(r'\d\d\d\d\d\d', kwargs['inp_date']):
return func(*args, **kwargs)
else:
logger.error(f'Enter {kwargs["key"]} date as <%d%m%y>, for example: 010199,\n'
'or press <Enter> to set default date ...')
print('---------------------------------------\n')
return
else:
logger.debug(f'Default value of {kwargs["key"]} date')
return kwargs['def_date']
return wrapper
def endless_cycle(func):
def wrapper(*args, **kwargs):
while True:
result = func(*args, **kwargs)
if result:
return result
else:
kwargs['inp_date'] = input(f'{kwargs["key"]} date: ')
return wrapper
def copy_file(get_file, set_file):
try:
shutil.copy2(get_file, set_file)
except FileNotFoundError:
logger.error(f'{get_file} has not been found')
logger.info('Press <Enter> to return...')
input()
except IOError:
logger.error(f'{get_file} has not been copied')
logger.info('Press <Enter> to return...')
input()
else:
logger.info(f'{get_file}\n has been copied to the work dir as {set_file}')
return True
def sign_compress(cmd, compress):
sign = subprocess.run(cmd, shell=False)
if sign.returncode == 0:
logger.info(f'{cmd} - OK')
code = subprocess.run(compress, shell=False)
if code.returncode == 0:
logger.info(f'{compress} - OK')
else:
logger.error(f'{compress} - FAIL')
logger.info('Press <Enter> to return...')
input()
else:
logger.error(f'{cmd} - FAIL')
logger.info('Press <Enter> to return...')
input()
def db_way(config):
iter_list = config['db_path'] + '\\*\\*\\**\\Cinema.xml'
iter_paths = glob.iglob(iter_list, recursive=True)
return [path for path in iter_paths if os.path.sep + 'old' not in path]
def find_string_in_db(paths_list, a_string):
logger.info(f'Finding "{a_string}" in database, please wait...')
uid_list_from_db = []
for path in tqdm(paths_list, ncols=74):
with open(path, 'r') as file:
read_obj = file.read()
uid_tmp = search(a_string, read_obj)
if uid_tmp:
uid_list_from_db.append(os.path.abspath(path))
return uid_list_from_db