aboutsummaryrefslogtreecommitdiff
path: root/control
diff options
context:
space:
mode:
authorPaul Sokolovsky <paul.sokolovsky@linaro.org>2011-06-06 13:42:54 +0300
committerPaul Sokolovsky <paul.sokolovsky@linaro.org>2011-06-06 13:42:54 +0300
commit95278599041a71159f279d419e6f8f63ad388c2f (patch)
tree2d3f8ec53712df17c93749726bd69de668f26904 /control
parentfd978ef3df37065141c49a8e1f2acd71d59c6f1d (diff)
Add optparse support, --limit=N option and use old good diff -u.
Diffstat (limited to 'control')
-rwxr-xr-xcontrol/mangle-jobs38
1 files changed, 25 insertions, 13 deletions
diff --git a/control/mangle-jobs b/control/mangle-jobs
index ae841cc..9f1b85d 100755
--- a/control/mangle-jobs
+++ b/control/mangle-jobs
@@ -18,20 +18,27 @@ import os
import sys
from tempfile import NamedTemporaryFile
import urllib2
-
+import optparse
from lxml.etree import fromstring, tostring
-really_change = False
-if '--really' in sys.argv:
- sys.argv.remove('--really')
- really_change = True
-username = sys.argv[1]
-password = open(sys.argv[2]).read().strip()
+optparser = optparse.OptionParser(usage="%prog <jenkins user> <passw file> <mangle script>")
+optparser.add_option("--really", action="store_true",
+ help="Actually perform changes")
+optparser.add_option("--limit", type="int", default=-1,
+ help="Change at most LIMIT jobs")
+
+options, args = optparser.parse_args(sys.argv[1:])
+if len(args) != 3:
+ optparser.error("Wrong number of arguments")
+
+username = args[0]
+password = open(args[1]).read().strip()
d = {}
-execfile(sys.argv[3], d, d)
+execfile(args[2], d, d)
mangler = d['mangle']
+limit = options.limit
auth_headers = {
'Authorization': 'Basic %s' % (
@@ -69,15 +76,20 @@ jobs = json.load(urllib2.urlopen('http://localhost:9090/jenkins/api/json?tree=jo
names = [job['name'] for job in jobs['jobs']]
names = [name for name in names if name == 'blank' or '_' in name]
for name in names:
- print name
+ if limit == 0:
+ break
+ limit -= 1
+ print "Processing:" + name
text = getJobConfig(name)
tree = fromstring(text)
mangler(tree)
- if not really_change:
+ new_text = tostring(tree, xml_declaration=True, encoding='UTF-8')
+ if not options.really:
with nested(NamedTemporaryFile(), NamedTemporaryFile()) as (a, b):
a.write(text)
- b.write(tostring(tree))
+ b.write(new_text)
a.flush(); b.flush()
- os.system('xmldiff %s %s' % (a.name, b.name))
+ os.system('diff -u %s %s' % (a.name, b.name))
+ print
else:
- postConfig('job/' + name + '/config.xml', tostring(tree))
+ postConfig('job/' + name + '/config.xml', new_text)