forked from odk-x/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ss.py
executable file
·58 lines (51 loc) · 1.7 KB
/
ss.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
#!/usr/bin/env python
import os
import subprocess
import sys
import PIL.Image as Image
import PIL.ImageCms as ImageCms
import tempfile
def ensure_dir(file_path):
directory = os.path.dirname(file_path)
if not os.path.exists(directory):
os.makedirs(directory)
def screencap():
return subprocess.check_output("adb exec-out screencap -p", shell=True)
def save_screencap(cap, filename):
with open(filename, 'wb') as f:
f.write(cap)
def convert_profile(filename):
img = Image.open(filename)
icc = tempfile.mkstemp(suffix='.icc')[1]
if 'icc_profile' in img.info:
with open(icc, 'wb') as f:
f.write(img.info['icc_profile'])
srgb = ImageCms.createProfile('sRGB')
img = ImageCms.profileToProfile(img, icc, srgb)
img.save(filename)
if __name__ == "__main__":
short_filename = sys.argv[1]
silent_mode = False
try:
if sys.argv[2] == '-s':
silent_mode = True
except:
pass
filename = 'img/' + short_filename + '.png'
ensure_dir(filename)
save_screencap(screencap(), filename)
convert_profile(filename)
if not silent_mode:
print("Insert image into doc with:")
print(".. image:: /img/" + short_filename + ".*")
print(" :alt: Alt text here. Be sure to add alt text.")
print("")
print("")
print("Use the figure directive to add a caption:")
print(".. figure:: /img/" + short_filename + ".*")
print(" :alt: Alt text here. Be sure to add alt text.")
print("")
print(" The caption is here.")
print("")
print("")
print("See https://docs.odk-x.org/contributing/#images-and-figures for more details.")