-
Notifications
You must be signed in to change notification settings - Fork 0
/
img_transfer.py
executable file
·121 lines (56 loc) · 2.23 KB
/
img_transfer.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"""
Version: 1.0
Function: Transfer images from cluster pis to PiContrller
Author: suxing liu
Author-email: [email protected]
USAGE
python3 img_transfer.py -p /home/pi/code/image_data/ -a 1
"""
import subprocess, os
import sys
import argparse
from os.path import relpath
def move_img(host_address):
#cmd_line = "ssh pi@" + ''.join(host_adr) + ' exit'
#cmd_line = "ls && ls -la"
cmd_line = "scp " + host_address + folder_path + "*.jpg " + folder_path
#cmd_line = "scp " + host_address + folder_path + "transfer.zip " + folder_path
#scp 192.168.1.110:/home/pi/code/cam/*.jpg .
print(cmd_line)
try:
#subprocess.call(cmd_line + [str(img_name)])
os.system(cmd_line)
print("Captured images were moved to PiController...\n")
except OSError:
print("Failed moving image!\n")
def delete_img(host_address):
host_add = host_address.replace(":", "")
#delete_cmd = " sudo rm -rf " + folder_path + "*.jpg "
delete_cmd = " sudo rm -rf " + folder_path
cmd_line = "ssh " + ''.join(host_add) + delete_cmd + " exit"
print(cmd_line)
try:
#subprocess.call(cmd_line + [str(img_name)])
os.system(cmd_line)
print( "Images on Pi01 were deleted...\n")
except OSError:
print("Failed moving image!\n")
def main(args):
#pasre paramters
ap = argparse.ArgumentParser()
ap.add_argument('-p', '--path', required = False, type = str, default = '/home/pi/code/image_data/', help = "image files path")
ap.add_argument('-a', '--action', required = True, type = int, help = '"1" is move files' + '"2" is delete files')
args = vars(ap.parse_args())
global folder_path
folder_path = args['path']
host_list = "[email protected]:"
#move file to PiController
if args['action'] == 1:
move_img(host_list)
elif args['action'] == 2:
delete_img(host_list)
delete_local = "sudo rm -rf " + folder_path
else:
print("Invalid action choice!\n")
if __name__ == '__main__':
sys.exit(main(sys.argv))