Merge lp:~jml/pkgme/upload-to-ppa into lp:pkgme

Proposed by Jonathan Lange
Status: Merged
Approved by: James Westby
Approved revision: 94
Merged at revision: 73
Proposed branch: lp:~jml/pkgme/upload-to-ppa
Merge into: lp:pkgme
Diff against target: 221 lines (+85/-57)
4 files modified
pkgme/bin/main.py (+21/-8)
pkgme/debuild.py (+16/-28)
pkgme/dput.py (+7/-0)
pkgme/run_script.py (+41/-21)
To merge this branch: bzr merge lp:~jml/pkgme/upload-to-ppa
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+70042@code.launchpad.net

Description of the change

This branch makes pkgme upload to a PPA if the PPA is provided as an argument to 'pkgme'.

 * It doesn't do any validation of the argument. It lets 'dput' do all of that.
 * 'dput' is in a module all by its own. I don't know where else to put it.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pkgme/bin/main.py'
2--- pkgme/bin/main.py 2011-08-01 09:00:08 +0000
3+++ pkgme/bin/main.py 2011-08-01 16:13:58 +0000
4@@ -6,23 +6,26 @@
5
6 from pkgme import __version__, write_packaging
7 from pkgme.debuild import build_source_package
8+from pkgme.dput import dput
9 from pkgme.errors import PkgmeError
10 from pkgme import trace
11
12
13-def build_package(target_dir, interactive):
14+def build_package(target_dir, interactive, ppa=None):
15 """Where the magic happens."""
16 trace.debug("Building packaging for %s" % (target_dir,))
17 write_packaging(target_dir)
18 trace.debug("Built packaging for %s" % (target_dir,))
19 trace.debug("Building source package for %s" % (target_dir,))
20- build_source_package(target_dir, sign=interactive)
21+ changes_file = build_source_package(target_dir, sign=interactive)
22 trace.debug("Built source package for %s" % (target_dir,))
23-
24-
25-def main(argv=None, target_dir=None, interactive=True):
26- if argv is None:
27- argv = sys.argv[1:]
28+ if ppa:
29+ trace.debug('Uploading to PPA: %s => %s' % (changes_file, ppa))
30+ dput(ppa, changes_file)
31+ trace.debug('Uploaded to PPA: %s => %s' % (changes_file, ppa))
32+
33+
34+def make_arg_parser():
35 parser = argparse.ArgumentParser(
36 description='pkgme - A Debian packaging generation framework.')
37 parser.add_argument(
38@@ -30,13 +33,23 @@
39 action='version', version='pkgme {0}'.format(__version__),
40 help='Print this version string and exit')
41 parser.add_argument('-D', '--debug', action='store_true')
42+ parser.add_argument(
43+ 'ppa', nargs='?', metavar='PPA',
44+ help='A PPA to upload to. e.g. ppa:user/ppa-name')
45+ return parser
46+
47+
48+def main(argv=None, target_dir=None, interactive=True):
49+ if argv is None:
50+ argv = sys.argv[1:]
51+ parser = make_arg_parser()
52 options = parser.parse_args(args=argv)
53 if options.debug:
54 trace.set_debug()
55 if target_dir is None:
56 target_dir = os.getcwd()
57 try:
58- build_package(target_dir, interactive=interactive)
59+ build_package(target_dir, interactive=interactive, ppa=options.ppa)
60 except PkgmeError, e:
61 if options.debug:
62 raise
63
64=== modified file 'pkgme/debuild.py'
65--- pkgme/debuild.py 2011-07-29 17:14:50 +0000
66+++ pkgme/debuild.py 2011-08-01 16:13:58 +0000
67@@ -1,34 +1,22 @@
68-import subprocess
69-
70-from pkgme.errors import PkgmeError
71-from pkgme import trace
72-
73-
74-class DebuildError(PkgmeError):
75-
76- def __init__(self, command, retcode, output_lines):
77- super(DebuildError, self).__init__(
78- "%s failed with %s. Output:\n%s" % (
79- ' '.join(command),
80- retcode,
81- ''.join(' | %s' % (line,) for line in output_lines if line)))
82+import os
83+import re
84+
85+from pkgme.run_script import run_subprocess
86+
87+
88+def find_changes_file(output_lines,
89+ _changes_file_re=re.compile(r' dpkg-genchanges -S >(.*)')):
90+ for line in output_lines:
91+ match = _changes_file_re.match(line)
92+ if match:
93+ return match.group(1)
94+ raise ValueError("Could not find changes filename")
95
96
97 def build_source_package(directory, sign=True):
98 cmd = ['debuild', '--no-lintian', '-S']
99 if not sign:
100 cmd.extend(['-uc', '-us'])
101- trace.debug("Running %s" % ' '.join(cmd))
102- proc = subprocess.Popen(
103- cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=directory)
104- output = []
105- while True:
106- stdout = proc.stdout.readline()
107- output.append(stdout)
108- if stdout:
109- trace.debug('D: %s' % (stdout.rstrip('\n'),))
110- else:
111- break
112- retcode = proc.wait()
113- if retcode != 0:
114- raise DebuildError(cmd, retcode, output)
115+ output = run_subprocess(cmd, cwd=directory)
116+ changes_file = find_changes_file(output)
117+ return os.path.abspath(os.path.join(directory, changes_file))
118
119=== added file 'pkgme/dput.py'
120--- pkgme/dput.py 1970-01-01 00:00:00 +0000
121+++ pkgme/dput.py 2011-08-01 16:13:58 +0000
122@@ -0,0 +1,7 @@
123+from pkgme.run_script import run_subprocess
124+
125+
126+def dput(ppa_name, changes_file):
127+ """Use 'dput' to upload to a PPA."""
128+ # XXX: This won't raise an error if the PPA doesn't exist.
129+ return run_subprocess(['dput', ppa_name, changes_file])
130
131=== modified file 'pkgme/run_script.py'
132--- pkgme/run_script.py 2011-07-29 14:55:52 +0000
133+++ pkgme/run_script.py 2011-08-01 16:13:58 +0000
134@@ -2,12 +2,14 @@
135 import os
136 import subprocess
137
138+from pkgme.errors import PkgmeError
139 from pkgme import trace
140
141
142-class ScriptProblem(Exception):
143+class ScriptProblem(PkgmeError):
144
145 def __init__(self, script_path):
146+ super(ScriptProblem, self).__init__()
147 self.script_path = script_path
148
149
150@@ -22,15 +24,45 @@
151
152 class ScriptFailed(ScriptProblem):
153
154- def __init__(self, script_path, returncode, output):
155- super(ScriptFailed, self).__init__(script_path)
156+ def __init__(self, command, returncode, output_lines):
157+ super(ScriptFailed, self).__init__(command[0])
158+ self.command = command
159 self.returncode = returncode
160- self.output = output
161+ self.output_lines = output_lines
162
163 def __str__(self):
164- return (
165- "%s failed with returncode %d, output was %s"
166- % (self.script_path, self.returncode, self.output))
167+ return "%s failed with returncode %s. Output:\n%s" % (
168+ ' '.join(self.command),
169+ self.returncode,
170+ ''.join(' | %s' % (line,)
171+ for line in self.output_lines if line))
172+
173+
174+def run_subprocess(cmd, cwd=None, env=None, to_write=None):
175+ trace.debug("Running %s" % ' '.join(cmd))
176+ try:
177+ proc = subprocess.Popen(
178+ cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
179+ stderr=subprocess.STDOUT, cwd=cwd, env=env)
180+ except OSError as e:
181+ if e.errno == errno.ENOENT:
182+ raise ScriptMissing(cmd[0])
183+ raise
184+ output = []
185+ if to_write:
186+ proc.stdin.write(to_write)
187+ proc.stdin.close()
188+ while True:
189+ stdout = proc.stdout.readline()
190+ output.append(stdout)
191+ if stdout:
192+ trace.debug('D: %s' % (stdout.rstrip('\n'),))
193+ else:
194+ break
195+ retcode = proc.wait()
196+ if retcode != 0:
197+ raise ScriptFailed(cmd, retcode, output)
198+ return output
199
200
201 def run_script(basepath, script_name, cwd, to_write=None):
202@@ -43,17 +75,5 @@
203 env['PATH'] = os.pathsep.join([env['PATH'], helperpath])
204 else:
205 env['PATH'] = helperpath
206- try:
207- trace.debug("Running script %s..." % (script_path,))
208- proc = subprocess.Popen(
209- [script_path], stdout=subprocess.PIPE,
210- stderr=subprocess.STDOUT, stdin=subprocess.PIPE,
211- cwd=cwd, env=env)
212- except OSError as e:
213- if e.errno == errno.ENOENT:
214- raise ScriptMissing(script_path)
215- raise
216- out, ignore = proc.communicate(to_write)
217- if proc.returncode != 0:
218- raise ScriptFailed(script_path, proc.returncode, out)
219- return out
220+ output = run_subprocess([script_path], cwd=cwd, env=env, to_write=to_write)
221+ return ''.join(output)

Subscribers

People subscribed via source and target branches