-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateavd.py
58 lines (48 loc) · 1.67 KB
/
updateavd.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/python2
import os, re, subprocess
def check_config(fn):
with open(fn, 'r') as f:
for line in f:
key = line.split('=')
if key[0] == 'hw.keyboard' and key[1].startswith('yes'):
return True
return False
def main():
p = subprocess.Popen('avdmanager list avd', stdout=subprocess.PIPE, shell=True, universal_newlines=True)
(data, errors) = p.communicate()
name = None
path = None
for line in data.split("\n"):
if line == '---------':
name = None
path = None
continue
match = re.match(' +Name: (.*)$', line)
if match != None:
name = match.group(1)
match = re.match(' +Path: (.*)$', line)
if match != None:
path = match.group(1)
if name and path:
# We have found an AVD named 'name' at path 'path'
if not re.match('avd[0-4]$', name):
# This isn't our AVD, move along
name = None
path = None
continue
# This is our AVD, check if we need to update it
config = os.path.join(path, 'config.ini')
if check_config(config):
# This config is already updated
print 'AVD %s appears to have been updated already, skipping' % name
name = None
path = None
continue
# Update this configuration
with open(config, 'a') as f:
print 'Updating AVD %s' % name
print >> f, 'hw.keyboard=yes'
name = None
path = None
if __name__ == "__main__":
main()