forked from CyanogenMod/hudson
-
Notifications
You must be signed in to change notification settings - Fork 1
/
repopick.py
56 lines (47 loc) · 1.78 KB
/
repopick.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
#!/usr/bin/env python
import sys
import json
import os
import subprocess
import re
try:
# For python3
import urllib.request
except ImportError:
# For python2
import imp
import urllib2
urllib = imp.new_module('urllib')
urllib.request = urllib2
for change in sys.argv[1:]:
print(change)
f = urllib.request.urlopen('https://gerrit.omnirom.org/query?q=change:%s' % change)
d = f.read().decode()
# gerrit doesnt actually return json. returns two json blobs, separate lines. bizarre.
print(d)
d = d.split('\n')[0]
data = json.loads(d)
project = data['project']
plist = subprocess.Popen([os.environ['HOME']+"/bin/repo","list"], stdout=subprocess.PIPE)
while(True):
retcode = plist.poll()
pline = plist.stdout.readline().rstrip()
ppaths = re.split('\s*:\s*', pline.decode())
if ppaths[1] == project:
project = ppaths[0]
break
if(retcode is not None):
break
print(project)
number = data['number']
patch_count = 0
junk = number[len(number) - 2:]
if not os.path.isdir(project):
sys.stderr.write('no project directory: %s' % project)
sys.exit(1)
while 0 != os.system('cd %s ; git fetch https://gerrit.omnirom.org/%s refs/changes/%s/%s/%s' % (project, data['project'], junk, number, patch_count + 1)):
patch_count = patch_count + 1
while 0 == os.system('cd %s ; git fetch https://gerrit.omnirom.org/%s refs/changes/%s/%s/%s' % (project, data['project'], junk, number, patch_count + 1)):
patch_count = patch_count + 1
os.system('cd %s ; git fetch https://gerrit.omnirom.org/%s refs/changes/%s/%s/%s' % (project, data['project'], junk, number, patch_count))
os.system('cd %s ; git cherry-pick FETCH_HEAD' % project)