-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiCpy.py
60 lines (53 loc) · 1.61 KB
/
piCpy.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
# /import usb.core
# import usb.util
import dircache, io, os
from os import listdir
from os import path
from os import makedirs
from datetime import datetime
startTime = datetime.now()
base = '/media/'
volumes = dircache.listdir(base)
for vol in volumes:
if (vol != 'root'):
curr_path = base + vol + '/'
dest_dir = base + 'DEST/'
print dest_dir
if not os.path.isdir(dest_dir):
os.mkdir(dest_dir)
print "created directory %s" % dest_dir
files = listdir(curr_path)
if curr_path == "media/DEST":
files = []
for file_name in files:
srcfile = curr_path + file_name
if (path.isfile(srcfile)):
fd_read = io.open(srcfile, 'rb')
if (fd_read.name == "/media/SRC/._.Trashes"):
print "dont' do this"
else:
dest = dest_dir + '/' +file_name
dest_buf = open(dest, 'w+')
rbuf = io.BufferedReader(fd_read, 4096)
data = rbuf.read()
while (data):
dest_buf.write(data)
data = rbuf.read()
fd_read.close()
else:
print "don't touch Simba please!!!"
print(datetime.now() - startTime)
import re
import subprocess
device_re = re.compile("Bus\s+(?P<bus>\d+)\s+Device\s+(?P<device>\d+).+ID\s(?P<id>\w+:\w+)\s(?P<tag>.+)$", re.I)
df = subprocess.check_output("lsusb", shell=True)
devices = []
for line in df.split('\n'):
if re.match("USB High-Speed Bus", line):
print line
info = device_re.match(i)
if info:
dinfo = info.groupdict()
dinfo['device'] = '/dev/bus/usb/%s/%s' % (dinfo.pop('bus'), dinfo.pop('device'))
devices.append(dinfo)
print devices