-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathget_screenshots.py
More file actions
148 lines (120 loc) · 3.66 KB
/
get_screenshots.py
File metadata and controls
148 lines (120 loc) · 3.66 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#! /usr/bin/env python
import sys
import os
import glob
import getopt
import zipfile
import json
import subprocess
import shutil
help = """
get_screenshots.py
Captures screenshots from an already-build pbw (or series of pbw's) as
generated by make_all.sh, and stores them into resources/clock_faces.
get_screenshots.py [opts]
Options:
-b file.pbw[,file.pbw...]
Specifies the pbw or pbw's that will be used. The default is
build/rosewright_*.pbw.
-p platform[,platform...]
Specifies the build platform. The default is all platforms
supported by the named pbw's.
"""
def usage(code, msg = ''):
print(help, file=sys.stderr)
print(msg, file=sys.stderr)
sys.exit(code)
watches = {
'Rosewright A' : 'a',
'Rosewright B' : 'b',
'Rosewright C' : 'c',
'Rosewright Chronograph' : 'c2',
'Rosewright D' : 'd',
'Rosewright E' : 'e',
}
def send_pebble_command(*args):
args = ['pebble'] + list(args)
status = subprocess.call(args)
if status == 0:
return True
print("Command failed: %s" % (args,))
return False
def get_screenshots_for_platform(pbw, id, platform):
print(pbw, id, platform)
if not send_pebble_command('wipe'):
return False
if not send_pebble_command('install', '--emulator', platform, pbw):
return False
for i in range(5):
filename = '%s_%s_%s.png' % (id, platform, i + 1)
print(filename)
if os.path.exists(filename):
os.unlink(filename)
if not send_pebble_command('screenshot', '--emulator', platform, filename):
return False
if not os.path.exists(filename):
print("Screenshot file not created: %s" % (filename))
return False
targetFilename = 'resources/clock_faces/%s_screenshots/%s' % (id, filename)
print(targetFilename)
if os.path.exists(targetFilename):
os.unlink(targetFilename)
shutil.move(filename, targetFilename)
if not send_pebble_command('emu-tap', '--emulator', platform):
return False
if not send_pebble_command('kill'):
return False
return True
def get_screenshots(pbw, platforms):
try:
zip = zipfile.ZipFile(pbw, 'r')
except IOError:
print("Could not open %s" % (pbw))
return False
try:
appinfoData = zip.read('appinfo.json')
except KeyError:
print("Could not find appinfo.json in %s" % (pbw))
return False
zip = None
appinfo = json.loads(appinfoData)
targetPlatforms = appinfo['targetPlatforms']
name = appinfo['name']
if name not in watches:
print("Unknown watch name '%s' in %s" % (name, pbw))
return False
id = watches[name]
if platforms:
unsupported = set(platforms) - set(targetPlatforms)
if unsupported:
print("Platform %s not supported by %s" % (','.join(sorted(unsupported)), pbw))
return False
else:
platforms = targetPlatforms
for platform in platforms:
if not get_screenshots_for_platform(pbw, id, platform):
return False
return True
# Main.
try:
opts, args = getopt.getopt(sys.argv[1:], 'b:p:h')
except getopt.error as msg:
usage(1, msg)
pbws = []
targetPlatforms = []
for opt, arg in opts:
if opt == '-b':
pbws += arg.split(',')
elif opt == '-p':
targetPlatforms += arg.split(',')
elif opt == '-h':
usage(0)
if not pbws:
pbws = glob.glob('build/rosewright_*.pbw')
pbws.sort()
if not pbws:
print("No pbw's found.", file=sys.stderr)
sys.exit(1)
for pbw in pbws:
if not get_screenshots(pbw, targetPlatforms):
sys.exit(1)