-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgphoto.py
56 lines (37 loc) · 1.29 KB
/
gphoto.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
import shlex
from subprocess import Popen, PIPE
import re
from time import sleep
import datetime
def cmd(c):
p = Popen(shlex.split(c), stdout=PIPE, stdin=PIPE, stderr=PIPE)
std_out, std_err = p.communicate()
return_code = p.wait()
# print std_out
if return_code != 0:
raise Exception('%s Err=%d >> %s' % (c, return_code, std_err))
return (return_code, std_out, std_err)
def camera_device():
list = cmd("lsusb")[1]
# list = '''Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
# Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
# Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
# Bus 001 Device 004: ID 04a9:3145 Canon, Inc.'''
for l in list.splitlines():
print l
m = re.match('.*?Bus (\d+) Device (\d+).*?Canon', l)
if m:
return '/dev/bus/usb/%s/%s' % (m.group(1), m.group(2))
def reset_device():
dev = camera_device()
if dev:
cmd('./usbreset ' + dev)
print 'reset: ' + dev
else:
raise Exception("Device not fount")
def capture():
reset_device()
cmd('gphoto2 --set-config capturetarget=1 --capture-image')
def capture_local():
reset_device()
cmd('gphoto2 --set-config capturetarget=0 --capture-image-and-download')