-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
90 lines (79 loc) · 2.72 KB
/
Copy pathrun.py
File metadata and controls
90 lines (79 loc) · 2.72 KB
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
import atexit
from kleentimer import kleentimer
from kleenlogger import kleenlogger, KleenLogger
from duplicationdrivetos3.database_service import database
from duplicationdrivetos3.drive_service import drive
from duplicationdrivetos3.s3_service import s3
@atexit.register
def on_crash():
database.close_conn()
def parse_url(url: str):
url_temp = url.replace('https://drive.google.com/drive/', '')
if url_temp == "my-drive":
return "root"
else:
url_temp = url_temp.replace('folders/', '')
return url_temp
def prompt_user_for_info():
resume = input("Last session crashed ? (yes/no) : ").lower()
if resume == "yes":
return "resume"
database.create_table()
drive_type = input("Drive / Teamdrive ? : ").lower()
drive_url = parse_url(input("Drive URL : ").strip())
aws_key_id = input("AWS key id : ")
aws_key_secret = input("AWS key secret : ")
bucket_name = input("Bucket name : ")
user_input = {
'type': drive_type,
'url': drive_url,
'awskey': aws_key_id,
'awssecret': aws_key_secret,
'bucket': bucket_name
}
database.inject_config(drive_type, drive_url, aws_key_id, aws_key_secret, bucket_name)
return user_input
def main():
resume = False
config = prompt_user_for_info()
if config == "resume":
config = {}
inline_conf = database.get_config()
config['url'] = inline_conf[1]
config['type'] = inline_conf[0]
config['awskey'] = inline_conf[2]
config['awssecret'] = inline_conf[3]
config['bucket'] = inline_conf[4]
resume = True
kleenlogger.logger.info(
'The script run with following parameters : resume={}, url={}, awskey={}, awsSecret={}, bucket={}'.format(
str(resume),
config.get('url'),
config.get('awskey'),
config.get('awssecret'),
config.get('bucket')
)
)
kleentimer.start_timer()
s3.init_service(config.get('awskey'), config.get('awssecret'), config.get('bucket'))
drive.init_service()
drive.list_items(config.get('url'), None, resume, "")
size_uploaded = database.get_upload_size()
print(size_uploaded)
kleenlogger.logger.info(size_uploaded)
database.close_conn()
if __name__ == '__main__':
kleenlogger.init_logger(
"DuplicateToS3",
KleenLogger.DEBUG,
"[%(asctime)s][%(levelname)s] : [%(filename)s][%(funcName)s] : %(message)s",
"%Y-%m-%d %H:%M:%S",
"utf-8"
)
kleentimer.init_timer("The script has run for {hours}h {minutes}min and {secondes}sec")
main()
kleentimer.end_timer()
output = kleentimer.elapsed_time()
print(output)
kleenlogger.logger.info(output)
exit()