-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.py
95 lines (77 loc) · 2.52 KB
/
sync.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
from shutil import rmtree
from secureAuth import Auth
from syncDirectory import Synchronizer
from myParser import Parser
DEFAULT_music_folder = "/MEDIA/Music/"
DEFAULT_local_folder = "D://Music/"
DEFAULT_GROUPNAME = "DEFAULT"
DEFAULT_FOLDER = "smb"
DEFAULT_SERVICE_NAME = "musicSMBsync"
DEFAULT_PORT = 139
def print_genders(genders):
for gender in genders:
print(gender)
def show_server(server):
if server is False:
print("Connection failed check for username and password")
exit(0)
else:
print(server)
def remove_folder(name):
rmtree('{}/{}'.format(Synchronizer.TMP_FOLDER, name))
def main():
parser = Parser()
args = parser()
if args.port is None:
port = DEFAULT_PORT
else:
port = args.port
if args.local_folder is None:
local_folder = DEFAULT_local_folder
else:
local_folder = args.local_folder
if args.music_folder is None:
music_folder = DEFAULT_music_folder
else:
music_folder = args.music_folder
if args.group is None:
group = DEFAULT_GROUPNAME
else:
group = args.group
if args.service_name is None:
service_name = DEFAULT_SERVICE_NAME
else:
service_name = args.service_name
if args.white_list is None:
white_list = []
else:
white_list = args.white_list
if args.black_list is None:
black_list = []
else:
black_list = args.black_list
authenticator = Auth(args.host, args.user, args.folder,
name=group,
password=args.password,
store_credential=args.store_password,
service_name=service_name,
port=port,
)
server = authenticator()
if not server.is_ready():
print("Can't connect to the server {}:{}".format(args.host, port))
exit(1)
show_server(server)
synchronizer = Synchronizer(server, local_folder, music_folder, white_list, black_list,
verbosity=args.verbose, remove_not_present=args.remove)
# Navigate to music folder
if args.verbose:
print("cd {}".format(music_folder))
genres = synchronizer.get_folders_name()
print_genders([genre['name'] for genre in genres])
synchronizer()
# Clear temp folder
Synchronizer.clean_temp()
if __name__ == '__main__':
main()
exit(0)