From 661d927d38df9d0c9d60e0199e7f8d87b2a21ed3 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 20 Oct 2009 14:30:15 +0000 Subject: [PATCH] code cleanup --- dist/osc.complete | 332 ++++++++++++++++---------------- mktar.py | 14 +- osc-wrapper.py | 10 +- osc/OscConfigParser.py | 8 +- osc/babysitter.py | 2 +- osc/build.py | 96 +++++----- osc/cmdln.py | 72 +++---- osc/commandline.py | 189 +++++++++---------- osc/conf.py | 55 +++--- osc/core.py | 420 ++++++++++++++++++++--------------------- osc/fetch.py | 22 +-- osc/meter.py | 10 +- osc/oscerr.py | 12 +- osc/util/ar.py | 6 +- osc/util/cpio.py | 10 +- osc_expand_link.pl | 244 ++++++++++++------------ osc_hotshot.py | 2 +- tests.py | 16 +- 18 files changed, 756 insertions(+), 764 deletions(-) diff --git a/dist/osc.complete b/dist/osc.complete index 504d01a7..0b399d07 100644 --- a/dist/osc.complete +++ b/dist/osc.complete @@ -63,320 +63,320 @@ submit () local target if ((pos == 1)) ; then - if test -z "${cmdline[$((2+off))]}" -a -n "${oscprj}" ; then - builtin compgen -W "${oscprj}" - else - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[$((2+off))]}" - fi + if test -z "${cmdline[$((2+off))]}" -a -n "${oscprj}" ; then + builtin compgen -W "${oscprj}" + else + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[$((2+off))]}" + fi fi if ((pos == 2)) ; then - if test -z "${cmdline[$((3+off))]}" -a -n "${oscpkg}" ; then - builtin compgen -W "${oscpkg}" - else - builtin compgen -W "$(command osc ls "${cmdline[$((2+off))]}")" -- "${cmdline[$((3+off))]}" - fi + if test -z "${cmdline[$((3+off))]}" -a -n "${oscpkg}" ; then + builtin compgen -W "${oscpkg}" + else + builtin compgen -W "$(command osc ls "${cmdline[$((2+off))]}")" -- "${cmdline[$((3+off))]}" + fi fi if ((pos == 3)) ; then - if test -z "${cmdline[$((4+off))]}" -a -n "${lnkprj}" ; then - builtin compgen -W "${lnkprj}" - else - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[$((4+off))]}" - fi + if test -z "${cmdline[$((4+off))]}" -a -n "${lnkprj}" ; then + builtin compgen -W "${lnkprj}" + else + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[$((4+off))]}" + fi fi if ((pos == 4)) ; then - target="${lnkpkg}" - target="${target:+$target }$oscpkg" - if test -n "${target}" ; then - builtin compgen -W "${target}" -- "${cmdline[$((5+off))]}" - else - builtin compgen -W "$(command osc ls "${cmdline[$((4+off))]}")" -- "${cmdline[$((5+off))]}" - fi + target="${lnkpkg}" + target="${target:+$target }$oscpkg" + if test -n "${target}" ; then + builtin compgen -W "${target}" -- "${cmdline[$((5+off))]}" + else + builtin compgen -W "$(command osc ls "${cmdline[$((4+off))]}")" -- "${cmdline[$((5+off))]}" + fi fi } case "${cmdline[1]}" in add|addremove|ar) if ((count == 1)) ; then - builtin compgen -W 'add addremove ar' -- "${cmdline[1]}" + builtin compgen -W 'add addremove ar' -- "${cmdline[1]}" else - for x in $(builtin compgen -f -X '.osc' -- "${cmdline[2]}"); do - test -d $x && builtin echo $x/ || builtin echo $x - done + for x in $(builtin compgen -f -X '.osc' -- "${cmdline[2]}"); do + test -d $x && builtin echo $x/ || builtin echo $x + done fi ;; branch) if ((count == 1)) ; then - builtin compgen -W 'branch' -- "${cmdline[1]}" + builtin compgen -W 'branch' -- "${cmdline[1]}" fi case "${cmdline[2]}" in --nodevelproject) - if ((count == 3)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[3]}" - fi - if ((count == 4)) ; then - builtin compgen -W "$(command osc ls "${cmdline[3]}")" -- "${cmdline[4]}" - fi - ;; + if ((count == 3)) ; then + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[3]}" + fi + if ((count == 4)) ; then + builtin compgen -W "$(command osc ls "${cmdline[3]}")" -- "${cmdline[4]}" + fi + ;; -*) builtin compgen -W '--nodevelproject' -- "${cmdline[3]}" ;; *) - if ((count == 2)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" - fi - if ((count == 3)) ; then - builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}" - fi + if ((count == 2)) ; then + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" + fi + if ((count == 3)) ; then + builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}" + fi esac ;; list|ls) if ((count == 1)) ; then - builtin compgen -W 'list ls' -- "${cmdline[1]}" + builtin compgen -W 'list ls' -- "${cmdline[1]}" fi if ((count == 2)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" fi if ((count == 3)) ; then - builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}" + builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}" fi ;; sr|submitreq|submitrequest) if ((count == 1)) ; then - builtin compgen -W 'sr submitreq submitrequest' -- "${cmdline[1]}" + builtin compgen -W 'sr submitreq submitrequest' -- "${cmdline[1]}" fi case "${cmdline[2]}" in --nodevelproject) - submit $((count - 2)) 1 ;; + submit $((count - 2)) 1 ;; -*) builtin compgen -W '--nodevelproject' -- "${cmdline[2]}" ;; *) submit $((count - 1)) 0 ;; esac ;; rq|request) if ((count == 1)) ; then - builtin compgen -W 'rq request' -- "${cmdline[1]}" + builtin compgen -W 'rq request' -- "${cmdline[1]}" fi case "${cmdline[2]}" in accept|decline|wipe|revoke|log) - if ((count == 3)) ; then - builtin echo -n 'ID' - fi - ;; + if ((count == 3)) ; then + builtin echo -n 'ID' + fi + ;; show) - if ((count == 3)) ; then - builtin compgen -W '--diff' -- "${cmdline[3]}" - else - builtin echo -n 'ID' - fi - ;; + if ((count == 3)) ; then + builtin compgen -W '--diff' -- "${cmdline[3]}" + else + builtin echo -n 'ID' + fi + ;; list) - if ((count == 3)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[3]}" - fi - if ((count == 4)) ; then - builtin compgen -W "$(command osc ls "${cmdline[3]}")" -- "${cmdline[4]}" - fi - ;; + if ((count == 3)) ; then + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[3]}" + fi + if ((count == 4)) ; then + builtin compgen -W "$(command osc ls "${cmdline[3]}")" -- "${cmdline[4]}" + fi + ;; *) - ((count == 2)) && builtin compgen -W "$(builtin echo ${oscreq[@]})" -- "${cmdline[2]}" + ((count == 2)) && builtin compgen -W "$(builtin echo ${oscreq[@]})" -- "${cmdline[2]}" esac ;; copypac|linkpac) if ((count == 1)) ; then - builtin compgen -W 'copypac linkpac' -- "${cmdline[1]}" + builtin compgen -W 'copypac linkpac' -- "${cmdline[1]}" fi case "${cmdline[2]}" in *) - if ((count == 2)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" - fi - if ((count == 3)) ; then - builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}" - fi - if ((count == 4)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[4]}" - fi - if ((count == 5)) ; then - builtin compgen -W "$(command osc ls "${cmdline[4]}")" -- "${cmdline[5]}" - fi + if ((count == 2)) ; then + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" + fi + if ((count == 3)) ; then + builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}" + fi + if ((count == 4)) ; then + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[4]}" + fi + if ((count == 5)) ; then + builtin compgen -W "$(command osc ls "${cmdline[4]}")" -- "${cmdline[5]}" + fi esac ;; deleterequest|deletereq|dr) if ((count == 1)) ; then - builtin compgen -W 'deleterequest deletereq dr' -- "${cmdline[1]}" + builtin compgen -W 'deleterequest deletereq dr' -- "${cmdline[1]}" fi case "${cmdline[2]}" in *) - if ((count == 2)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" - fi - if ((count == 3)) ; then - builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}" - fi + if ((count == 2)) ; then + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" + fi + if ((count == 3)) ; then + builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}" + fi esac ;; changedevelrequest|changedevelreq|cr) if ((count == 1)) ; then - builtin compgen -W 'changedevelrequest changedevelreq cr' -- "${cmdline[1]}" + builtin compgen -W 'changedevelrequest changedevelreq cr' -- "${cmdline[1]}" fi case "${cmdline[2]}" in *) - if ((count == 2)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" - fi - if ((count == 3)) ; then - builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}" - fi - if ((count == 4)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[4]}" - fi - if ((count == 5)) ; then - builtin compgen -W "$(command osc ls "${cmdline[4]}")" -- "${cmdline[5]}" - fi + if ((count == 2)) ; then + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" + fi + if ((count == 3)) ; then + builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}" + fi + if ((count == 4)) ; then + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[4]}" + fi + if ((count == 5)) ; then + builtin compgen -W "$(command osc ls "${cmdline[4]}")" -- "${cmdline[5]}" + fi esac ;; rdiff) if ((count == 1)) ; then - builtin compgen -W 'rdiff' -- "${cmdline[1]}" + builtin compgen -W 'rdiff' -- "${cmdline[1]}" fi case "${cmdline[2]}" in *) - if ((count == 2)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" - fi - if ((count == 3)) ; then - builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}" - fi - if ((count == 4)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -P --oldprj= -- "${cmdline[4]#*=}" - fi - if ((count == 5)) ; then - builtin compgen -W "$(command osc ls "${cmdline[4]#*=}")" -P --oldpkg= -- "${cmdline[5]#*=}" - fi + if ((count == 2)) ; then + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" + fi + if ((count == 3)) ; then + builtin compgen -W "$(osc ls "${cmdline[2]}")" -- "${cmdline[3]}" + fi + if ((count == 4)) ; then + builtin compgen -W "$(command cat ~/.osc.projects)" -P --oldprj= -- "${cmdline[4]#*=}" + fi + if ((count == 5)) ; then + builtin compgen -W "$(command osc ls "${cmdline[4]#*=}")" -P --oldpkg= -- "${cmdline[5]#*=}" + fi esac ;; ci|commit|checkin) if ((count == 1)) ; then - builtin compgen -W 'ci commit checkin' -- "${cmdline[1]}" + builtin compgen -W 'ci commit checkin' -- "${cmdline[1]}" else - for x in $(builtin compgen -f -X '.osc' -- "${cmdline[2]}"); do - test -d $x && builtin echo $x/ || builtin echo $x - done + for x in $(builtin compgen -f -X '.osc' -- "${cmdline[2]}"); do + test -d $x && builtin echo $x/ || builtin echo $x + done fi ;; co|checkout) if ((count == 1)) ; then - builtin compgen -W 'co copypac checkout' -- "${cmdline[1]}" + builtin compgen -W 'co copypac checkout' -- "${cmdline[1]}" else - if ((count == 2)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" - fi - if ((count == 3)) ; then - builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}" - fi + if ((count == 2)) ; then + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" + fi + if ((count == 3)) ; then + builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}" + fi fi ;; maintainer) if ((count == 1)) ; then - builtin compgen -W 'maintainer' -- "${cmdline[1]}" + builtin compgen -W 'maintainer' -- "${cmdline[1]}" else - if ((count == 2)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" - fi - if ((count == 3)) ; then - builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}" - fi + if ((count == 2)) ; then + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" + fi + if ((count == 3)) ; then + builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}" + fi fi ;; up|update) if ((count == 1)) ; then - builtin compgen -W 'up update' -- "${cmdline[1]}" + builtin compgen -W 'up update' -- "${cmdline[1]}" fi if ((count == 2)) ; then - builtin compgen -W '--expand-link --unexpand-link' -- "${cmdline[2]}" + builtin compgen -W '--expand-link --unexpand-link' -- "${cmdline[2]}" fi ;; meta) if ((count == 1)) ; then - builtin compgen -W 'meta metafromspec' -- "${cmdline[1]}" + builtin compgen -W 'meta metafromspec' -- "${cmdline[1]}" fi if ((count == 2)) ; then - builtin compgen -W 'prj pkg' -- "${cmdline[2]}" + builtin compgen -W 'prj pkg' -- "${cmdline[2]}" fi if ((count == 3)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[3]}" + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[3]}" fi if ((count == 4)) && test "${cmdline[2]}" = pkg ; then - builtin compgen -W "$(command osc ls "${cmdline[3]}")" -- "${cmdline[4]}" + builtin compgen -W "$(command osc ls "${cmdline[3]}")" -- "${cmdline[4]}" fi if ((count == 5)) ; then - builtin compgen -W '--edit -e' -- "${cmdline[5]}" + builtin compgen -W '--edit -e' -- "${cmdline[5]}" fi ;; wipebinaries) if ((count == 1)) ; then - builtin compgen -W 'wipebinaries' -- "${cmdline[1]}" + builtin compgen -W 'wipebinaries' -- "${cmdline[1]}" fi if ((count == 2)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" fi if ((count == 3)) ; then - builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}" + builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}" fi if ((count == 4)) ; then - builtin compgen -W "--expansion --broken --build-failed --build-disabled" -- "${cmdline[4]}" + builtin compgen -W "--expansion --broken --build-failed --build-disabled" -- "${cmdline[4]}" fi ;; help) if ((count == 1)) ; then - builtin compgen -W 'help' -- "${cmdline[1]}" + builtin compgen -W 'help' -- "${cmdline[1]}" fi ((count == 2)) && builtin compgen -W "$(builtin echo ${osccmds[@]})" -- "${cmdline[2]}" ;; search) if ((count == 1)) ; then - builtin compgen -W 'search' -- "${cmdline[1]}" + builtin compgen -W 'search' -- "${cmdline[1]}" else - oscsearch="--help --csv -i --involved -v --verbose --description --title \ - --project --package -e --exact --repos-baseurl" - builtin compgen -W "${oscsearch}" -- "${cmdline[$count]}" + oscsearch="--help --csv -i --involved -v --verbose --description --title \ + --project --package -e --exact --repos-baseurl" + builtin compgen -W "${oscsearch}" -- "${cmdline[$count]}" fi ;; pr|prjresults) if ((count == 1)) ; then - builtin compgen -W 'pr prjresults' -- "${cmdline[1]}" + builtin compgen -W 'pr prjresults' -- "${cmdline[1]}" fi if ((count == 2)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" fi if ((count > 2)) ; then - case "${cmdline[$((count-1))]}" in - -n|--name-filter*) - builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[$count]}" - ;; - -s|--status-filter*) - OIFS="$IFS"; IFS=: - builtin compgen -W 'disabled:failed:finished:building:succeeded:broken:scheduled:expansion error:blocked' -- "${cmdline[$count]}" - IFS="$OIFS" - ;; - -p|--project*) - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[$count]}" - ;; - *) - builtin compgen -W "-n --name-filter -s --status-filter -c --csv -q --hide-legend" -- "${cmdline[$count]}" - ;; - esac + case "${cmdline[$((count-1))]}" in + -n|--name-filter*) + builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[$count]}" + ;; + -s|--status-filter*) + OIFS="$IFS"; IFS=: + builtin compgen -W 'disabled:failed:finished:building:succeeded:broken:scheduled:expansion error:blocked' -- "${cmdline[$count]}" + IFS="$OIFS" + ;; + -p|--project*) + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[$count]}" + ;; + *) + builtin compgen -W "-n --name-filter -s --status-filter -c --csv -q --hide-legend" -- "${cmdline[$count]}" + ;; + esac fi ;; r|results) if ((count == 1)) ; then - builtin compgen -W 'r results' -- "${cmdline[1]}" + builtin compgen -W 'r results' -- "${cmdline[1]}" fi if ((count == 2)) ; then - builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" + builtin compgen -W "$(command cat ~/.osc.projects)" -- "${cmdline[2]}" fi if ((count == 3)) ; then - builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}" + builtin compgen -W "$(command osc ls "${cmdline[2]}")" -- "${cmdline[3]}" fi if ((count > 3)) ; then - builtin compgen -W "-r --repo -a --arch -l --last-build --xml" -- "${cmdline[$count]}" + builtin compgen -W "-r --repo -a --arch -l --last-build --xml" -- "${cmdline[$count]}" fi ;; *) diff --git a/mktar.py b/mktar.py index 385b3fc4..c04b88bd 100755 --- a/mktar.py +++ b/mktar.py @@ -9,21 +9,21 @@ from osc import core release = False v = core.__version__ if (len(sys.argv) > 1 and sys.argv[1] == '-r'): - release = True + release = True if release: - if (v.endswith('_SVN')): - v=v[:-4] - print "don't forget to increase version in osc/core.py after release" + if (v.endswith('_SVN')): + v=v[:-4] + print "don't forget to increase version in osc/core.py after release" else: - v += subprocess.Popen(["svnversion", "."], stdout=subprocess.PIPE).stdout.read().strip() + v += subprocess.Popen(["svnversion", "."], stdout=subprocess.PIPE).stdout.read().strip() d = "osc-" + v f = d+".tar.bz2" subprocess.check_call(["svn", "export", ".", d]) if release: - # TODO: create tag for release - subprocess.check_call(["sed", "-ie", "/^__version__/s/_SVN//", d+"/osc/core.py"]) + # TODO: create tag for release + subprocess.check_call(["sed", "-ie", "/^__version__/s/_SVN//", d+"/osc/core.py"]) subprocess.check_call(["tar", "--force-local", "--owner=root", "--group=root", "-cjf", f, d]) subprocess.call(["rm", "-rf", d]) # XXX how to do this in python properly? print f diff --git a/osc-wrapper.py b/osc-wrapper.py index 4f24b147..b477dc64 100755 --- a/osc-wrapper.py +++ b/osc-wrapper.py @@ -1,12 +1,11 @@ #!/usr/bin/env python -# this wrapper exists so it can be put into /usr/bin, but still allows the +# this wrapper exists so it can be put into /usr/bin, but still allows the # python module to be called within the source directory during development - import sys, locale -# this is a hack to make osc work as expected with utf-8 characters, no matter -# how site.py is set... +# this is a hack to make osc work as expected with utf-8 characters, +# no matter how site.py is set... reload(sys) loc = locale.getdefaultlocale()[1] if not loc: @@ -21,6 +20,3 @@ osccli = commandline.Osc() r = babysitter.run(osccli) sys.exit(r) - - - diff --git a/osc/OscConfigParser.py b/osc/OscConfigParser.py index d63aea1a..f71ab59a 100644 --- a/osc/OscConfigParser.py +++ b/osc/OscConfigParser.py @@ -1,14 +1,14 @@ # Copyright 2008,2009 Marcus Huewe -# +# # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License version 2 # as published by the Free Software Foundation; -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA @@ -97,7 +97,7 @@ class SectionLine(Line): Line.__init__(self, sectname, 'section') self._lines = [] self._dict = dict - + def _find(self, name): for line in self._lines: if line.name == name: diff --git a/osc/babysitter.py b/osc/babysitter.py index 81a1b67c..b822be53 100644 --- a/osc/babysitter.py +++ b/osc/babysitter.py @@ -141,7 +141,7 @@ def run(prg): except AttributeError, e: print >>sys.stderr, e return 1 - + except RPMError, e: print >>sys.stderr, e return 1 diff --git a/osc/build.py b/osc/build.py index 9a8cc416..c94db7aa 100644 --- a/osc/build.py +++ b/osc/build.py @@ -30,7 +30,7 @@ change_personality = { 's390': 's390', } -can_also_build = { +can_also_build = { 'armv4l': [ 'armv4l' ], 'armv5el':[ 'armv4l', 'armv5el' ], 'armv6l' :[ 'armv4l', 'armv5el' ], @@ -83,7 +83,7 @@ class Buildinfo: self.buildarch = root.find('arch').text self.release = "0" if root.find('release') != None: - self.release = root.find('release').text + self.release = root.find('release').text self.downloadurl = root.get('downloadurl') self.debuginfo = 0 if root.find('debuginfo') != None: @@ -125,9 +125,9 @@ class Pac: def __init__(self, node, buildarch, pacsuffix, apiurl, localpkgs = []): self.mp = {} - for i in ['name', 'package', - 'version', 'release', - 'project', 'repository', + for i in ['name', 'package', + 'version', 'release', + 'project', 'repository', 'preinstall', 'vminstall', 'noinstall', 'runscripts', ]: self.mp[i] = node.get(i) @@ -151,7 +151,7 @@ class Pac: if pacsuffix == 'deb' and not (self.mp['name'] and self.mp['arch'] and self.mp['version']): raise oscerr.APIError( - "buildinfo for package %s/%s/%s is incomplete" + "buildinfo for package %s/%s/%s is incomplete" % (self.mp['name'], self.mp['arch'], self.mp['version'])) self.mp['apiurl'] = apiurl @@ -186,7 +186,7 @@ class Pac: self.fullpartname = os.path.join(self.localdir, self.partname) self.url_local = 'file://%s/' % self.fullfilename - # first, add the local URL + # first, add the local URL self.urllist.append(self.url_local) # remote URLs @@ -203,21 +203,21 @@ class Pac: def get_built_files(pacdir, pactype): if pactype == 'rpm': - b_built = subprocess.Popen(['find', os.path.join(pacdir, 'RPMS'), + b_built = subprocess.Popen(['find', os.path.join(pacdir, 'RPMS'), '-name', '*.rpm'], stdout=subprocess.PIPE).stdout.read().strip() - s_built = subprocess.Popen(['find', os.path.join(pacdir, 'SRPMS'), + s_built = subprocess.Popen(['find', os.path.join(pacdir, 'SRPMS'), '-name', '*.rpm'], stdout=subprocess.PIPE).stdout.read().strip() elif pactype == 'kiwi': - b_built = subprocess.Popen(['find', os.path.join(pacdir, 'KIWI'), + b_built = subprocess.Popen(['find', os.path.join(pacdir, 'KIWI'), '-type', 'f'], stdout=subprocess.PIPE).stdout.read().strip() else: b_built = subprocess.Popen(['find', os.path.join(pacdir, 'DEBS'), '-name', '*.deb'], stdout=subprocess.PIPE).stdout.read().strip() - s_built = subprocess.Popen(['find', os.path.join(pacdir, 'SOURCES.DEB'), + s_built = subprocess.Popen(['find', os.path.join(pacdir, 'SOURCES.DEB'), '-type', 'f'], stdout=subprocess.PIPE).stdout.read().strip() return s_built, b_built @@ -338,7 +338,7 @@ def main(opts, argv): return 1 # make it possible to override configuration of the rc file - for var in ['OSC_PACKAGECACHEDIR', 'OSC_SU_WRAPPER', 'OSC_BUILD_ROOT']: + for var in ['OSC_PACKAGECACHEDIR', 'OSC_SU_WRAPPER', 'OSC_BUILD_ROOT']: val = os.getenv(var) if val: if var.startswith('OSC_'): var = var[4:] @@ -373,23 +373,23 @@ def main(opts, argv): bi_file = None try: if opts.noinit: - if not os.path.isfile(bi_file_name): - print >>sys.stderr, '--noinit is not possible, no local build info file' - sys.exit(1) - print 'Use local .buildinfo.xml file as build description' - bi_file = open(bi_file_name, 'r') + if not os.path.isfile(bi_file_name): + print >>sys.stderr, '--noinit is not possible, no local build info file' + sys.exit(1) + print 'Use local .buildinfo.xml file as build description' + bi_file = open(bi_file_name, 'r') else: - print 'Getting buildinfo from server and store to local directory as .buildinfo.xml' - bi_file = open(bi_file_name, 'w+') - bi_text = ''.join(get_buildinfo(apiurl, - prj, - pac, - repo, - arch, - specfile=build_descr_data, - addlist=extra_pkgs)) - bi_file.write(bi_text) - bi_file.flush() + print 'Getting buildinfo from server and store to local directory as .buildinfo.xml' + bi_file = open(bi_file_name, 'w+') + bi_text = ''.join(get_buildinfo(apiurl, + prj, + pac, + repo, + arch, + specfile=build_descr_data, + addlist=extra_pkgs)) + bi_file.write(bi_text) + bi_file.flush() except urllib2.HTTPError, e: if e.code == 404: # check what caused the 404 @@ -415,7 +415,7 @@ def main(opts, argv): buildargs.append('--debug') buildargs = ' '.join(set(buildargs)) - # real arch of this machine + # real arch of this machine # vs. # arch we are supposed to build for if hostarch != bi.buildarch: @@ -445,7 +445,7 @@ def main(opts, argv): # transform 'url1, url2, url3' form into a list if 'urllist' in config: if type(config['urllist']) == str: - re_clist = re.compile('[, ]+') + re_clist = re.compile('[, ]+') urllist = [ i.strip() for i in re_clist.split(config['urllist'].strip()) ] else: urllist = config['urllist'] @@ -455,7 +455,7 @@ def main(opts, argv): urllist.append(bi.downloadurl + '/%(extproject)s/%(extrepository)s/%(arch)s/%(filename)s') urllist.append( '%(apiurl)s/build/%(project)s/%(repository)s/%(repoarch)s/%(repopackage)s/%(repofilename)s' ) - fetcher = Fetcher(cachedir = config['packagecachedir'], + fetcher = Fetcher(cachedir = config['packagecachedir'], urllist = urllist, api_host_options = config['api_host_options'], offline = opts.noinit, @@ -535,18 +535,18 @@ def main(opts, argv): vm_options="" if config['build-device'] and config['build-memory'] and config['build-type']: - if config['build-type'] == "kvm": - vm_options="--kvm " + config['build-device'] - elif config['build-type'] == "xen": - vm_options="--xen " + config['build-device'] - else: - print "ERROR: unknown VM is set ! (" + config['build-type'] + ")" - sys.exit(1) - if config['build-swap']: - vm_options+=" --swap " + config['build-swap'] - if config['build-memory']: - vm_options+=" --memory " + config['build-memory'] - + if config['build-type'] == "kvm": + vm_options="--kvm " + config['build-device'] + elif config['build-type'] == "xen": + vm_options="--xen " + config['build-device'] + else: + print "ERROR: unknown VM is set ! (" + config['build-type'] + ")" + sys.exit(1) + if config['build-swap']: + vm_options+=" --swap " + config['build-swap'] + if config['build-memory']: + vm_options+=" --memory " + config['build-memory'] + print 'Running build' # special handling for overlay and rsync-src/dest specialcmdopts = " " @@ -583,13 +583,13 @@ def main(opts, argv): cmd = '%s --root=%s --rpmlist=%s --dist=%s %s --arch=%s --release=%s %s %s %s' \ % (config['build-cmd'], config['build-root'], - rpmlist_file.name, - bc_file.name, + rpmlist_file.name, + bc_file.name, specialcmdopts, bi.buildarch, bi.release, vm_options, - build_descr, + build_descr, buildargs) if config['su-wrapper'].startswith('su '): @@ -603,7 +603,7 @@ def main(opts, argv): cmd = (change_personality.get(bi.buildarch, '') + ' ' + cmd).strip() rc = subprocess.call(cmd, shell=True) - if rc: + if rc: print print 'The buildroot was:', config['build-root'] sys.exit(rc) @@ -615,7 +615,7 @@ def main(opts, argv): if os.path.exists(pacdir): (s_built, b_built) = get_built_files(pacdir, bi.pacsuffix) - + print if s_built: print s_built print diff --git a/osc/cmdln.py b/osc/cmdln.py index 43d83b84..aa6090d5 100644 --- a/osc/cmdln.py +++ b/osc/cmdln.py @@ -103,7 +103,7 @@ class CmdlnUserError(Exception): def alias(*aliases): """Decorator to add aliases for Cmdln.do_* command handlers. - + Example: class MyShell(cmdln.Cmdln): @cmdln.alias("!", "sh") @@ -177,7 +177,7 @@ class RawCmdln(cmd.Cmd): man_options_header = MAN_OPTIONS_HEADER man_footer = MAN_FOOTER - def __init__(self, completekey='tab', + def __init__(self, completekey='tab', stdin=None, stdout=None, stderr=None): """Cmdln(completekey='tab', stdin=None, stdout=None, stderr=None) @@ -185,11 +185,11 @@ class RawCmdln(cmd.Cmd): completion key; it defaults to the Tab key. If completekey is not None and the readline module is available, command completion is done automatically. - + The optional arguments 'stdin', 'stdout' and 'stderr' specify alternate input, output and error output file objects; if not specified, sys.* are used. - + If 'stdout' but not 'stderr' is specified, stdout is used for error output. This is to provide least surprise for users used to only the 'stdin' and 'stdout' options with cmd.Cmd. @@ -230,7 +230,7 @@ class RawCmdln(cmd.Cmd): can return None to have no options at the top-level. Typically an instance of CmdlnOptionParser should be returned. """ - version = (self.version is not None + version = (self.version is not None and "%s %s" % (self._name_str, self.version) or None) return CmdlnOptionParser(self, version=version) @@ -256,14 +256,14 @@ class RawCmdln(cmd.Cmd): class MyCmd(cmdln.Cmdln): name = "mycmd" ... - + if __name__ == "__main__": MyCmd().main() By default this will use sys.argv to issue a single command to 'MyCmd', then exit. The 'loop' argument can be use to control interactive shell behaviour. - + Arguments: "argv" (optional, default sys.argv) is the command to run. It must be a sequence, where the first element is the @@ -316,7 +316,7 @@ class RawCmdln(cmd.Cmd): def cmd(self, argv): """Run one command and exit. - + "argv" is the arglist for the command to run. argv[0] is the command to run. If argv is an empty list then the 'emptyline' handler is run. @@ -352,7 +352,7 @@ class RawCmdln(cmd.Cmd): """Repeatedly issue a prompt, accept input, parse into an argv, and dispatch (via .precmd(), .onecmd() and .postcmd()), passing them the argv. In other words, start a shell. - + "intro" (optional) is a introductory message to print when starting the command loop. This overrides the class "intro" attribute, if any. @@ -404,7 +404,7 @@ class RawCmdln(cmd.Cmd): interpreted, but after the input prompt is generated and issued. "argv" is the cmd to run. - + Returns an argv to run (i.e. this method can modify the command to run). """ @@ -412,7 +412,7 @@ class RawCmdln(cmd.Cmd): def postcmd(self, argv): """Hook method executed just after a command dispatch is finished. - + "argv" is the command that was run. """ pass @@ -454,7 +454,7 @@ class RawCmdln(cmd.Cmd): """Hook called to handle a command for which there is no handler. "argv" is the command and arguments to run. - + The default implementation writes and error message to stderr and returns an error exit status. @@ -490,7 +490,7 @@ class RawCmdln(cmd.Cmd): "cmd" is the command name on which help was requested. "known" is a boolean indicating if this command is known (i.e. if there is a handler for it). - + Returns a return code. """ if known: @@ -564,7 +564,7 @@ class RawCmdln(cmd.Cmd): ${name} man """ self.stdout.write(self.man_header % { - 'date': date.today().strftime('%b %Y'), + 'date': date.today().strftime('%b %Y'), 'version': self.get_version(), 'name': self.name, 'ucname': self.name.upper() @@ -652,7 +652,7 @@ class RawCmdln(cmd.Cmd): i.e. using @cmdln.option decorators or manually setting the 'optparser' attribute on the 'do_*' method.) - Returns the processed help. + Returns the processed help. """ preprocessors = { "${name}": self._help_preprocess_name, @@ -687,7 +687,7 @@ class RawCmdln(cmd.Cmd): block = self.optparser.format_option_help() + '\n' else: block = "" - + help = help.replace(indent+marker+suffix, block, 1) return help @@ -724,7 +724,7 @@ class RawCmdln(cmd.Cmd): doc = handler.__doc__ else: doc = helpfunc() - + # Strip "${cmd_name}: " from the start of a command's doc. Best # practice dictates that command help strings begin with this, but # it isn't at all wanted for the command list. @@ -786,7 +786,7 @@ class RawCmdln(cmd.Cmd): handler = self._get_cmd_handler(cmdname) if not handler: raise CmdlnError("cannot preprocess '%s' into help string: " - "could not find command handler for %r" + "could not find command handler for %r" % (marker, cmdname)) s = cmdname if hasattr(handler, "aliases"): @@ -802,7 +802,7 @@ class RawCmdln(cmd.Cmd): handler = self._get_cmd_handler(cmdname) if not handler: raise CmdlnError("cannot preprocess '%s' into help string: " - "could not find command handler for %r" + "could not find command handler for %r" % (marker, cmdname)) indent, indent_width = _get_indent(marker, help) suffix = _get_trailing_whitespace(marker, help) @@ -838,7 +838,7 @@ class RawCmdln(cmd.Cmd): # keyword arguments from the command line. Could # *perhaps* consider: arg=value arg2=value2 ... warnings.warn("argument '**%s' on '%s.%s' command " - "handler will never get values" + "handler will never get values" % (name, self.__class__.__name__, func.func_name)) if co_flags & CO_FLAGS_ARGS: @@ -870,7 +870,7 @@ class RawCmdln(cmd.Cmd): handler = self._get_cmd_handler(cmdname) if not handler: raise CmdlnError("cannot preprocess '%s' into help string: " - "could not find command handler for %r" + "could not find command handler for %r" % (marker, cmdname)) indent, indent_width = _get_indent(marker, help) suffix = _get_trailing_whitespace(marker, help) @@ -963,7 +963,7 @@ class StopOptionProcessing(Exception): StopIteration. This is raised by _OptionParserEx's default "help" and "version" option actions and can be raised by custom option callbacks too. - + Hence the typical CmdlnOptionParser (a subclass of _OptionParserEx) usage is: @@ -1059,7 +1059,7 @@ class SubCmdOptionParser(_OptionParserEx): def option(*args, **kwargs): """Decorator to add an option to the optparser argument of a Cmdln subcommand. - + Example: class MyShell(cmdln.Cmdln): @cmdln.option("-f", "--force", help="force removal") @@ -1206,14 +1206,14 @@ class Cmdln(RawCmdln): raise CmdlnError("incorrect argcount for %s(): takes %d, must " "take 2 for 'argv' signature or 3+ for 'opts' " "signature" % (handler.__name__, co_argcount)) - + #---- internal support functions def _format_linedata(linedata, indent, indent_width): """Format specific linedata into a pleasant layout. - + "linedata" is a list of 2-tuples of the form: (, ) "indent" is a string to use for one level of indentation @@ -1242,7 +1242,7 @@ def _format_linedata(linedata, indent, indent_width): def _summarize_doc(doc, length=60): r"""Parse out a short one line summary from the given doclines. - + "doc" is the doc string to summarize. "length" is the max length for the summary @@ -1274,19 +1274,19 @@ def _summarize_doc(doc, length=60): summary = ' '.join(summlines) if len(summary) > length: - summary = summary[:length-3] + "..." + summary = summary[:length-3] + "..." return summary def line2argv(line): r"""Parse the given line into an argument vector. - + "line" is the line of input to parse. This may get niggly when dealing with quoting and escaping. The current state of this parsing may not be completely thorough/correct in this respect. - + >>> from cmdln import line2argv >>> line2argv("foo") ['foo'] @@ -1298,7 +1298,7 @@ def line2argv(line): ['foo', 'bar'] Quote handling: - + >>> line2argv("'foo bar'") ['foo bar'] >>> line2argv('"foo bar"') @@ -1379,9 +1379,9 @@ def line2argv(line): def argv2line(argv): r"""Put together the given argument vector into a command line. - + "argv" is the argument vector to process. - + >>> from cmdln import argv2line >>> argv2line(['foo']) 'foo' @@ -1414,18 +1414,18 @@ def argv2line(argv): # Recipe: dedent (0.1) in /Users/trentm/tm/recipes/cookbook def _dedentlines(lines, tabsize=8, skip_first_line=False): """_dedentlines(lines, tabsize=8, skip_first_line=False) -> dedented lines - + "lines" is a list of lines to dedent. "tabsize" is the tab width to use for indent width calculations. "skip_first_line" is a boolean indicating if the first line should be skipped for calculating the indent width and for dedenting. This is sometimes useful for docstrings and similar. - + Same as dedent() except operates on a sequence of lines. Note: the lines list is modified **in-place**. """ DEBUG = False - if DEBUG: + if DEBUG: print "dedent: dedent(..., tabsize=%d, skip_first_line=%r)"\ % (tabsize, skip_first_line) indents = [] @@ -1487,7 +1487,7 @@ def _dedent(text, tabsize=8, skip_first_line=False): "skip_first_line" is a boolean indicating if the first line should be skipped for calculating the indent width and for dedenting. This is sometimes useful for docstrings and similar. - + textwrap.dedent(s), but don't expand tabs to spaces """ lines = text.splitlines(1) diff --git a/osc/commandline.py b/osc/commandline.py index b5469f44..23ecc804 100755 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -542,11 +542,11 @@ class Osc(cmdln.Cmdln): src_update = None # we should check here for home::branch and default to update, but that would require OBS 1.7 server if opts.cleanup: - src_update = "cleanup" + src_update = "cleanup" elif opts.no_cleanup: - src_update = "update" + src_update = "update" elif opts.no_update: - src_update = "noupdate" + src_update = "noupdate" args = slash_split(args) @@ -616,15 +616,15 @@ Warning: failed to fetch meta data for '%s' package '%s' (new package?) """ \ % (dst_project, dst_package) pass - if devloc \ - and dst_project != devloc \ - and src_project != devloc: - print """\ + if devloc and \ + dst_project != devloc and \ + src_project != devloc: + print """\ Sorry, but a different project, %s, is defined as the place where development of the package %s primarily takes place. Please submit there instead, or use --nodevelproject to force direct submission.""" \ % (devloc, dst_package) - sys.exit(1) + sys.exit(1) if opts.diff: print 'old: %s/%s\nnew: %s/%s' %(dst_project, dst_package, src_project, src_package) rdiff = server_diff(apiurl, @@ -681,7 +681,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. project = args[0] package = None if len(args) > 1: - package = args[1] + package = args[1] if not opts.message: opts.message = edit_message() @@ -717,7 +717,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. package = args[1] devel_package = package if len(args) > 3: - devel_package = args[3] + devel_package = args[3] if not opts.message: opts.message = edit_message() @@ -892,7 +892,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. import time days = opts.days or conf.config['request_list_days'] since = '' - try: + try: days = int(days) except ValueError: days = 0 @@ -1036,9 +1036,9 @@ Please submit there instead, or use --nodevelproject to force direct submission. for p in packages: print "setting revision for package", p if opts.unset: - rev=-1 + rev=-1 else: - rev, dummy = parseRevisionOption(opts.revision) + rev, dummy = parseRevisionOption(opts.revision) set_link_rev(apiurl, project, p, rev) @@ -1092,7 +1092,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. return 1 if opts.current: - rev = show_upstream_rev(conf.config['apiurl'], src_project, src_package); + rev = show_upstream_rev(conf.config['apiurl'], src_project, src_package) if rev and not checkRevision(src_project, src_package, rev): print >>sys.stderr, 'Revision \'%s\' does not exist' % rev @@ -1207,7 +1207,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. if src_project == dst_project and \ src_package == dst_package and \ src_apiurl == dst_apiurl: - raise oscerr.WrongArgs('Source and destination are the same.') + raise oscerr.WrongArgs('Source and destination are the same.') if src_apiurl != dst_apiurl: opts.client_side_copy = True @@ -1218,7 +1218,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. comment = opts.message else: if not rev: - rev = show_upstream_rev(src_apiurl, src_project, src_package); + rev = show_upstream_rev(src_apiurl, src_project, src_package) comment = 'osc copypac from project:%s package:%s revision:%s' % ( src_project, src_package, rev ) r = copy_pac(src_apiurl, src_project, src_package, @@ -1256,7 +1256,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. home:USERNAME:branches:PROJECT/PACKAGE if nothing else specified. - With getpac or bco, the branched package will come from + With getpac or bco, the branched package will come from %(getpac_default_project)s if nothing else specified. @@ -1286,8 +1286,8 @@ Please submit there instead, or use --nodevelproject to force direct submission. tpackage = args[3] r = branch_pkg(conf.config['apiurl'], args[0], args[1], - nodevelproject=opts.nodevelproject, rev=opts.revision, - target_project=tproject, target_package=tpackage, + nodevelproject=opts.nodevelproject, rev=opts.revision, + target_project=tproject, target_package=tpackage, return_existing=opts.checkout) expected = 'home:%s:branches:%s' % (conf.config['user'], args[0]) @@ -1311,7 +1311,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. package = args[1] if tpackage: - package = tpackage + package = tpackage if opts.checkout: checkout_package(conf.config['apiurl'], r, package, expand_link=True, prj_dir=r) @@ -1353,11 +1353,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. pkgs = args[1:] if pkgs: - for pkg in pkgs: + for pkg in pkgs: # careful: if pkg is an empty string, the package delete request results # into a project delete request - which works recursively... - if pkg: - delete_package(conf.config['apiurl'], prj, pkg) + if pkg: + delete_package(conf.config['apiurl'], prj, pkg) elif len(meta_get_packagelist(conf.config['apiurl'], prj)) >= 1 and not opts.force: print >>sys.stderr, 'Project contains packages. It must be empty before deleting it. ' \ 'If you are sure that you want to remove this project and all its ' \ @@ -1521,8 +1521,8 @@ Please submit there instead, or use --nodevelproject to force direct submission. def do_install(self, subcmd, opts, *args): """${cmd_name}: install a package after build via zypper in -r - Not implemented yet. Use osc repourls, - select the url you best like (standard), + Not implemented yet. Use osc repourls, + select the url you best like (standard), chop off after the last /, this should work with zypper. @@ -1532,9 +1532,9 @@ Please submit there instead, or use --nodevelproject to force direct submission. args = slash_split(args) args = expand_proj_pack(args) - cmd = "sudo zypper -p http://download.opensuse.org/repositories/%s/%s --no-refresh -v in %s" % (re.sub(':',':/',args[0]), 'openSUSE_11.1', args[1]) + cmd = "sudo zypper -p http://download.opensuse.org/repositories/%s/%s --no-refresh -v in %s" % (re.sub(':',':/',args[0]), 'openSUSE_11.1', args[1]) print self.do_install.__doc__ - print "Example: \n" + cmd + print "Example: \n" + cmd def do_repourls(self, subcmd, opts, *args): @@ -1631,7 +1631,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. rev, dummy = parseRevisionOption(opts.revision) if rev==None: - rev="latest" + rev="latest" if rev and rev != "latest" and not checkRevision(project, package, rev): print >>sys.stderr, 'Revision \'%s\' does not exist' % rev @@ -1827,7 +1827,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. continue # ignore foo.rXX, foo.mine for files which are in 'C' state if os.path.splitext(filename)[0] in p.in_conflict: - continue + continue state = p.status(filename) if state == '?': @@ -2063,8 +2063,8 @@ Please submit there instead, or use --nodevelproject to force direct submission. side only. This is needed for removing the entire project. As a safety measure, projects must be empty (i.e., you need to delete all - packages first). - + packages first). + If you are sure that you want to remove a package and all its files use \'--force\' switch. Sometimes this also works without --force. @@ -2098,11 +2098,11 @@ Please submit there instead, or use --nodevelproject to force direct submission. if not p.todo: prj_dir, pac_dir = getPrjPacPaths(p.absdir) if is_project_dir(prj_dir): - if conf.config['do_package_tracking']: - prj = Project(prj_dir, False) - prj.delPackage(p, opts.force) - else: - print "WARNING: package tracking is disabled, operation skipped !" + if conf.config['do_package_tracking']: + prj = Project(prj_dir, False) + prj.delPackage(p, opts.force) + else: + print "WARNING: package tracking is disabled, operation skipped !" else: pathn = getTransActPath(p.dir) for filename in p.todo: @@ -2483,9 +2483,9 @@ Please submit there instead, or use --nodevelproject to force direct submission. help='Delete old build root before initializing it') @cmdln.option('--no-changelog', action='store_true', help='don\'t update the package changelog from a changes file') - @cmdln.option('--rsync-src', metavar='RSYNCSRCPATH', dest='rsyncsrc', + @cmdln.option('--rsync-src', metavar='RSYNCSRCPATH', dest='rsyncsrc', help='Copy folder to buildroot after installing all RPMs. Use together with --rsync-dest. This is the path on the HOST filesystem e.g. /tmp/linux-kernel-tree. It defines RSYNCDONE 1 .') - @cmdln.option('--rsync-dest', metavar='RSYNCDESTPATH', dest='rsyncdest', + @cmdln.option('--rsync-dest', metavar='RSYNCDESTPATH', dest='rsyncdest', help='Copy folder to buildroot after installing all RPMs. Use together with --rsync-src. This is the path on the TARGET filesystem e.g. /usr/src/packages/BUILD/linux-2.6 .') @cmdln.option('--overlay', metavar='OVERLAY', help='Copy overlay filesystem to buildroot after installing all RPMs .') @@ -2678,20 +2678,20 @@ Please submit there instead, or use --nodevelproject to force direct submission. """ if len(args) == 4: - apiurl = conf.config['apiurl'] - project = args[0] - package = args[1] - repository = args[2] - arch = args[3] + apiurl = conf.config['apiurl'] + project = args[0] + package = args[1] + repository = args[2] + arch = args[3] elif len(args) == 2: - wd = os.curdir - package = store_read_package(wd) - project = store_read_project(wd) - repository = args[0] - arch = args[1] - apiurl = store_read_apiurl(wd) + wd = os.curdir + package = store_read_package(wd) + project = store_read_project(wd) + repository = args[0] + arch = args[1] + apiurl = store_read_apiurl(wd) else: - raise oscerr.WrongArgs('Wrong number of arguments') + raise oscerr.WrongArgs('Wrong number of arguments') format = 'text' if opts.csv: @@ -2951,14 +2951,14 @@ Please submit there instead, or use --nodevelproject to force direct submission. architecture = args[3] elif len(args) == 2: if is_package_dir(os.getcwd()): - project = Project(os.getcwd()).name - p = Package(os.getcwd()) - package = p.name - apiurl = p.apiurl - repository = args[0] - architecture = args[1] + project = Project(os.getcwd()).name + p = Package(os.getcwd()) + package = p.name + apiurl = p.apiurl + repository = args[0] + architecture = args[1] else: - sys.exit('Local directory is no checkout package, neither it is specified. ' ) + sys.exit('Local directory is no checkout package, neither it is specified. ' ) else: sys.exit('Need either 2 or 4 arguments.' ) @@ -3011,7 +3011,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. osc my rq osc my ... requests (osc req list -a -B) ${cmd_option_list} - 'osc my' implements memonic shorthands for + 'osc my' implements memonic shorthands for specific 'osc search' and 'osc req list' commands. See there for additional help. """ @@ -3019,14 +3019,13 @@ Please submit there instead, or use --nodevelproject to force direct submission. if not args: raise oscerr.WrongArgs('Please specify one of projects/packages/requests') - if args[0] in ('requests', 'request', 'req', 'rq', - 'submitrequest', 'submitreq', 'submit', 'sr'): + if args[0] in ('requests', 'request', 'req', 'rq', 'submitrequest', 'submitreq', 'submit', 'sr'): ## FIXME: involvement bugowner is not reported here. ## this only reports usernames found in request history. opts.state = 'all' opts.type = '' - if args[0] in ('submitrequest', 'submitreq', 'submit', 'sr'): - opts.type = 'submit' + if args[0] in ('submitrequest', 'submitreq', 'submit', 'sr'): + opts.type = 'submit' opts.days = conf.config['request_list_days'] opts.mine = False opts.bugowner = True @@ -3090,14 +3089,14 @@ Please submit there instead, or use --nodevelproject to force direct submission. osc se ... ${cmd_option_list} - osc search does not find binary rpm names. Use + osc search does not find binary rpm names. Use http://software.opensuse.org/search?q=binaryname """ if opts.mine: opts.bugowner = True opts.package = True - + for_user = False if opts.involved or opts.bugowner or opts.maintainer: for_user = True @@ -3161,9 +3160,9 @@ Please submit there instead, or use --nodevelproject to force direct submission. ## ## search used to report the table as ## 'package project', I see no reason for having package before project. - ## But it definitly hinders copy-paste. + ## But it definitly hinders copy-paste. ## Changed to more normal 'project package' ordering. 2009-10-05, jw - ## + ## for j, i in l: result.extend([j, i]) @@ -3422,17 +3421,17 @@ Please submit there instead, or use --nodevelproject to force direct submission. m = show_package_meta(conf.config['apiurl'], prj, pac) tree = ET.parse(StringIO(''.join(m))) if not opts.nodevelproject and not opts.delete and not opts.add: - while tree.findall('devel'): - d = tree.find('devel') - prj = d.get('project', prj) - pac = d.get('package', pac) - print "Following to the development space:", prj, "/", pac - m = show_package_meta(conf.config['apiurl'], prj, pac) - tree = ET.parse(StringIO(''.join(m))) - if not tree.findall('person'): - print "No dedicated persons in package defined, showing the project persons !" - m = show_project_meta(conf.config['apiurl'], prj) - tree = ET.parse(StringIO(''.join(m))) + while tree.findall('devel'): + d = tree.find('devel') + prj = d.get('project', prj) + pac = d.get('package', pac) + print "Following to the development space:", prj, "/", pac + m = show_package_meta(conf.config['apiurl'], prj, pac) + tree = ET.parse(StringIO(''.join(m))) + if not tree.findall('person'): + print "No dedicated persons in package defined, showing the project persons !" + m = show_project_meta(conf.config['apiurl'], prj) + tree = ET.parse(StringIO(''.join(m))) else: raise oscerr.WrongArgs('I need at least one argument.') @@ -3451,7 +3450,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. print role, ":" for person in tree.findall('person'): if person.get('role') == role: - maintainers.append(person.get('userid')) + maintainers.append(person.get('userid')) if opts.email: emails = [] @@ -3492,12 +3491,12 @@ Please submit there instead, or use --nodevelproject to force direct submission. if len(args) == 1 and (args[0].startswith('http://') or args[0].startswith('https://')): - opts.method = 'GET' - opts.headers = None - opts.data = None - opts.file = None - return self.do_api('list', opts, *args) - + opts.method = 'GET' + opts.headers = None + opts.data = None + opts.file = None + return self.do_api('list', opts, *args) + args = slash_split(args) @@ -3533,7 +3532,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. This command checks out a package with merged source changes. It uses a 3-way merge to resolve file conflicts. After reviewing/repairing - the merge, use 'osc resolved ...' and 'osc ci' to re-create a + the merge, use 'osc resolved ...' and 'osc ci' to re-create a working source link. usage: @@ -3555,7 +3554,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. package = target_package = args[1] target_prj = args[2] if len(args) == 4: - target_package = args[3] + target_package = args[3] elif len(args) == 2: target_prj = prj = args[0] target_package = package = args[1] @@ -3656,8 +3655,8 @@ Please submit there instead, or use --nodevelproject to force direct submission. os.chdir(destdir) init_package_dir(apiurl, target_prj, target_package, destdir, files=False) os.chdir(olddir) - store_write_string(destdir, '_files', ''.join(meta)); - store_write_string(destdir, '_linkrepair', ''); + store_write_string(destdir, '_files', ''.join(meta)) + store_write_string(destdir, '_linkrepair', '') pac = Package(destdir) storedir = os.path.join(destdir, store) @@ -3741,7 +3740,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. osc signkey [--create|--delete] This command is for managing gpg keys. It shows the public key - by default. There is no way to download or upload the private + by default. There is no way to download or upload the private part of a key by design. However you can create a new own key. You may want to consider @@ -3768,14 +3767,14 @@ Please submit there instead, or use --nodevelproject to force direct submission. raise oscerr.WrongArgs('Please specify just the project') if opts.create: - url = makeurl(apiurl, ['source', prj], query='cmd=createkey') - f = http_POST(url) + url = makeurl(apiurl, ['source', prj], query='cmd=createkey') + f = http_POST(url) elif opts.delete: - url = makeurl(apiurl, ['source', prj, "_pubkey"]) - f = http_DELETE(url) + url = makeurl(apiurl, ['source', prj, "_pubkey"]) + f = http_DELETE(url) else: - url = makeurl(apiurl, ['source', prj, "_pubkey"]) - f = http_GET(url) + url = makeurl(apiurl, ['source', prj, "_pubkey"]) + f = http_GET(url) while 1: buf = f.read(16384) diff --git a/osc/conf.py b/osc/conf.py index b839f226..9269c6ac 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -6,11 +6,11 @@ """Read osc configuration and store it in a dictionary This module reads and parses ~/.oscrc. The resulting configuration is stored -for later usage in a dictionary named 'config'. +for later usage in a dictionary named 'config'. The .oscrc is kept mode 0600, so that it is not publically readable. -This gives no real security for storing passwords. +This gives no real security for storing passwords. If in doubt, use your favourite keyring. -Password is stored on ~/.oscrc as bz2 compressed and base64 encoded, so that is fairly +Password is stored on ~/.oscrc as bz2 compressed and base64 encoded, so that is fairly large and not to be recognized or remembered easily by an occasional spectator. If information is missing, it asks the user questions. @@ -45,18 +45,18 @@ try: GENERIC_KEYRING = True except: - try: - import gobject - gobject.set_application_name('osc') - import gnomekeyring - if os.environ['GNOME_DESKTOP_SESSION_ID']: - # otherwise gnome keyring bindings spit out errors, when you have - # it installed, but you are not under gnome - # (even though hundreds of gnome-keyring daemons got started in parallel) - # another option would be to support kwallet here - GNOME_KEYRING = gnomekeyring.is_available() - except: - pass + try: + import gobject + gobject.set_application_name('osc') + import gnomekeyring + if os.environ['GNOME_DESKTOP_SESSION_ID']: + # otherwise gnome keyring bindings spit out errors, when you have + # it installed, but you are not under gnome + # (even though hundreds of gnome-keyring daemons got started in parallel) + # another option would be to support kwallet here + GNOME_KEYRING = gnomekeyring.is_available() + except: + pass DEFAULTS = { 'apiurl': 'https://api.opensuse.org', 'user': 'your_username', @@ -93,7 +93,7 @@ DEFAULTS = { 'apiurl': 'https://api.opensuse.org', # local files to ignore with status, addremove, .... # local files to ignore with status, addremove, .... 'exclude_glob': '.osc CVS .svn .* _linkerror *~ #*# *.orig *.bak', - # keep passwords in plaintext. If you see this comment, your osc + # keep passwords in plaintext. If you see this comment, your osc # already uses the encrypted password, and only keeps them in plain text # for backwards compatibility. Default will change to 0 in future releases. 'plaintext_passwd': '1', @@ -278,7 +278,7 @@ def verify_cb(ok, store): if(not ok): err = store.get_error() cert = store.get_current_cert() - print "*** Certificate verify failed (depth=%s) ***" % store.get_error_depth() + print "*** Certificate verify failed (depth=%s) ***" % store.get_error_depth() print "Subject: ", cert.get_subject() print "Issuer: ", cert.get_issuer() print "Fingerprint: ", cert.get_fingerprint() @@ -337,7 +337,7 @@ def init_basicauth(config): cookie_file = os.path.expanduser(config['cookiejar']) cookiejar = cookielib.LWPCookieJar(cookie_file) - try: + try: cookiejar.load(ignore_discard=True) except IOError: try: @@ -361,7 +361,7 @@ def init_basicauth(config): if ctx.load_verify_locations(capath=capath, cafile=cafile) != 1: raise Exception('No CA certificates found') opener = m2urllib2.build_opener(ctx, urllib2.HTTPCookieProcessor(cookiejar), authhandler) else: - import sys; + import sys print >>sys.stderr, "WARNING: SSL certificate checks disabled. Connection is insecure!\n" opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar), authhandler) @@ -478,10 +478,10 @@ def add_section(filename, url, user, passwd): if file: file.close() -def get_config(override_conffile = None, +def get_config(override_conffile = None, override_apiurl = None, - override_debug = None, - override_http_debug = None, + override_debug = None, + override_http_debug = None, override_traceback = None, override_post_mortem = None, override_no_keyring = None, @@ -526,7 +526,7 @@ def get_config(override_conffile = None, re_clist = re.compile('[, ]+') config['extra-pkgs'] = [ i.strip() for i in re_clist.split(config['extra-pkgs'].strip()) if i ] - if config['extra-pkgs'] == []: + if config['extra-pkgs'] == []: config['extra-pkgs'] = None # collect the usernames, passwords and additional options for each api host @@ -581,10 +581,10 @@ def get_config(override_conffile = None, passwordx = cp.get(url, 'passx', raw=True) # especially on password! if password is None or password == 'your_password': try: - password = passwordx.decode('base64').decode('bz2'); + password = passwordx.decode('base64').decode('bz2') except: - print "%s: no credentials known" % url - password = 'your_password' + print "%s: no credentials known" % url + password = 'your_password' else: if not passwordx: print "%s: rewriting from plain pass to encoded pass\n" % url @@ -640,7 +640,8 @@ def get_config(override_conffile = None, # override values which we were called with if override_verbose: config['verbose'] = override_verbose + 1 - if not config.has_key('verbose') : config['verbose'] = 1; + if not config.has_key('verbose'): + config['verbose'] = 1 if override_debug: config['debug'] = override_debug diff --git a/osc/core.py b/osc/core.py index 19d70ce7..8b5282ec 100755 --- a/osc/core.py +++ b/osc/core.py @@ -101,7 +101,7 @@ It also does some weird stuff. i586 --> - + """ @@ -111,8 +111,8 @@ new_package_templ = """\ Title of New Package -LONG DESCRIPTION -GOES +LONG DESCRIPTION +GOES HERE @@ -120,11 +120,11 @@ HERE PUT_UPSTREAM_URL_HERE - @@ -193,10 +193,10 @@ buildstatus_symbols = {'succeeded': '.', # os.path.samefile is available only under Unix def os_path_samefile(path1, path2): - try: - return os.path.samefile(path1, path2) - except: - return os.path.realpath(path1) == os.path.realpath(path2) + try: + return os.path.samefile(path1, path2) + except: + return os.path.realpath(path1) == os.path.realpath(path2) class File: """represent a file, including its metadata""" @@ -229,9 +229,9 @@ class Serviceinfo: name = service.get('name') try: for param in service.findall('param'): - option = param.get('name', None) - value = param.text - name += " --" + option + " '" + value + "'" + option = param.get('name', None) + value = param.text + name += " --" + option + " '" + value + "'" self.commands.append(name) except: msg = 'invalid service format:\n%s' % ET.tostring(root) @@ -244,16 +244,16 @@ class Serviceinfo: temp_dir = tempfile.mkdtemp() name = call.split(None, 1)[0] if not os.path.exists("/usr/lib/obs/service/"+name): - msg = "ERROR: service is not installed !" - msg += "Can maybe solved with: zypper in obs-server-" + name - raise oscerr.APIError(msg) + msg = "ERROR: service is not installed !" + msg += "Can maybe solved with: zypper in obs-server-" + name + raise oscerr.APIError(msg) c = "/usr/lib/obs/service/" + call + " --outdir " + temp_dir ret = subprocess.call(c, shell=True) if ret != 0: - print "ERROR: service call failed: " + c + print "ERROR: service call failed: " + c for file in os.listdir(temp_dir): - os.rename( os.path.join(temp_dir, file), os.path.join(dir, "_service:"+name+":"+file) ) + os.rename( os.path.join(temp_dir, file), os.path.join(dir, "_service:"+name+":"+file) ) os.rmdir(temp_dir) class Linkinfo: @@ -332,7 +332,7 @@ class Project: self.pacs_available = meta_get_packagelist(self.apiurl, self.name) else: self.pacs_available = [] - + if conf.config['do_package_tracking']: self.pac_root = self.read_packages().getroot() self.pacs_have = [ pac.get('name') for pac in self.pac_root.findall('package') ] @@ -442,7 +442,7 @@ class Project: if filestate == 'M' or filestate == 'C' or \ filestate == 'A' or filestate == '?': can_delete = False - else: + else: del_files.append(file) if can_delete or force: for file in del_files: @@ -511,7 +511,7 @@ class Project: rev = p.linkinfo.lsrcmd5 print 'Unexpanding to rev', rev elif p.islink() and p.isexpanded(): - rev = p.latest_rev(); + rev = p.latest_rev() print 'Updating %s' % p.name p.update(rev, service_files) elif state == 'D': @@ -635,7 +635,7 @@ class Project: pac_path = '.' else: pac_path = os.path.join(self.dir, pac) - + project = store_read_project(pac_path) package = store_read_package(pac_path) apiurl = store_read_apiurl(pac_path) @@ -689,7 +689,7 @@ class Package: self.todo_delete = [] def info(self): - source_url = makeurl(self.apiurl, ['source', self.prjname, self.name]) + source_url = makeurl(self.apiurl, ['source', self.prjname, self.name]) r = info_templ % (self.prjname, self.name, self.absdir, self.apiurl, source_url, self.srcmd5, self.rev, self.linkinfo) return r @@ -698,7 +698,7 @@ class Package: f = File(n, None, st.st_size, st.st_mtime) self.filelist.append(f) self.filenamelist.append(n) - self.filenamelist_unvers.remove(n) + self.filenamelist_unvers.remove(n) shutil.copy2(os.path.join(self.dir, n), os.path.join(self.storedir, n)) def delete_file(self, n, force=False): @@ -749,7 +749,7 @@ class Package: os.unlink(upfilename) if self.islinkrepair(): os.unlink(os.path.join(self.dir, n + '.old')) - except: + except: pass self.in_conflict.remove(n) @@ -779,10 +779,10 @@ class Package: query = 'rev=upload' u = makeurl(self.apiurl, ['source', self.prjname, self.name, pathname2url(n)], query=query) http_DELETE(u) - + def put_source_file(self, n): - - # escaping '+' in the URL path (note: not in the URL query string) is + + # escaping '+' in the URL path (note: not in the URL query string) is # only a workaround for ruby on rails, which swallows it otherwise query = 'rev=upload' u = makeurl(self.apiurl, ['source', self.prjname, self.name, pathname2url(n)], query=query) @@ -792,27 +792,27 @@ class Package: def commit(self, msg=''): # commit only if the upstream revision is the same as the working copy's - upstream_rev = self.latest_rev(); + upstream_rev = self.latest_rev() if self.rev != upstream_rev: raise oscerr.WorkingCopyOutdated((self.absdir, self.rev, upstream_rev)) if not self.todo: self.todo = self.filenamelist_unvers + self.filenamelist - + pathn = getTransActPath(self.dir) have_conflicts = False for filename in self.todo: if not filename.startswith('_service:') and not filename.startswith('_service_'): - st = self.status(filename) - if st == 'A' or st == 'M': - self.todo_send.append(filename) - print statfrmt('Sending', os.path.join(pathn, filename)) - elif st == 'D': - self.todo_delete.append(filename) - print statfrmt('Deleting', os.path.join(pathn, filename)) - elif st == 'C': - have_conflicts = True + st = self.status(filename) + if st == 'A' or st == 'M': + self.todo_send.append(filename) + print statfrmt('Sending', os.path.join(pathn, filename)) + elif st == 'D': + self.todo_delete.append(filename) + print statfrmt('Deleting', os.path.join(pathn, filename)) + elif st == 'C': + have_conflicts = True if have_conflicts: print 'Please resolve all conflicts before committing using "osc resolved FILE"!' @@ -829,7 +829,7 @@ class Package: u = makeurl(self.apiurl, ['source', self.prjname, self.name], query=query) f = http_POST(u) - print 'Transmitting file data ', + print 'Transmitting file data ', try: for filename in self.todo_delete: # do not touch local files on commit -- @@ -881,9 +881,9 @@ class Package: if self.filenamelist.count('_service'): print 'The package contains a source service.' - for filename in self.todo: - if filename.startswith('_service:') and os.path.exists(filename): - os.unlink(filename) #remove local files + for filename in self.todo: + if filename.startswith('_service:') and os.path.exists(filename): + os.unlink(filename) # remove local files print_request_list(self.apiurl, self.prjname, self.name) def write_conflictlist(self): @@ -917,24 +917,24 @@ class Package: os.rename(filename, myfilename) mtime = self.findfilebyname(n).mtime - get_source_file(self.apiurl, self.prjname, self.name, n, + get_source_file(self.apiurl, self.prjname, self.name, n, revision=self.rev, targetfilename=upfilename) os.utime(upfilename, (-1, mtime)) if binary_file(myfilename) or binary_file(upfilename): - # don't try merging - shutil.copy2(upfilename, filename) - shutil.copy2(upfilename, storefilename) - self.in_conflict.append(n) - self.write_conflictlist() - return 'C' + # don't try merging + shutil.copy2(upfilename, filename) + shutil.copy2(upfilename, storefilename) + self.in_conflict.append(n) + self.write_conflictlist() + return 'C' else: # try merging # diff3 OPTIONS... MINE OLDER YOURS merge_cmd = 'diff3 -m -E %s %s %s > %s' % (myfilename, storefilename, upfilename, filename) # we would rather use the subprocess module, but it is not availablebefore 2.4 ret = subprocess.call(merge_cmd, shell=True) - + # "An exit status of 0 means `diff3' was successful, 1 means some # conflicts were found, and 2 means trouble." if ret == 0: @@ -992,13 +992,13 @@ class Package: self.filenamelist = [] self.filelist = [] for node in files_tree_root.findall('entry'): - try: - f = File(node.get('name'), - node.get('md5'), - int(node.get('size')), + try: + f = File(node.get('name'), + node.get('md5'), + int(node.get('size')), int(node.get('mtime'))) - except: - # okay, a very old version of _files, which didn't contain any metadata yet... + except: + # okay, a very old version of _files, which didn't contain any metadata yet... f = File(node.get('name'), '', 0, 0) self.filelist.append(f) self.filenamelist.append(f.name) @@ -1008,7 +1008,7 @@ class Package: self.linkrepair = os.path.isfile(os.path.join(self.storedir, '_linkrepair')) # gather unversioned files, but ignore some stuff - self.excluded = [ i for i in os.listdir(self.dir) + self.excluded = [ i for i in os.listdir(self.dir) for j in conf.config['exclude_glob'] if fnmatch.fnmatch(i, j) ] self.filenamelist_unvers = [ i for i in os.listdir(self.dir) @@ -1016,13 +1016,13 @@ class Package: if i not in self.filenamelist ] def islink(self): - """tells us if the package is a link (has 'linkinfo'). + """tells us if the package is a link (has 'linkinfo'). A package with linkinfo is a package which links to another package. Returns True if the package is a link, otherwise False.""" return self.linkinfo.islink() def isexpanded(self): - """tells us if the package is a link which is expanded. + """tells us if the package is a link which is expanded. Returns True if the package is expanded, otherwise False.""" return self.linkinfo.isexpanded() @@ -1114,7 +1114,7 @@ class Package: elif not exists and not exists_in_store and not known_by_meta: # this case shouldn't happen (except there was a typo in the filename etc.) raise IOError('osc: \'%s\' is not under version control' % n) - + return state def comparePac(self, cmp_pac): @@ -1123,7 +1123,7 @@ class Package: the filelist of the passed package to see which files were added, removed and changed. """ - + changed_files = [] added_files = [] removed_files = [] @@ -1158,12 +1158,12 @@ localfilelist: %s linkinfo: %s rev: %s 'todo' files: %s -""" % (self.name, - self.prjname, - self.dir, - '\n '.join(self.filenamelist), - self.linkinfo, - self.rev, +""" % (self.name, + self.prjname, + self.dir, + '\n '.join(self.filenamelist), + self.linkinfo, + self.rev, self.todo) return r @@ -1187,7 +1187,7 @@ rev: %s else: print 'no specfile was found - please specify one ' \ 'with --specfile' - sys.exit(1) + sys.exit(1) data = read_meta_from_spec(specfile, 'Summary', 'Url', '%description') self.summary = data['Summary'] @@ -1210,7 +1210,7 @@ rev: %s if url == None: url = ET.SubElement(tree, 'url') url.text = self.url - + u = makeurl(self.apiurl, ['source', self.prjname, self.name, '_meta']) mf = metafile(u, ET.tostring(tree)) @@ -1295,14 +1295,14 @@ rev: %s print 'At revision %s.' % self.rev if not service_files: - self.run_source_services() + self.run_source_services() def run_source_services(self): if self.filenamelist.count('_service'): - service = ET.parse(os.path.join(self.absdir, '_service')).getroot() - si = Serviceinfo() - si.read(service) - si.execute(self.absdir) + service = ET.parse(os.path.join(self.absdir, '_service')).getroot() + si = Serviceinfo() + si.read(service) + si.execute(self.absdir) def prepare_filelist(self): """Prepare a list of files, which will be processed by process_filelist @@ -1337,12 +1337,12 @@ rev: %s """Opens a package list in editor for eediting. This allows easy modifications of it just by simple text editing """ - + import tempfile tempdir = '/tmp' if sys.platform[:3] == 'win': tempdir = os.getenv('TEMP') - + (fd, filename) = tempfile.mkstemp(prefix = 'osc-filelist', suffix = '.txt', dir = tempdir) f = os.fdopen(fd, 'w') f.write(self.prepare_filelist()) @@ -1447,18 +1447,18 @@ class Request: try: src_prj = src_pkg = src_rev = dst_prj = dst_pkg = src_update = None if action.findall('source'): - n = action.find('source') - src_prj = n.get('project', None) - src_pkg = n.get('package', None) - src_rev = n.get('rev', None) + n = action.find('source') + src_prj = n.get('project', None) + src_pkg = n.get('package', None) + src_rev = n.get('rev', None) if action.findall('target'): - n = action.find('target') - dst_prj = n.get('project', None) - dst_pkg = n.get('package', None) + n = action.find('target') + dst_prj = n.get('project', None) + dst_pkg = n.get('package', None) if action.findall('options'): - n = action.find('options') - if n.findall('sourceupdate'): - src_update = n.find('sourceupdate').text.strip() + n = action.find('options') + if n.findall('sourceupdate'): + src_update = n.find('sourceupdate').text.strip() self.add_action(type, src_prj, src_pkg, src_rev, dst_prj, dst_pkg, src_update) except: msg = 'invalid request format:\n%s' % ET.tostring(root) @@ -1502,18 +1502,18 @@ class Request: ret = '%6d State:%-7s By:%-12s When:%-12s' % (self.reqid, self.state.name, self.state.who, self.state.when) for a in self.actions: - dst = "%s/%s" % (a.dst_project, a.dst_package) - if a.src_package == a.dst_package: - dst = a.dst_project + dst = "%s/%s" % (a.dst_project, a.dst_package) + if a.src_package == a.dst_package: + dst = a.dst_project - sr_source="" - if a.type=="submit": - sr_source="%s/%s -> " % (a.src_project, a.src_package) - if a.type=="change_devel": - dst = "developed in %s/%s" % (a.src_project, a.src_package) - sr_source="%s/%s" % (a.dst_project, a.dst_package) + sr_source="" + if a.type=="submit": + sr_source="%s/%s -> " % (a.src_project, a.src_package) + if a.type=="change_devel": + dst = "developed in %s/%s" % (a.src_project, a.src_package) + sr_source="%s/%s" % (a.dst_project, a.dst_package) - ret += '\n %s: %-50s %-20s ' % \ + ret += '\n %s: %-50s %-20s ' % \ (a.type, sr_source, dst) if self.statehistory and self.statehistory[0]: @@ -1536,26 +1536,26 @@ class Request: for action in self.actions: action_list=" %s: " % (action.type) if action.type=="submit": - r="" - if action.src_rev: - r="(r%s)" % (action.src_rev) - m="" - if action.src_update: - m="(%s)" % (action.src_update) - action_list=action_list+" %s/%s%s%s -> %s" % ( action.src_project, action.src_package, r, m, action.dst_project ) - if action.dst_package: - action_list=action_list+"/%s" % ( action.dst_package ) + r="" + if action.src_rev: + r="(r%s)" % (action.src_rev) + m="" + if action.src_update: + m="(%s)" % (action.src_update) + action_list=action_list+" %s/%s%s%s -> %s" % ( action.src_project, action.src_package, r, m, action.dst_project ) + if action.dst_package: + action_list=action_list+"/%s" % ( action.dst_package ) elif action.type=="delete": - action_list=action_list+" %s" % ( action.dst_project ) - if action.dst_package: - action_list=action_list+"/%s" % ( action.dst_package ) + action_list=action_list+" %s" % ( action.dst_project ) + if action.dst_package: + action_list=action_list+"/%s" % ( action.dst_package ) elif action.type=="change_devel": - action_list=action_list+" %s/%s developed in %s/%s" % \ + action_list=action_list+" %s/%s developed in %s/%s" % \ ( action.dst_project, action.dst_package, action.src_project, action.src_package ) action_list=action_list+"\n" s = """\ -Request #%s: +Request #%s: %s @@ -1598,7 +1598,7 @@ def is_project_dir(d): return os.path.exists(os.path.join(d, store, '_project')) and not \ os.path.exists(os.path.join(d, store, '_package')) - + def is_package_dir(d): return os.path.exists(os.path.join(d, store, '_project')) and \ os.path.exists(os.path.join(d, store, '_package')) @@ -1617,12 +1617,12 @@ def parse_disturl(disturl): apiurl = 'https://api.' + ".".join(apiurl.split('.')[1:]) return (apiurl, m.group('project'), m.group('source'), m.group('repository'), m.group('revision')) - + def slash_split(l): """Split command line arguments like 'foo/bar' into 'foo' 'bar'. This is handy to allow copy/paste a project/package combination in this form. - Trailing slashes are removed before the split, because the split would + Trailing slashes are removed before the split, because the split would otherwise give an additional empty string. """ r = [] @@ -1633,10 +1633,10 @@ def slash_split(l): def expand_proj_pack(args, idx=0, howmany=0): """looks for occurance of '.' at the position idx. - If howmany is 2, both proj and pack are expanded together + If howmany is 2, both proj and pack are expanded together using the current directory, or none of them, if not possible. If howmany is 0, proj is expanded if possible, then, if there - is no idx+1 element in args (or args[idx+1] == '.'), pack is also + is no idx+1 element in args (or args[idx+1] == '.'), pack is also expanded, if possible. If howmany is 1, only proj is expanded if possible. @@ -1651,7 +1651,7 @@ def expand_proj_pack(args, idx=0, howmany=0): if len(args) < idx: raise oscerr.WrongArgs('not enough argument, expected at least %d' % idx) - + if len(args) == idx: args += '.' if args[idx+0] == '.': @@ -1694,7 +1694,7 @@ def findpacs(files): else: pacs.append(p) return pacs - + def read_filemeta(dir): try: @@ -1728,7 +1728,7 @@ def read_inconflict(dir): def parseargs(list_of_args): """Convenience method osc's commandline argument parsing. - + If called with an empty tuple (or list), return a list containing the current directory. Otherwise, return a list of the arguments.""" if list_of_args: @@ -1738,9 +1738,9 @@ def parseargs(list_of_args): def filedir_to_pac(f): - """Takes a working copy path, or a path to a file inside a working copy, + """Takes a working copy path, or a path to a file inside a working copy, and returns a Package object instance - + If the argument was a filename, add it onto the "todo" list of the Package """ if os.path.isdir(f): @@ -1786,7 +1786,7 @@ def makeurl(baseurl, l, query=[]): query = urlencode(query) scheme, netloc = urlsplit(baseurl)[0:2] - return urlunsplit((scheme, netloc, '/'.join(l), query, '')) + return urlunsplit((scheme, netloc, '/'.join(l), query, '')) def http_request(method, url, headers={}, data=None, file=None, timeout=100): @@ -1796,14 +1796,14 @@ def http_request(method, url, headers={}, data=None, file=None, timeout=100): filefd = None if conf.config['http_debug']: - print + print print print '--', method, url if method == 'POST' and not file and not data: # adding data to an urllib2 request transforms it into a POST data = '' - + req = urllib2.Request(url) api_host_options=conf.get_apiurl_api_host_options(url) @@ -1934,12 +1934,12 @@ def check_store_version(dir): f = open(versionfile, 'w') f.write(__store_version__ + '\n') f.close() - return + return msg = 'The osc metadata of your working copy "%s"' % dir msg += '\nhas __store_version__ = %s, but it should be %s' % (v, __store_version__) msg += '\nPlease do a fresh checkout or update your client. Sorry about the inconvenience.' raise oscerr.WorkingCopyWrongVersion, msg - + def meta_get_packagelist(apiurl, prj): @@ -1973,9 +1973,9 @@ def meta_get_filelist(apiurl, prj, package, verbose=False, expand=False, revisio # rev = int(root.get('rev')) # don't force int. also allow srcmd5 here. rev = root.get('rev') for node in root.findall('entry'): - f = File(node.get('name'), - node.get('md5'), - int(node.get('size')), + f = File(node.get('name'), + node.get('md5'), + int(node.get('size')), int(node.get('mtime'))) f.rev = rev l.append(f) @@ -2113,7 +2113,7 @@ class metafile: print 'discarding', self.filename os.unlink(self.filename) return self - + # different types of metadata metatypes = { 'prj': { 'path': 'source/%s/_meta', @@ -2171,10 +2171,10 @@ def make_meta_url(metatype, path_args=None, apiurl=None): return makeurl(apiurl, [path]) -def edit_meta(metatype, - path_args=None, - data=None, - template_args=None, +def edit_meta(metatype, + path_args=None, + data=None, + template_args=None, edit=False, change_is_required=False, apiurl=None): @@ -2320,7 +2320,7 @@ def edit_message(footer='', template=''): while 1: subprocess.call('%s %s' % (editor, filename), shell=True) mtime = os.stat(filename).st_mtime - + if mtime_orig < mtime: msg = open(filename).read() os.unlink(filename) @@ -2343,9 +2343,9 @@ def create_delete_request(apiurl, project, package, message): import cgi if package: - package = """package="%s" """ % (package) + package = """package="%s" """ % (package) else: - package = "" + package = "" xml = """\ @@ -2365,8 +2365,8 @@ def create_delete_request(apiurl, project, package, message): return root.get('id') -def create_change_devel_request(apiurl, - devel_project, devel_package, +def create_change_devel_request(apiurl, + devel_project, devel_package, project, package, message): @@ -2380,9 +2380,9 @@ def create_change_devel_request(apiurl, %s -""" % (devel_project, +""" % (devel_project, devel_package, - project, + project, package, cgi.escape(message or '')) @@ -2393,15 +2393,15 @@ def create_change_devel_request(apiurl, return root.get('id') -def create_submit_request(apiurl, - src_project, src_package, +def create_submit_request(apiurl, + src_project, src_package, dst_project, dst_package, message, orev=None, src_update=None): import cgi options_block="" if src_update: - options_block="""%s """ % (src_update) + options_block="""%s """ % (src_update) # XXX: keep the old template for now in order to work with old obs instances xml = """\ @@ -2414,10 +2414,10 @@ def create_submit_request(apiurl, %s -""" % (src_project, +""" % (src_project, src_package, orev or show_upstream_rev(apiurl, src_project, src_package), - dst_project, + dst_project, dst_package, options_block, cgi.escape(message or '')) @@ -2440,8 +2440,8 @@ def get_request(apiurl, reqid): def change_request_state(apiurl, reqid, newstate, message=''): - u = makeurl(apiurl, - ['request', reqid], + u = makeurl(apiurl, + ['request', reqid], query={'cmd': 'changestate', 'newstate': newstate}) f = http_POST(u, data=message) return f.read() @@ -2454,10 +2454,10 @@ def get_request_list(apiurl, project, package, req_who='', req_state=('new',), r match = '' m = '' if not "all" in req_state: - for state in req_state: - if len(m): m += '%20or%20' - m += 'state/@name=\'%s\'' % quote_plus(state) - if len(m): match += "(" + m + ")" + for state in req_state: + if len(m): m += '%20or%20' + m += 'state/@name=\'%s\'' % quote_plus(state) + if len(m): match += "(" + m + ")" m = '' if req_who: if len(m): m += '%20and%20' @@ -2564,10 +2564,10 @@ def get_source_file(apiurl, prj, package, filename, targetfilename=None, revisio o.close() -def get_binary_file(apiurl, prj, repo, arch, - filename, +def get_binary_file(apiurl, prj, repo, arch, + filename, package = None, - target_filename = None, + target_filename = None, target_mtime = None, progress_meter = False): @@ -2613,7 +2613,7 @@ def get_binary_file(apiurl, prj, repo, arch, if target_mtime: os.utime(target_filename, (-1, target_mtime)) - # make sure that the temp file is cleaned up when we are interrupted + # make sure that the temp file is cleaned up when we are interrupted finally: try: os.unlink(tmpfilename) except: pass @@ -2860,12 +2860,12 @@ def make_dir(apiurl, project, package, pathname=None, prj_dir=None): pathname = pathname or getTransActPath(os.path.join(prj_dir, package)) if is_package_dir(prj_dir): - # we want this to become a project directory, + # we want this to become a project directory, # but it already is a package directory. raise oscerr.OscIOError(None, 'checkout_package: package/project clash. Moving myself away not implemented') if not is_project_dir(prj_dir): - # this directory could exist as a parent direory for one of our earlier + # this directory could exist as a parent direory for one of our earlier # checked out sub-projects. in this case, we still need to initialize it. print statfrmt('A', prj_dir) init_project_dir(apiurl, prj_dir, project) @@ -2883,7 +2883,7 @@ def make_dir(apiurl, project, package, pathname=None, prj_dir=None): return(os.path.join(prj_dir, package)) -def checkout_package(apiurl, project, package, +def checkout_package(apiurl, project, package, revision=None, pathname=None, prj_obj=None, expand_link=False, prj_dir=None, service_files=None): try: @@ -2901,14 +2901,14 @@ def checkout_package(apiurl, project, package, else: if conf.config['checkout_no_colon']: prj_dir = prj_dir.replace(':', '/') - + if not pathname: pathname = getTransActPath(os.path.join(prj_dir, package)) # before we create directories and stuff, check if the package actually # exists show_package_meta(apiurl, project, package) - + if expand_link: # try to read from the linkinfo # if it is a link we use the xsrcmd5 as the revision to be @@ -2923,9 +2923,9 @@ def checkout_package(apiurl, project, package, for filename in p.filenamelist: if service_files or not filename.startswith('_service:'): - p.updatefile(filename, revision) - #print 'A ', os.path.join(project, package, filename) - print statfrmt('A', os.path.join(pathname, filename)) + p.updatefile(filename, revision) + # print 'A ', os.path.join(project, package, filename) + print statfrmt('A', os.path.join(pathname, filename)) if conf.config['do_package_tracking']: # check if we can re-use an existing project object if prj_obj == None: @@ -2967,9 +2967,9 @@ def link_pac(src_project, src_package, dst_project, dst_package, force, rev='', except: src_meta = show_package_meta(conf.config['apiurl'], src_project, src_package) src_meta = replace_pkg_meta(src_meta, dst_package, dst_project) - + edit_meta('pkg', - path_args=(dst_project, dst_package), + path_args=(dst_project, dst_package), data=src_meta) # create the _link file @@ -2981,7 +2981,7 @@ def link_pac(src_project, src_package, dst_project, dst_package, force, rev='', print >>sys.stderr print >>sys.stderr, '_link file already exists...! Aborting' sys.exit(1) - + if rev: rev = 'rev="%s"' % rev else: @@ -3020,7 +3020,7 @@ def aggregate_pac(src_project, src_package, dst_project, dst_package, repo_map = src_meta = replace_pkg_meta(src_meta, dst_package, dst_project) edit_meta('pkg', - path_args=(dst_project, dst_package), + path_args=(dst_project, dst_package), data=src_meta) # create the _aggregate file @@ -3085,7 +3085,7 @@ def branch_pkg(apiurl, src_project, src_package, nodevelproject=False, rev=None, -def copy_pac(src_apiurl, src_project, src_package, +def copy_pac(src_apiurl, src_project, src_package, dst_apiurl, dst_project, dst_package, client_side_copy = False, keep_maintainers = False, @@ -3205,9 +3205,9 @@ def get_binarylist(apiurl, prj, repo, arch, package=None, verbose=False): else: l = [] for node in tree.findall('binary'): - f = File(node.get('filename'), - None, - int(node.get('size')), + f = File(node.get('filename'), + None, + int(node.get('size')), int(node.get('mtime'))) l.append(f) return l @@ -3316,7 +3316,7 @@ def get_prj_results(apiurl, prj, hide_legend=False, csv=False, status_filter=Non pacs_to_show = [] targets_to_show = [] - #filtering for Package Status + #filtering for Package Status if status_filter: if status_filter in buildstatus_symbols.values(): for txt, sym in buildstatus_symbols.items(): @@ -3331,7 +3331,7 @@ def get_prj_results(apiurl, prj, hide_legend=False, csv=False, status_filter=Non elif name_filter in pkg: pacs_to_show.append(pkg) - #filtering for Package Name + #filtering for Package Name elif name_filter: for pkg in pacs: if name_filter in pkg: @@ -3449,8 +3449,8 @@ def get_buildhistory(apiurl, prj, package, repository, arch, format = 'text'): r = [] for node in root.findall('entry'): rev = int(node.get('rev')) - srcmd5 = node.get('srcmd5') - versrel = node.get('versrel') + srcmd5 = node.get('srcmd5') + versrel = node.get('versrel') bcnt = int(node.get('bcnt')) t = time.localtime(int(node.get('time'))) t = time.strftime('%Y-%m-%d %H:%M:%S', t) @@ -3484,7 +3484,7 @@ def print_jobhistory(apiurl, prj, current_package, repository, arch, format = 't bcnt = node.get('bcnt') code = node.get('code') rev = int(node.get('rev')) - srcmd5 = node.get('srcmd5') + srcmd5 = node.get('srcmd5') rt = int(node.get('readytime')) readyt = time.localtime(rt) readyt = time.strftime('%Y-%m-%d %H:%M:%S', readyt) @@ -3497,7 +3497,7 @@ def print_jobhistory(apiurl, prj, current_package, repository, arch, format = 't waitbuild = "%2dh %2dm %2ds" % (waittm.tm_hour, waittm.tm_min, waittm.tm_sec) else: waitbuild = " %2dm %2ds" % (waittm.tm_min, waittm.tm_sec) - + if format == 'csv': print '%s|%s|%s|%s|%s' % (endtime, package, reason, code, waitbuild) else: @@ -3544,7 +3544,7 @@ def get_commitlog(apiurl, prj, package, revision, format = 'text'): t = time.strftime('%Y-%m-%d %H:%M:%S', t) if format == 'csv': - s = '%s|%s|%s|%s|%s|%s|%s' % (rev, user, t, srcmd5, version, + s = '%s|%s|%s|%s|%s|%s|%s' % (rev, user, t, srcmd5, version, comment.replace('\\', '\\\\').replace('\n', '\\n').replace('|', '\\|'), requestid) r.append(s) elif format == 'xml': @@ -3553,7 +3553,7 @@ def get_commitlog(apiurl, prj, package, revision, format = 'text'): r.append('%s' % user) r.append('%s' % t) r.append('%s' % requestid) - r.append('%s' % + r.append('%s' % comment.replace('&', '&').replace('<', '>').replace('>', '<')) r.append('') else: @@ -3730,7 +3730,7 @@ def parseRevisionOption(string): def checkRevision(prj, pac, revision, apiurl=None): """ - check if revision is valid revision, i.e. it is not + check if revision is valid revision, i.e. it is not larger than the upstream revision id """ if len(revision) == 32: @@ -3789,7 +3789,7 @@ def build_table(col_num, data = [], headline = [], width=1, csv = False): # calculate length for each column for i, row in enumerate(longest_col): longest_col[i] = row + width - # build rows + # build rows row = [] table = [] i = 0 @@ -3862,21 +3862,21 @@ def search(apiurl, search_list, kind, search_term, verbose = False, exact_matche def set_link_rev(apiurl, project, package, revision = None): url = makeurl(apiurl, ['source', project, package, '_link']) try: - f = http_GET(url) - root = ET.parse(f).getroot() + f = http_GET(url) + root = ET.parse(f).getroot() except urllib2.HTTPError, e: - e.osc_msg = 'Unable to get _link file in package \'%s\' for project \'%s\'' % (package, project) - raise + e.osc_msg = 'Unable to get _link file in package \'%s\' for project \'%s\'' % (package, project) + raise # set revision element if not revision: - src_project = root.attrib['project'] - src_package = root.attrib['package'] - root.attrib['rev'] = show_upstream_rev(apiurl, src_project, src_package); + src_project = root.attrib['project'] + src_package = root.attrib['package'] + root.attrib['rev'] = show_upstream_rev(apiurl, src_project, src_package) elif revision == -1: - del root.attrib['rev'] + del root.attrib['rev'] else: - root.attrib['rev'] = revision + root.attrib['rev'] = revision l = ET.tostring(root) # upload _link file again @@ -3963,7 +3963,7 @@ def unpack_srcrpm(srpm, dir, *files): def is_rpm(f): """check if the named file is an RPM package""" - try: + try: h = open(f, 'rb').read(4) except: return False @@ -3987,7 +3987,7 @@ def is_srcrpm(f): if h[7] == '\x01': return True else: - return False + return False def addMaintainer(apiurl, prj, pac, user): # for backward compatibility only @@ -4004,7 +4004,7 @@ def addPerson(apiurl, prj, pac, user, role="maintainer"): path_args=path, template_args=None, create_new=False) - + if data and get_user_meta(apiurl, user) != None: tree = ET.fromstring(''.join(data)) found = False @@ -4029,7 +4029,7 @@ def delMaintainer(apiurl, prj, pac, user): def delPerson(apiurl, prj, pac, user, role="maintainer"): """ delete a person from a package or project """ - path = quote_plus(prj), + path = quote_plus(prj), kind = 'prj' if pac: path = path + (quote_plus(pac), ) @@ -4062,22 +4062,22 @@ def setDevelProject(apiurl, prj, pac, dprj, dpkg=None): path_args=path, template_args=None, create_new=False) - + if data and show_project_meta(apiurl, dprj) != None: tree = ET.fromstring(''.join(data)) if not tree.find('devel') != None: ET.SubElement(tree, 'devel') elem = tree.find('devel') if dprj: - elem.attrib['project'] = dprj + elem.attrib['project'] = dprj else: - if elem.attrib.has_key('project'): - del elem.attrib['project'] + if elem.attrib.has_key('project'): + del elem.attrib['project'] if dpkg: - elem.attrib['package'] = dpkg + elem.attrib['package'] = dpkg else: - if elem.attrib.has_key('package'): - del elem.attrib['package'] + if elem.attrib.has_key('package'): + del elem.attrib['package'] edit_meta(metatype='pkg', path_args=path, data=ET.tostring(tree)) @@ -4230,7 +4230,7 @@ def getStatus(pacs, prj_obj=None, verbose=False, quiet=False): if prj_obj and conf.config['do_package_tracking']: state = prj_obj.get_state(p.name) if state != None and (state != ' ' or verbose): - lines.append(statfrmt(state, os.path.normpath(os.path.join(prj_obj.dir, p.name)))) + lines.append(statfrmt(state, os.path.normpath(os.path.join(prj_obj.dir, p.name)))) for filename in p.todo: if filename in p.excluded: @@ -4261,7 +4261,7 @@ def get_commit_message_template(pac): files = filter(lambda file: '.changes' in file and pac.status(file) in ('A', 'M'), pac.todo) if not files: return template - + for file in files: if pac.status(file) == 'M': diff += get_source_file_diff(pac.absdir, file, pac.rev) @@ -4270,7 +4270,7 @@ def get_commit_message_template(pac): for line in f: diff += '+' + line f.close() - + if diff: index = 0 diff = diff.split('\n') @@ -4287,7 +4287,7 @@ def get_commit_message_template(pac): template.append('') else: template.append(line[1:]) - + return template def check_filelist_before_commit(pacs): diff --git a/osc/fetch.py b/osc/fetch.py index e4849c1f..105dfb8f 100644 --- a/osc/fetch.py +++ b/osc/fetch.py @@ -17,7 +17,7 @@ except: def join_url(self, base_url, rel_url): """to override _join_url of MirrorGroup, because we want to pass full URLs instead of base URL where relative_url is added later... - IOW, we make MirrorGroup ignore relative_url""" + IOW, we make MirrorGroup ignore relative_url""" return base_url @@ -67,8 +67,8 @@ class Fetcher: # for use by the failure callback self.curpac = pac - if self.offline: - return True + if self.offline: + return True MirrorGroup._join_url = join_url mg = MirrorGroup(self.gr, pac.urllist) @@ -81,7 +81,7 @@ class Fetcher: try: # it returns the filename - ret = mg.urlgrab(pac.filename, + ret = mg.urlgrab(pac.filename, filename = pac.fullpartname, text = '(%s) %s' %(pac.project, pac.filename)) @@ -109,7 +109,7 @@ class Fetcher: pac.filename = canonname pac.fullfilename = os.path.join(pac.localdir, canonname) - os.rename(pac.fullpartname, pac.fullfilename); + os.rename(pac.fullpartname, pac.fullfilename) def dirSetup(self, pac): dir = os.path.join(self.cachedir, pac.localdir) @@ -143,7 +143,7 @@ class Fetcher: def verify_pacs(pac_list): - """Take a list of rpm filenames and run rpm -K on them. + """Take a list of rpm filenames and run rpm -K on them. In case of failure, exit. @@ -154,7 +154,7 @@ def verify_pacs(pac_list): if not pac_list: return - + # don't care about the return value because we check the # output anyway, and rpm always writes to stdout. @@ -166,19 +166,19 @@ def verify_pacs(pac_list): stderr=subprocess.STDOUT, close_fds=True).stdout # restore locale - if saved_LC_ALL: os.environ['LC_ALL'] = saved_LC_ALL; + if saved_LC_ALL: os.environ['LC_ALL'] = saved_LC_ALL else: os.environ.pop('LC_ALL') for line in o.readlines(): if not 'OK' in line: - print + print print >>sys.stderr, 'The following package could not be verified:' print >>sys.stderr, line sys.exit(1) if 'NOT OK' in line: - print + print print >>sys.stderr, 'The following package could not be verified:' print >>sys.stderr, line @@ -198,7 +198,7 @@ def verify_pacs(pac_list): - If you do not trust the packages, you should configure osc build for XEN or KVM - You may use --no-verify to skip the verification (which is a risk for your system). -""" % {'name': missing_key, +""" % {'name': missing_key, 'dir': os.path.expanduser('~')} else: diff --git a/osc/meter.py b/osc/meter.py index 286ff1fc..e52a709c 100644 --- a/osc/meter.py +++ b/osc/meter.py @@ -9,12 +9,12 @@ # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., -# 59 Temple Place, Suite 330, +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA -# this is basically a copy of python-urlgrabber's TextMeter class, +# this is basically a copy of python-urlgrabber's TextMeter class, # with support added for dynamical sizing according to screen size. # it uses getScreenWidth() scrapped from smart. # 2007-04-24, poeml @@ -22,7 +22,7 @@ from urlgrabber.progress import BaseMeter, format_time, format_number import sys, os - + def getScreenWidth(): import termios, struct, fcntl s = struct.pack('HHHH', 0, 0, 0, 0) diff --git a/osc/oscerr.py b/osc/oscerr.py index a45e5e99..d36f7afc 100644 --- a/osc/oscerr.py +++ b/osc/oscerr.py @@ -17,15 +17,15 @@ class UserAbort(OscBaseError): class ConfigError(OscBaseError): """Exception raised when there is an error in the config file""" - def __init__(self, msg, file): + def __init__(self, msg, fname): OscBaseError.__init__(self) self.msg = msg - self.file = file + self.file = fname class ConfigMissingApiurl(ConfigError): """Exception raised when a apiurl does not exist in the config file""" - def __init__(self, msg, file, url): - ConfigError.__init__(self, msg, file) + def __init__(self, msg, fname, url): + ConfigError.__init__(self, msg, fname) self.url = url class APIError(OscBaseError): @@ -60,7 +60,7 @@ class WorkingCopyWrongVersion(OscBaseError): class WorkingCopyOutdated(OscBaseError): """Exception raised when the working copy is outdated. - It takes a tuple with three arguments: path to wc, + It takes a tuple with three arguments: path to wc, revision that it has, revision that it should have. """ def __str__(self): @@ -92,7 +92,7 @@ class SignalInterrupt(Exception): class PackageExists(PackageError): """ - Exception raised when a local object already exists + Exception raised when a local object already exists """ def __init__(self, prj, pac, msg): PackageError.__init__(self, prj, pac) diff --git a/osc/util/ar.py b/osc/util/ar.py index 43e19bfe..4fbe8e52 100644 --- a/osc/util/ar.py +++ b/osc/util/ar.py @@ -1,14 +1,14 @@ # Copyright 2009 Marcus Huewe -# +# # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License version 2 # as published by the Free Software Foundation; -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA diff --git a/osc/util/cpio.py b/osc/util/cpio.py index 9299ed6c..fdb06187 100644 --- a/osc/util/cpio.py +++ b/osc/util/cpio.py @@ -1,14 +1,14 @@ # Copyright 2009 Marcus Huewe -# +# # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License version 2 # as published by the Free Software Foundation; -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA @@ -231,13 +231,13 @@ class CpioWrite: c.append('\0' * (len(''.join(c)) % 4)) c.append(content) - + c = ''.join(c) if len(c) % 4: c += '\0' * (4 - len(c) % 4) self.cpio += c - + def add_padding(self): if len(self.cpio) % 512: self.cpio += '\0' * (512 - len(self.cpio) % 512) diff --git a/osc_expand_link.pl b/osc_expand_link.pl index aebc33f8..0aa1cbf1 100755 --- a/osc_expand_link.pl +++ b/osc_expand_link.pl @@ -8,7 +8,6 @@ # 2008-03-25, jw, v0.3 -- go via api using iChains and ~/.oscrc # 2008-03-26, jw, v0.4 -- added linked file retrieval and usage. - use Data::Dumper; use LWP::UserAgent; use HTTP::Status; @@ -34,7 +33,7 @@ my $cfg = { @ISA = qw(LWP::UserAgent); sub new - { + { my $self = LWP::UserAgent::new(@_); $self->agent("osc_expand_link.pl/$version"); $self; @@ -46,20 +45,20 @@ my $cfg = { unless ($self->{auth}) { - print STDERR "Auth for $realm at $netloc\n"; - unless (open IN, "<", "$ENV{HOME}/.oscrc") - { - print STDERR "$ENV{HOME}/.oscrc: $!\n"; - return (undef, undef); - } - while (defined (my $line = )) - { - chomp $line; - $self->{auth}{pass} = $1 if $line =~ m{^pass\s*=\s*(\S+)}; - $self->{auth}{user} = $1 if $line =~ m{^user\s*=\s*(\S+)}; - } - close IN; - print STDERR "~/.oscrc: user=$self->{auth}{user}\n"; + print STDERR "Auth for $realm at $netloc\n"; + unless (open IN, "<", "$ENV{HOME}/.oscrc") + { + print STDERR "$ENV{HOME}/.oscrc: $!\n"; + return (undef, undef); + } + while (defined (my $line = )) + { + chomp $line; + $self->{auth}{pass} = $1 if $line =~ m{^pass\s*=\s*(\S+)}; + $self->{auth}{user} = $1 if $line =~ m{^user\s*=\s*(\S+)}; + } + close IN; + print STDERR "~/.oscrc: user=$self->{auth}{user}\n"; } return ($self->{auth}{user},$self->{auth}{pass}); } @@ -99,7 +98,7 @@ if (my $url = $ARGV[0]) die qq{osc_expand_link $version; -Usage: +Usage: osc co $cfg->{project} $cfg->{package} cd $cfg->{project}/$cfg->{package} @@ -127,30 +126,30 @@ to retrieve the original specfile behind a link. if ($url =~ m{^(.*/)?linked/(.*)$}) { $url = (defined $1) ? $1 : "$cfg->{project}/$cfg->{package}"; - my $file = $2; + my $file = $2; $url = "$source/$url" if $cfg->{apiurl} and $url !~ m{://}; - print STDERR "$url\n"; + print STDERR "$url\n"; my $dir = xml_parse(cred_get($url), 'merge'); - my $li = $dir->{directory}{linkinfo} || die "no linkinfo in $url\n"; - $url = "$source/$li->{project}/$li->{package}"; - mkdir("linked"); + my $li = $dir->{directory}{linkinfo} || die "no linkinfo in $url\n"; + $url = "$source/$li->{project}/$li->{package}"; + mkdir("linked"); - if ($file =~ m{\*}) - { + if ($file =~ m{\*}) + { my $dir = xml_parse(cred_get($url), 'merge'); - $dir = $dir->{directory} if $dir->{directory}; - my @list = sort map { $_->{name} } @{$dir->{entry}}; - my $file_re = "\Q$file\E"; $file_re =~ s{\\\*}{\.\*}g; - my @match = grep { $_ =~ m{^$file_re$} } @list; - die "pattern $file not found in\n @list\n" unless @match; - $file = $match[0]; - } - $url .= "/$file"; + $dir = $dir->{directory} if $dir->{directory}; + my @list = sort map { $_->{name} } @{$dir->{entry}}; + my $file_re = "\Q$file\E"; $file_re =~ s{\\\*}{\.\*}g; + my @match = grep { $_ =~ m{^$file_re$} } @list; + die "pattern $file not found in\n @list\n" unless @match; + $file = $match[0]; + } + $url .= "/$file"; - print STDERR "$url -> linked/$file\n"; - my $r = cred_getstore($url, "linked/$file"); + print STDERR "$url -> linked/$file\n"; + my $r = cred_getstore($url, "linked/$file"); print STDERR " Error: $r\n" if $r != RC_OK; - exit 0; + exit 0; } $url = "$cfg->{project}/$cfg->{package}/$url" unless $url =~ m{/}; @@ -179,19 +178,19 @@ for my $file (@{$dir->{entry}}) if (-f $file->{name}) { ## check the md5sum of the existing file and be happy. - $md5 = Digest::MD5->new; - open IN, "<", $file->{name} or die "md5sum($file->{name} failed: $!"; - $md5->addfile(*IN); - close IN; - if ($md5->hexdigest eq $file->{md5}) - { - print STDERR " - $file->{name} (md5 unchanged)\n"; - } - else - { - print STDERR "Modified: $file->{name}, please commit changes!\n"; - } - next; + $md5 = Digest::MD5->new; + open IN, "<", $file->{name} or die "md5sum($file->{name} failed: $!"; + $md5->addfile(*IN); + close IN; + if ($md5->hexdigest eq $file->{md5}) + { + print STDERR " - $file->{name} (md5 unchanged)\n"; + } + else + { + print STDERR "Modified: $file->{name}, please commit changes!\n"; + } + next; } print STDERR " get $file->{name}"; # fixme: xsrcmd5 is obsolete. @@ -216,10 +215,10 @@ sub slurp_file ## xml parser imported from w3dcm.pl and somewhat expanded. ## 2006-12-15, jw ## -## xml_parse assumes correct container closing. -## Any tag would closes an open . +## xml_parse assumes correct container closing. +## Any tag would closes an open . ## Thus xml_parse is not suitable for HTML. -## +## sub xml_parse { my ($text, $attr) = @_; @@ -236,13 +235,13 @@ sub xml_parse my $s = $tags[$i]->{offset} + $tags[$i]->{tag_len}; if (defined $tags[$i+1]) { - my $l = $tags[$i+1]->{offset} - $s; - $cdata = substr $text, $s, $l; - } + my $l = $tags[$i+1]->{offset} - $s; + $cdata = substr $text, $s, $l; + } else { - $cdata = substr $text, $s; - } + $cdata = substr $text, $s; + } # print "tag=$tag\n"; my $name = $1 if $tag =~ s{<([\?/]?[\w:-]+)\s*}{}; @@ -256,29 +255,29 @@ sub xml_parse xml_add_attr($x, $tag, $attr) unless $tag eq ''; if (!$close) - { - delete $t->{-cdata} if $t->{-cdata} and $t->{-cdata} =~ m{^\s*$}; - unless ($t->{$name}) - { - $t->{$name} = $x; - } - else - { - $t->{$name} = [ $t->{$name} ] unless ref $t->{$name} eq 'ARRAY'; - push @{$t->{$name}}, $x; - } - } + { + delete $t->{-cdata} if $t->{-cdata} and $t->{-cdata} =~ m{^\s*$}; + unless ($t->{$name}) + { + $t->{$name} = $x; + } + else + { + $t->{$name} = [ $t->{$name} ] unless ref $t->{$name} eq 'ARRAY'; + push @{$t->{$name}}, $x; + } + } if ($close) { - $t = pop @stack; - } + $t = pop @stack; + } elsif ($nest) { - push @stack, $t; - $t = $x; - } + push @stack, $t; + $t = $x; + } } print "stack=", Data::Dumper::Dumper(\@stack) if $verbose > 2; @@ -305,7 +304,7 @@ sub xml_slurp_file $xml = xml_parse($xml, $opt->{attr}); if (my $container = $opt->{container}) { - die "xml_slurp($file, '$container') malformed file, should have only one toplevel node.\n" + die "xml_slurp($file, '$container') malformed file, should have only one toplevel node.\n" unless scalar keys %$xml == 1; $container = (keys %$xml)[0] if $container eq '' or $container eq '*'; die "xml_slurp($file, '$container') toplevel tag missing or wrong.\n" unless $xml->{$container}; @@ -360,36 +359,35 @@ sub scalar_cdata my $val = $hash->{$key}; if (ref $val eq 'ARRAY') { - for my $i (0..$#$val) - { + for my $i (0..$#$val) + { scalar_cdata($hash->{$key}[$i]); - } - } + } + } elsif (ref $val eq 'HASH') { - my @k = keys %$val; - if (scalar(@k) == 1 && ($k[0] eq '-cdata')) - { - $hash->{$key} = $hash->{$key}{-cdata}; - } - else - { - delete $hash->{$key}{-cdata} if exists $val->{-cdata} && $val->{-cdata} =~ m{^\s*$}; + my @k = keys %$val; + if (scalar(@k) == 1 && ($k[0] eq '-cdata')) + { + $hash->{$key} = $hash->{$key}{-cdata}; + } + else + { + delete $hash->{$key}{-cdata} if exists $val->{-cdata} && $val->{-cdata} =~ m{^\s*$}; scalar_cdata($hash->{$key}); - } - } + } + } } delete $hash->{$selftag}; } - ## ## find_tags -- a brute force tag finder. ## This code is robust enough to parse the weirdest HTML. ## An Array containing hashes of { offset, name, tag_len } is returned. ## CDATA is skipped, but can be determined from gaps between tags. ## The name parser may chop names, so XML-style tag names are -## unreliable. +## unreliable. ## sub find_tags { @@ -405,39 +403,39 @@ sub find_tags if ($inquotes) { - $inquotes = 0 if $what eq '"'; - next; - } - + $inquotes = 0 if $what eq '"'; + next; + } + if ($incomment) { - $incomment = 0 if $what eq '-->'; - next; - } - + $incomment = 0 if $what eq '-->'; + next; + } + if ($what eq '"') { - $inquotes = 1; - next; - } + $inquotes = 1; + next; + } if ($what eq '