This repository has been archived by the owner on May 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scow-sync-start
executable file
·43 lines (36 loc) · 1.63 KB
/
scow-sync-start
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
#!/usr/bin/python3
'''
Start a file transfer asynchronously
'''
import os
import sys
from subprocess import Popen
import utils
from argsparser import ArgsParser
if __name__ == '__main__':
# 初始化保存日志的文件夹
SCOW_PATH = os.path.expanduser('~/scow')
if not os.path.exists(SCOW_PATH):
os.mkdir(SCOW_PATH, 0o700)
SCOW_SYNC_PATH = os.path.join(SCOW_PATH, '.scow-sync')
if not os.path.exists(SCOW_SYNC_PATH):
os.mkdir(SCOW_SYNC_PATH, 0o700)
OUT_PATH = os.path.join(SCOW_SYNC_PATH, 'scow-sync.out')
ERROR_PATH = os.path.join(SCOW_SYNC_PATH, 'scow-sync.err')
if not os.path.exists(OUT_PATH):
with open(OUT_PATH,'a',encoding='utf-8') as out:
out.write('This is the tranferring log for scow-sync\n')
os.chmod(OUT_PATH, 0o700)
if not os.path.exists(ERROR_PATH):
with open(ERROR_PATH,'a',encoding='utf-8') as err:
err.write('This is the error log for scow-sync\n')
os.chmod(ERROR_PATH, 0o700)
# 子进程执行scow-sync
args = ArgsParser().get_args_parser().parse_args()
cmd = f'scow-sync -a {args.address} -u {args.user} -s {args.source} -d {args.destination} -m {args.max_depth} -p {args.port} -k {args.sshkey_path}'
raw_string = f'{args.address} {args.user} {args.source} {args.destination}'
unique_id = utils.gen_file_transfer_id(raw_string)
if not os.path.exists(os.path.join(SCOW_SYNC_PATH, str(unique_id))):
os.mkdir(os.path.join(SCOW_SYNC_PATH, str(unique_id)), 0o700)
popen = Popen(cmd, shell=True, stdout=open(OUT_PATH,'a',encoding='utf-8'), stderr=open(ERROR_PATH,'a',encoding='utf-8'))
sys.exit()