Merge lp:~bjornt/launchpad/quiet-update-sourcecode into lp:launchpad

Proposed by Björn Tillenius
Status: Merged
Approved by: Jonathan Lange
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~bjornt/launchpad/quiet-update-sourcecode
Merge into: lp:launchpad
Diff against target: 130 lines (+31/-20)
1 file modified
lib/devscripts/sourcecode.py (+31/-20)
To merge this branch: bzr merge lp:~bjornt/launchpad/quiet-update-sourcecode
Reviewer Review Type Date Requested Status
Abel Deuring (community) Approve
Review via email: mp+19710@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Björn Tillenius (bjornt) wrote :

Add a --quiet flag to update-sourcecode.py. This makes it easier to use
this script in a crontab.

Revision history for this message
Abel Deuring (adeuring) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/devscripts/sourcecode.py'
2--- lib/devscripts/sourcecode.py 2010-04-08 15:40:56 +0000
3+++ lib/devscripts/sourcecode.py 2010-04-19 11:14:26 +0000
4@@ -148,7 +148,7 @@
5
6
7 def get_branches(sourcecode_directory, new_branches,
8- possible_transports=None, tip=False):
9+ possible_transports=None, tip=False, quiet=False):
10 """Get the new branches into sourcecode."""
11 for project, (branch_url, revision, optional) in new_branches.iteritems():
12 destination = os.path.join(sourcecode_directory, project)
13@@ -163,8 +163,9 @@
14 raise
15 possible_transports.append(
16 remote_branch.bzrdir.root_transport)
17- print 'Getting %s from %s at %s' % (
18- project, branch_url, _format_revision_name(revision, tip))
19+ if not quiet:
20+ print 'Getting %s from %s at %s' % (
21+ project, branch_url, _format_revision_name(revision, tip))
22 # If the 'optional' flag is set, then it's a branch that shares
23 # history with Launchpad, so we should share repositories. Otherwise,
24 # we should avoid sharing repositories to avoid format
25@@ -178,7 +179,7 @@
26
27
28 def update_branches(sourcecode_directory, update_branches,
29- possible_transports=None, tip=False):
30+ possible_transports=None, tip=False, quiet=False):
31 """Update the existing branches in sourcecode."""
32 if possible_transports is None:
33 possible_transports = []
34@@ -188,8 +189,9 @@
35 update_branches.iteritems()):
36 # Update project from branch_url.
37 destination = os.path.join(sourcecode_directory, project)
38- print 'Updating %s to %s' % (
39- project, _format_revision_name(revision, tip))
40+ if not quiet:
41+ print 'Updating %s to %s' % (
42+ project, _format_revision_name(revision, tip))
43 local_tree = WorkingTree.open(destination)
44 try:
45 remote_branch = Branch.open(
46@@ -220,21 +222,24 @@
47 remote_branch, stop_revision=revision_id, overwrite=True,
48 possible_transports=possible_transports)
49 if result.old_revid == result.new_revid:
50- print ' (No change)'
51+ if not quiet:
52+ print ' (No change)'
53 else:
54 if result.old_revno < result.new_revno:
55 change = 'Updated'
56 else:
57 change = 'Reverted'
58- print ' (%s from %s to %s)' % (
59- change, result.old_revno, result.new_revno)
60-
61-
62-def remove_branches(sourcecode_directory, removed_branches):
63+ if not quiet:
64+ print ' (%s from %s to %s)' % (
65+ change, result.old_revno, result.new_revno)
66+
67+
68+def remove_branches(sourcecode_directory, removed_branches, quiet=False):
69 """Remove sourcecode that's no longer there."""
70 for project in removed_branches:
71 destination = os.path.join(sourcecode_directory, project)
72- print 'Removing %s' % project
73+ if not quiet:
74+ print 'Removing %s' % project
75 try:
76 shutil.rmtree(destination)
77 except OSError:
78@@ -242,7 +247,7 @@
79
80
81 def update_sourcecode(sourcecode_directory, config_filename, public_only,
82- tip, dry_run):
83+ tip, dry_run, quiet=False):
84 """Update the sourcecode."""
85 config_file = open(config_filename)
86 config = interpret_config(parse_config_file(config_file), public_only)
87@@ -255,9 +260,11 @@
88 print 'Branches to update:', updated.keys()
89 print 'Branches to remove:', list(removed)
90 else:
91- get_branches(sourcecode_directory, new, possible_transports, tip)
92- update_branches(sourcecode_directory, updated, possible_transports, tip)
93- remove_branches(sourcecode_directory, removed)
94+ get_branches(
95+ sourcecode_directory, new, possible_transports, tip, quiet)
96+ update_branches(
97+ sourcecode_directory, updated, possible_transports, tip, quiet)
98+ remove_branches(sourcecode_directory, removed, quiet)
99
100
101 # XXX: JonathanLange 2009-09-11: By default, the script will operate on the
102@@ -282,6 +289,9 @@
103 parser.add_option(
104 '--dry-run', action='store_true',
105 help='Do nothing, but report what would have been done.')
106+ parser.add_option(
107+ '--quiet', action='store_true',
108+ help="Don't print informational messages.")
109 options, args = parser.parse_args(args)
110 root = get_launchpad_root()
111 if len(args) > 1:
112@@ -294,8 +304,9 @@
113 config_filename = os.path.join(root, 'utilities', 'sourcedeps.conf')
114 if len(args) > 3:
115 parser.error("Too many arguments.")
116- print 'Sourcecode: %s' % (sourcecode_directory,)
117- print 'Config: %s' % (config_filename,)
118+ if not options.quiet:
119+ print 'Sourcecode: %s' % (sourcecode_directory,)
120+ print 'Config: %s' % (config_filename,)
121 enable_default_logging()
122 # Tell bzr to use the terminal (if any) to show progress bars
123 ui.ui_factory = ui.make_ui_for_terminal(
124@@ -303,5 +314,5 @@
125 load_plugins()
126 update_sourcecode(
127 sourcecode_directory, config_filename,
128- options.public_only, options.tip, options.dry_run)
129+ options.public_only, options.tip, options.dry_run, options.quiet)
130 return 0