-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_owner_password.py
85 lines (67 loc) · 2.28 KB
/
find_owner_password.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
import os
import logging
from xml.dom import minidom
from utils import db_way, copy_file
from utils import go_path
from tqdm import tqdm
logger = logging.getLogger('sccscript.findownerpassword')
def compare_attr(attr, value):
if attr == value:
return True
def get_attr(xml_obj, name):
attr = xml_obj.getElementsByTagName(name)
if attr:
return attr[0].getAttribute("Value"), name
def parse_cinema_xml(cinema, inp):
parse_xml = minidom.parse(cinema)
parse_xml.normalize()
owner, key = get_attr(parse_xml, "Owner") or get_attr(parse_xml, "OwnerPassword")
if compare_attr(owner, inp):
return key, os.path.dirname(cinema)
def input_owner_password():
while True:
arg = input("enter owner password: ").strip()
print()
if arg == "":
return
elif len(arg) != 5:
logger.info("Owner password must have an 5 digits, try again..")
print()
continue
return arg
def main_find_password(config):
inp = input_owner_password()
if not inp:
return
paths_list = db_way(config)
print()
logger.info(f'Finding {inp} in database, please wait...')
print()
count = 0
found_path = None
for path in tqdm(paths_list, ncols=74):
result = parse_cinema_xml(path, inp)
if not result:
continue
else:
key, found_path = result
print(f"\n\n{key}: {inp}\nPath: {os.path.abspath(found_path)}\n\n")
count += 1
if count == 0:
logger.info(f"There is no owner password <{inp}> in database!")
logger.info('Press <Enter> to return...')
input()
elif count == 1:
choice = input("Press <Enter> to copy files to the work dir")
if choice == '':
copy_file(os.path.join(found_path, r'Cinema.xml'), 'Cinema.xml')
copy_file(os.path.join(found_path, r'CinemaSettings.xml'), 'CinemaSettings.xml')
else:
logger.info('Copying files has been skipped')
choice = input('Press <Enter> to follow the path')
if choice == '':
go_path(found_path)
else:
logger.info('More than one owner password has been found in database!')
logger.info('Press <Enter> to return...')
input()