This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbisection_script.py
91 lines (80 loc) · 3.29 KB
/
bisection_script.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
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
import requests
import logging
import subprocess
from argparse import ArgumentParser
from mozci.sources.buildapi import query_repo_url
JSON_PUSHES = "%(repo_url)s/json-pushes"
logging.basicConfig(format='%(levelname)s:\t %(message)s')
LOG = logging.getLogger()
LOG.setLevel(logging.INFO)
# requests is too noisy
logging.getLogger("requests").setLevel(logging.WARNING)
def parse_args(argv=None):
parser = ArgumentParser()
parser.add_argument("-s", "--start-rev",
dest="start_rev",
type=str,
help="Starting revision.")
parser.add_argument("-e", "--end-rev",
dest="end_rev",
type=str,
help="Ending revision.")
parser.add_argument("-c", "--changeset",
dest="changeset",
type=str,
help="Current changeset.")
parser.add_argument("-p", "--patch",
dest="patch",
type=str,
help="Topmost additional patch in series to push before trypatch.")
parser.add_argument("--cwd",
dest="cwd",
required=True,
type=str,
help="Path for mozilla repo.")
parser.add_argument("--repo",
dest="repo_name",
required=True,
type=str,
help="Repository Name.")
parser.add_argument("-t", "--try-syntax",
dest="try_syntax",
required=True,
type=str,
help="Try syntax with which push.")
options = parser.parse_args(argv)
return options
def main():
options = parse_args()
repo_url = query_repo_url(options.repo_name)
if options.start_rev and options.end_rev:
url = "%s?fromchange=%s&tochange=%s&tipsonly=1" % (JSON_PUSHES % {"repo_url": repo_url},
options.start_rev, options.end_rev)
elif options.changeset:
url = "%s?changeset=%s" % (JSON_PUSHES % {"repo_url": repo_url}, options.changeset)
else:
raise Exception("You need to enter either --start-rev and --end-rev or --changeset")
response = requests.get(url).json()
total_revisions = []
for push, value in response.iteritems():
for changeset in value["changesets"]:
total_revisions.append(changeset)
LOG.info("We are going to push the following revisions on try:\n %s" % total_revisions)
for revision in total_revisions:
LOG.info("Updating and pushing the revision %s to try" % revision)
commands = [
['hg', 'qpop', '-a'],
['hg', 'update', '%s' % revision]]
if options.patch:
commands += [['hg', 'qpush', '%s' % options.patch]]
commands += [
['hg', 'qnew', 'trypatch'],
['hg', 'qpush', 'trypatch'],
['hg', 'qref', '-m', 'hg update %s; %s' % (revision, options.try_syntax)],
['hg', 'push', '-f', 'try']
]
print commands
for command in commands:
subprocess.call(command, cwd=options.cwd)
LOG.info("Pushed revision %s to try" % revision)
if __name__ == "__main__": main()