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
=== modified file 'pkgme/bin/main.py'
--- pkgme/bin/main.py 2011-08-01 09:00:08 +0000
+++ pkgme/bin/main.py 2011-08-01 16:13:58 +0000
@@ -6,23 +6,26 @@
66
7from pkgme import __version__, write_packaging7from pkgme import __version__, write_packaging
8from pkgme.debuild import build_source_package8from pkgme.debuild import build_source_package
9from pkgme.dput import dput
9from pkgme.errors import PkgmeError10from pkgme.errors import PkgmeError
10from pkgme import trace11from pkgme import trace
1112
1213
13def build_package(target_dir, interactive):14def build_package(target_dir, interactive, ppa=None):
14 """Where the magic happens."""15 """Where the magic happens."""
15 trace.debug("Building packaging for %s" % (target_dir,))16 trace.debug("Building packaging for %s" % (target_dir,))
16 write_packaging(target_dir)17 write_packaging(target_dir)
17 trace.debug("Built packaging for %s" % (target_dir,))18 trace.debug("Built packaging for %s" % (target_dir,))
18 trace.debug("Building source package for %s" % (target_dir,))19 trace.debug("Building source package for %s" % (target_dir,))
19 build_source_package(target_dir, sign=interactive)20 changes_file = build_source_package(target_dir, sign=interactive)
20 trace.debug("Built source package for %s" % (target_dir,))21 trace.debug("Built source package for %s" % (target_dir,))
2122 if ppa:
2223 trace.debug('Uploading to PPA: %s => %s' % (changes_file, ppa))
23def main(argv=None, target_dir=None, interactive=True):24 dput(ppa, changes_file)
24 if argv is None:25 trace.debug('Uploaded to PPA: %s => %s' % (changes_file, ppa))
25 argv = sys.argv[1:]26
27
28def make_arg_parser():
26 parser = argparse.ArgumentParser(29 parser = argparse.ArgumentParser(
27 description='pkgme - A Debian packaging generation framework.')30 description='pkgme - A Debian packaging generation framework.')
28 parser.add_argument(31 parser.add_argument(
@@ -30,13 +33,23 @@
30 action='version', version='pkgme {0}'.format(__version__),33 action='version', version='pkgme {0}'.format(__version__),
31 help='Print this version string and exit')34 help='Print this version string and exit')
32 parser.add_argument('-D', '--debug', action='store_true')35 parser.add_argument('-D', '--debug', action='store_true')
36 parser.add_argument(
37 'ppa', nargs='?', metavar='PPA',
38 help='A PPA to upload to. e.g. ppa:user/ppa-name')
39 return parser
40
41
42def main(argv=None, target_dir=None, interactive=True):
43 if argv is None:
44 argv = sys.argv[1:]
45 parser = make_arg_parser()
33 options = parser.parse_args(args=argv)46 options = parser.parse_args(args=argv)
34 if options.debug:47 if options.debug:
35 trace.set_debug()48 trace.set_debug()
36 if target_dir is None:49 if target_dir is None:
37 target_dir = os.getcwd()50 target_dir = os.getcwd()
38 try:51 try:
39 build_package(target_dir, interactive=interactive)52 build_package(target_dir, interactive=interactive, ppa=options.ppa)
40 except PkgmeError, e:53 except PkgmeError, e:
41 if options.debug:54 if options.debug:
42 raise55 raise
4356
=== modified file 'pkgme/debuild.py'
--- pkgme/debuild.py 2011-07-29 17:14:50 +0000
+++ pkgme/debuild.py 2011-08-01 16:13:58 +0000
@@ -1,34 +1,22 @@
1import subprocess1import os
22import re
3from pkgme.errors import PkgmeError3
4from pkgme import trace4from pkgme.run_script import run_subprocess
55
66
7class DebuildError(PkgmeError):7def find_changes_file(output_lines,
88 _changes_file_re=re.compile(r' dpkg-genchanges -S >(.*)')):
9 def __init__(self, command, retcode, output_lines):9 for line in output_lines:
10 super(DebuildError, self).__init__(10 match = _changes_file_re.match(line)
11 "%s failed with %s. Output:\n%s" % (11 if match:
12 ' '.join(command),12 return match.group(1)
13 retcode,13 raise ValueError("Could not find changes filename")
14 ''.join(' | %s' % (line,) for line in output_lines if line)))
1514
1615
17def build_source_package(directory, sign=True):16def build_source_package(directory, sign=True):
18 cmd = ['debuild', '--no-lintian', '-S']17 cmd = ['debuild', '--no-lintian', '-S']
19 if not sign:18 if not sign:
20 cmd.extend(['-uc', '-us'])19 cmd.extend(['-uc', '-us'])
21 trace.debug("Running %s" % ' '.join(cmd))20 output = run_subprocess(cmd, cwd=directory)
22 proc = subprocess.Popen(21 changes_file = find_changes_file(output)
23 cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=directory)22 return os.path.abspath(os.path.join(directory, changes_file))
24 output = []
25 while True:
26 stdout = proc.stdout.readline()
27 output.append(stdout)
28 if stdout:
29 trace.debug('D: %s' % (stdout.rstrip('\n'),))
30 else:
31 break
32 retcode = proc.wait()
33 if retcode != 0:
34 raise DebuildError(cmd, retcode, output)
3523
=== added file 'pkgme/dput.py'
--- pkgme/dput.py 1970-01-01 00:00:00 +0000
+++ pkgme/dput.py 2011-08-01 16:13:58 +0000
@@ -0,0 +1,7 @@
1from pkgme.run_script import run_subprocess
2
3
4def dput(ppa_name, changes_file):
5 """Use 'dput' to upload to a PPA."""
6 # XXX: This won't raise an error if the PPA doesn't exist.
7 return run_subprocess(['dput', ppa_name, changes_file])
08
=== modified file 'pkgme/run_script.py'
--- pkgme/run_script.py 2011-07-29 14:55:52 +0000
+++ pkgme/run_script.py 2011-08-01 16:13:58 +0000
@@ -2,12 +2,14 @@
2import os2import os
3import subprocess3import subprocess
44
5from pkgme.errors import PkgmeError
5from pkgme import trace6from pkgme import trace
67
78
8class ScriptProblem(Exception):9class ScriptProblem(PkgmeError):
910
10 def __init__(self, script_path):11 def __init__(self, script_path):
12 super(ScriptProblem, self).__init__()
11 self.script_path = script_path13 self.script_path = script_path
1214
1315
@@ -22,15 +24,45 @@
2224
23class ScriptFailed(ScriptProblem):25class ScriptFailed(ScriptProblem):
2426
25 def __init__(self, script_path, returncode, output):27 def __init__(self, command, returncode, output_lines):
26 super(ScriptFailed, self).__init__(script_path)28 super(ScriptFailed, self).__init__(command[0])
29 self.command = command
27 self.returncode = returncode30 self.returncode = returncode
28 self.output = output31 self.output_lines = output_lines
2932
30 def __str__(self):33 def __str__(self):
31 return (34 return "%s failed with returncode %s. Output:\n%s" % (
32 "%s failed with returncode %d, output was %s"35 ' '.join(self.command),
33 % (self.script_path, self.returncode, self.output))36 self.returncode,
37 ''.join(' | %s' % (line,)
38 for line in self.output_lines if line))
39
40
41def run_subprocess(cmd, cwd=None, env=None, to_write=None):
42 trace.debug("Running %s" % ' '.join(cmd))
43 try:
44 proc = subprocess.Popen(
45 cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
46 stderr=subprocess.STDOUT, cwd=cwd, env=env)
47 except OSError as e:
48 if e.errno == errno.ENOENT:
49 raise ScriptMissing(cmd[0])
50 raise
51 output = []
52 if to_write:
53 proc.stdin.write(to_write)
54 proc.stdin.close()
55 while True:
56 stdout = proc.stdout.readline()
57 output.append(stdout)
58 if stdout:
59 trace.debug('D: %s' % (stdout.rstrip('\n'),))
60 else:
61 break
62 retcode = proc.wait()
63 if retcode != 0:
64 raise ScriptFailed(cmd, retcode, output)
65 return output
3466
3567
36def run_script(basepath, script_name, cwd, to_write=None):68def run_script(basepath, script_name, cwd, to_write=None):
@@ -43,17 +75,5 @@
43 env['PATH'] = os.pathsep.join([env['PATH'], helperpath])75 env['PATH'] = os.pathsep.join([env['PATH'], helperpath])
44 else:76 else:
45 env['PATH'] = helperpath77 env['PATH'] = helperpath
46 try:78 output = run_subprocess([script_path], cwd=cwd, env=env, to_write=to_write)
47 trace.debug("Running script %s..." % (script_path,))79 return ''.join(output)
48 proc = subprocess.Popen(
49 [script_path], stdout=subprocess.PIPE,
50 stderr=subprocess.STDOUT, stdin=subprocess.PIPE,
51 cwd=cwd, env=env)
52 except OSError as e:
53 if e.errno == errno.ENOENT:
54 raise ScriptMissing(script_path)
55 raise
56 out, ignore = proc.communicate(to_write)
57 if proc.returncode != 0:
58 raise ScriptFailed(script_path, proc.returncode, out)
59 return out

Subscribers

People subscribed via source and target branches