Convert tabs to spaces in Python scripts (PEP-8) part 1.

This commit is contained in:
Benjamin Drung 2010-12-22 01:28:00 +01:00
parent 0a35d3d13d
commit 493597a500
5 changed files with 237 additions and 233 deletions

182
404main
View File

@ -31,131 +31,131 @@ import apt_pkg
import apt
def process_deps(cache, deps):
"""Takes a list of (build) dependencies and processes it."""
"""Takes a list of (build) dependencies and processes it."""
for basedep in [d.or_dependencies[0] for d in deps]:
if not packages.has_key(basedep.name) and basedep.name != '':
# Check the (build) dependencies recursively
find_main(cache, basedep.name)
for basedep in [d.or_dependencies[0] for d in deps]:
if not packages.has_key(basedep.name) and basedep.name != '':
# Check the (build) dependencies recursively
find_main(cache, basedep.name)
def get_package_version(cache, distro, pack):
if pack not in cache:
return None
for version in (cache[pack].candidate, cache[pack].installed):
if not version:
continue
for origin in version.origins:
if origin.archive == distro:
return version
return None
if pack not in cache:
return None
for version in (cache[pack].candidate, cache[pack].installed):
if not version:
continue
for origin in version.origins:
if origin.archive == distro:
return version
return None
# Cache::CompTypeDeb isn't exposed via python-apt
def comp_type_deb(op):
ops = ("", "<=", ">=", "<<", ">>", "=", "!=")
if (op & 15) < 7:
return ops[op & 15]
return ""
ops = ("", "<=", ">=", "<<", ">>", "=", "!=")
if (op & 15) < 7:
return ops[op & 15]
return ""
def find_main(cache, pack):
"""Searches the dependencies and build dependencies of a package recursively
to determine if they are all in the 'main' component or not."""
"""Searches the dependencies and build dependencies of a package recursively
to determine if they are all in the 'main' component or not."""
global packages
global packages
if pack in packages:
return
if pack in packages:
return
# Retrieve information about the package
version = get_package_version(cache, distro, pack)
# Retrieve information about the package
version = get_package_version(cache, distro, pack)
if not version:
packages[pack] = False
return
elif [origin for origin in version.origins if origin.component == 'main']:
packages[pack] = True
return
else:
if not packages.has_key(pack):
packages[pack] = False
if not version:
packages[pack] = False
return
elif [origin for origin in version.origins if origin.component == 'main']:
packages[pack] = True
return
else:
if not packages.has_key(pack):
packages[pack] = False
# Retrieve package dependencies
process_deps(cache, version.dependencies)
# Retrieve package dependencies
process_deps(cache, version.dependencies)
# Retrieve package build dependencies. There's no handy
# attribute on version for this, so unfortunately we have to
# do a lot of messing about with apt.
deps = []
src_records = apt_pkg.SourceRecords()
got_src = False
while src_records.lookup(version.source_name):
if pack in src_records.binaries:
got_src = True
break
if got_src:
for deptype, all_deps in src_records.build_depends.iteritems():
for or_deps in all_deps:
base_deps = []
for (name, ver, op) in or_deps:
base_deps.append(apt.package.BaseDependency(name, op, ver, False))
deps.append(apt.package.Dependency(base_deps))
# Retrieve package build dependencies. There's no handy
# attribute on version for this, so unfortunately we have to
# do a lot of messing about with apt.
deps = []
src_records = apt_pkg.SourceRecords()
got_src = False
while src_records.lookup(version.source_name):
if pack in src_records.binaries:
got_src = True
break
if got_src:
for deptype, all_deps in src_records.build_depends.iteritems():
for or_deps in all_deps:
base_deps = []
for (name, ver, op) in or_deps:
base_deps.append(apt.package.BaseDependency(name, op, ver, False))
deps.append(apt.package.Dependency(base_deps))
process_deps(cache, deps)
process_deps(cache, deps)
def main():
global packages, distro
global packages, distro
# Check if the amount of arguments is correct
if len(sys.argv) < 2 or len(sys.argv) > 3 or sys.argv[1] in ('help', '-h', '--help'):
print 'Usage: %s <package name> [<distribution>]' % sys.argv[0]
sys.exit(1)
# Check if the amount of arguments is correct
if len(sys.argv) < 2 or len(sys.argv) > 3 or sys.argv[1] in ('help', '-h', '--help'):
print 'Usage: %s <package name> [<distribution>]' % sys.argv[0]
sys.exit(1)
cache = apt.cache.Cache()
if len(sys.argv) == 3 and sys.argv[2]:
distro = sys.argv[2]
if not get_package_version(cache, distro, 'bash'):
print '«%s» is not a valid distribution.' % distro
print 'Remember that for 404main to work with a certain distribution it must be in your /etc/apt/sources.list file.'
sys.exit(1)
else:
distro = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).stdout.read().strip('\n')
if len(sys.argv) == 3 and sys.argv[2]:
distro = sys.argv[2]
if not get_package_version(cache, distro, 'bash'):
print '«%s» is not a valid distribution.' % distro
print 'Remember that for 404main to work with a certain distribution it must be in your /etc/apt/sources.list file.'
sys.exit(1)
else:
distro = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).stdout.read().strip('\n')
if not get_package_version(cache, distro, sys.argv[1]):
print 'Can\'t find package «%s» in distribution «%s».' % (sys.argv[1], distro)
sys.exit(1)
if not get_package_version(cache, distro, sys.argv[1]):
print 'Can\'t find package «%s» in distribution «%s».' % (sys.argv[1], distro)
sys.exit(1)
print 'Checking package «%s» in distribution «%s»...' % (sys.argv[1], distro)
print 'Checking package «%s» in distribution «%s»...' % (sys.argv[1], distro)
find_main(cache, sys.argv[1])
find_main(cache, sys.argv[1])
# True if everything checked until the point is in main
all_in_main = True
# True if everything checked until the point is in main
all_in_main = True
for package in packages:
if not packages[package]:
if all_in_main:
print 'The following packages aren\'t in main:'
all_in_main = False
print ' ', package
for package in packages:
if not packages[package]:
if all_in_main:
print 'The following packages aren\'t in main:'
all_in_main = False
print ' ', package
if all_in_main:
print 'Package «%s» and all its dependencies and build dependencies are in main.' % sys.argv[1]
if all_in_main:
print 'Package «%s» and all its dependencies and build dependencies are in main.' % sys.argv[1]
if __name__ == '__main__':
# Global variable to hold the status of all packages
packages = {}
# Global variable to hold the status of all packages
packages = {}
# Global variable to hold the target distribution
distro = ''
# Global variable to hold the target distribution
distro = ''
try:
main()
except KeyboardInterrupt:
print 'Aborted.'
sys.exit(1)
try:
main()
except KeyboardInterrupt:
print 'Aborted.'
sys.exit(1)

2
dgetlp
View File

@ -45,7 +45,7 @@ If you specify the -d option then it won't do anything, except download the
.dsc file, but just print the commands it would run otherwise.
Example:
%prog http://launchpadlibrarian.net/10348157/coreutils_5.97-5.4ubuntu1.dsc
%prog http://launchpadlibrarian.net/10348157/coreutils_5.97-5.4ubuntu1.dsc
"""
unpack_cmd = "dpkg-source -x "

View File

@ -26,22 +26,22 @@ import re, os, sys
from tempfile import mkstemp
try:
from debian.changelog import Changelog
from debian.changelog import Changelog
except ImportError:
print 'This utility requires modules from the «python-debian» package, which isn\'t currently installed.'
sys.exit(1)
print 'This utility requires modules from the «python-debian» package, which isn\'t currently installed.'
sys.exit(1)
if not os.path.exists('/usr/bin/reportbug'):
print 'This utility requires the «reportbug» package, which isn\'t currently installed.'
sys.exit(1)
print 'This utility requires the «reportbug» package, which isn\'t currently installed.'
sys.exit(1)
def get_most_recent_debian_version(changelog):
for v in changelog.get_versions():
if not re.search('(ubuntu|build)', v.full_version):
return v.full_version
for v in changelog.get_versions():
if not re.search('(ubuntu|build)', v.full_version):
return v.full_version
def get_bug_body(changelog):
return '''In Ubuntu, the attached patch was applied to achieve the following:
return '''In Ubuntu, the attached patch was applied to achieve the following:
## ---------------- REPLACE THIS WITH ACTUAL INFORMATION ---------------------
## Please add all necessary information about why the change needed to go in
@ -56,56 +56,56 @@ Thanks for considering the patch.
''' % ("\n".join([a for a in changelog._blocks[0].changes()]))
def gen_debdiff(changelog):
pkg = changelog.package
pkg = changelog.package
oldver = changelog._blocks[1].version
newver = changelog._blocks[0].version
oldver = changelog._blocks[1].version
newver = changelog._blocks[0].version
(fd, debdiff) = mkstemp()
os.close(fd)
(fd, debdiff) = mkstemp()
os.close(fd)
if os.system('bzr diff -r tag:%s > /dev/null 2>&1' % oldver) == 256:
print "Extracting bzr diff between %s and %s" % (oldver, newver)
cmd = 'bzr diff -r tag:%s | filterdiff -x "*changelog*" > %s' % (oldver, debdiff)
run_cmd(cmd)
else:
if oldver.epoch is not None:
oldver = str(oldver)[str(oldver).index(":")+1:]
if newver.epoch is not None:
newver = str(newver)[str(newver).index(":")+1:]
if os.system('bzr diff -r tag:%s > /dev/null 2>&1' % oldver) == 256:
print "Extracting bzr diff between %s and %s" % (oldver, newver)
cmd = 'bzr diff -r tag:%s | filterdiff -x "*changelog*" > %s' % (oldver, debdiff)
run_cmd(cmd)
else:
if oldver.epoch is not None:
oldver = str(oldver)[str(oldver).index(":")+1:]
if newver.epoch is not None:
newver = str(newver)[str(newver).index(":")+1:]
olddsc = '../%s_%s.dsc' % (pkg, oldver)
newdsc = '../%s_%s.dsc' % (pkg, newver)
olddsc = '../%s_%s.dsc' % (pkg, oldver)
newdsc = '../%s_%s.dsc' % (pkg, newver)
check_file(olddsc)
check_file(newdsc)
check_file(olddsc)
check_file(newdsc)
print "Generating debdiff between %s and %s" % (oldver, newver)
cmd = 'debdiff %s %s | filterdiff -x "*changelog*" > %s' % (olddsc, newdsc, debdiff)
run_cmd(cmd)
print "Generating debdiff between %s and %s" % (oldver, newver)
cmd = 'debdiff %s %s | filterdiff -x "*changelog*" > %s' % (olddsc, newdsc, debdiff)
run_cmd(cmd)
return debdiff
return debdiff
def check_file(fname, critical = True):
if os.path.exists(fname):
return fname
else:
if not critical: return False
print "Couldn't find «%s».\n" % fname
sys.exit(1)
if os.path.exists(fname):
return fname
else:
if not critical: return False
print "Couldn't find «%s».\n" % fname
sys.exit(1)
def edit_debdiff(debdiff):
cmd = 'sensible-editor %s' % (debdiff)
run_cmd(cmd)
cmd = 'sensible-editor %s' % (debdiff)
run_cmd(cmd)
def submit_bugreport(body, debdiff, changelog):
cmd = 'reportbug -P "User: ubuntu-devel@lists.ubuntu.com" -P "Usertags: origin-ubuntu natty ubuntu-patch" -T patch -A %s -B debian -i %s -V %s %s' % (debdiff, body, deb_version, changelog.package)
run_cmd(cmd)
cmd = 'reportbug -P "User: ubuntu-devel@lists.ubuntu.com" -P "Usertags: origin-ubuntu natty ubuntu-patch" -T patch -A %s -B debian -i %s -V %s %s' % (debdiff, body, deb_version, changelog.package)
run_cmd(cmd)
def run_cmd(cmd):
if os.getenv('DEBUG'):
print "%s\n" % cmd
os.system(cmd)
if os.getenv('DEBUG'):
print "%s\n" % cmd
os.system(cmd)
changelog_file = check_file('debian/changelog', critical = False) or check_file('../debian/changelog')
changelog = Changelog(file(changelog_file).read())

View File

@ -19,112 +19,116 @@ import optparse
import os
import sys
from ubuntutools.logger import Logger
default_whitelisted_mimetypes = [
"application/vnd.font-fontforge-sfd", # font source: fontforge
"application/x-elc",
"application/x-empty",
"application/x-font-otf", # font object and source
"application/x-font-ttf", # font object and source
"application/x-font-woff", # font object and source
"application/x-symlink",
"application/xml",
"audio/x-wav",
"font/otf", # font object and source
"font/ttf", # font object and source
"image/gif",
"image/jpeg",
"image/png",
"image/svg+xml",
"image/x-icns",
"image/x-ico",
"image/x-ms-bmp",
"image/x-portable-pixmap",
"message/rfc822",
"text/html",
"text/plain",
"text/rtf",
"text/troff",
"text/x-asm",
"text/x-c",
"text/x-c++",
"text/x-diff",
"text/x-fortran",
"text/x-java",
"text/x-lisp",
"text/x-m4",
"text/x-makefile",
"text/x-msdos-batch",
"text/x-pascal",
"text/x-perl",
"text/x-php",
"text/x-po",
"text/x-shellscript",
"text/x-tex",
"text/x-texinfo",
"application/vnd.font-fontforge-sfd", # font source: fontforge
"application/x-elc",
"application/x-empty",
"application/x-font-otf", # font object and source
"application/x-font-ttf", # font object and source
"application/x-font-woff", # font object and source
"application/x-symlink",
"application/xml",
"audio/x-wav",
"font/otf", # font object and source
"font/ttf", # font object and source
"image/gif",
"image/jpeg",
"image/png",
"image/svg+xml",
"image/x-icns",
"image/x-ico",
"image/x-ms-bmp",
"image/x-portable-pixmap",
"message/rfc822",
"text/html",
"text/plain",
"text/rtf",
"text/troff",
"text/x-asm",
"text/x-c",
"text/x-c++",
"text/x-diff",
"text/x-fortran",
"text/x-java",
"text/x-lisp",
"text/x-m4",
"text/x-makefile",
"text/x-msdos-batch",
"text/x-pascal",
"text/x-perl",
"text/x-php",
"text/x-po",
"text/x-shellscript",
"text/x-tex",
"text/x-texinfo",
]
default_whitelisted_extensions = [
".fea", # font source format: afdko (Adobe font development kit for OpenType)
".fog", # font source format: Fontographer
".g2n", # font source format: fontforge
".gdh", # font source format: Graphite (headers)
".gdl", # font source format: Graphite
".glyph", # font source format: cross-toolkit UFO
".plate", # font source format: Spiro
".rsa",
".sfd", # font source format: fontforge
".sfdir", # font source format: fontforge
".ttx", # font source format: fonttools
".ufo", # font source format: cross-toolkit UFO
".vfb" # font source format: FontLab
".vtp", # font source format: OpenType (VOLT)
".xgf", # font source format: Xgridfit
".fea", # font source format: afdko (Adobe font development kit for OpenType)
".fog", # font source format: Fontographer
".g2n", # font source format: fontforge
".gdh", # font source format: Graphite (headers)
".gdl", # font source format: Graphite
".glyph", # font source format: cross-toolkit UFO
".plate", # font source format: Spiro
".rsa",
".sfd", # font source format: fontforge
".sfdir", # font source format: fontforge
".ttx", # font source format: fonttools
".ufo", # font source format: cross-toolkit UFO
".vfb" # font source format: FontLab
".vtp", # font source format: OpenType (VOLT)
".xgf", # font source format: Xgridfit
]
def main(whitelisted_mimetypes, whitelisted_extensions, directory, verbose=False):
ms = magic.open(magic.MAGIC_MIME_TYPE)
ms.load()
def main(whitelisted_mimetypes, whitelisted_extensions, directory,
verbose=False):
ms = magic.open(magic.MAGIC_MIME_TYPE)
ms.load()
for root, dirs, files in os.walk(directory):
for f in files:
mimetype = ms.file(os.path.join(root, f))
if mimetype not in whitelisted_mimetypes:
if not filter(lambda x: f.lower().endswith(x), whitelisted_extensions):
if verbose:
print "%s (%s)" % (os.path.join(root, f), mimetype)
else:
print os.path.join(root, f)
for d in (".bzr", "CVS", ".git", ".svn"):
if d in dirs:
dirs.remove(d)
for root, dirs, files in os.walk(directory):
for f in files:
mimetype = ms.file(os.path.join(root, f))
if mimetype not in whitelisted_mimetypes:
if not filter(lambda x: f.lower().endswith(x),
whitelisted_extensions):
if verbose:
print "%s (%s)" % (os.path.join(root, f), mimetype)
else:
print os.path.join(root, f)
for d in (".bzr", "CVS", ".git", ".svn"):
if d in dirs:
dirs.remove(d)
if __name__ == "__main__":
script_name = os.path.basename(sys.argv[0])
usage = "%s [options]" % (script_name)
epilog = "See %s(1) for more info." % (script_name)
parser = optparse.OptionParser(usage=usage, epilog=epilog)
script_name = os.path.basename(sys.argv[0])
usage = "%s [options]" % (script_name)
epilog = "See %s(1) for more info." % (script_name)
parser = optparse.OptionParser(usage=usage, epilog=epilog)
parser.add_option("-v", "--verbose", help="print more information",
dest="verbose", action="store_true", default=False)
parser.add_option("-d", "--directory",
help="check the files in the specified directory",
dest="directory", default=".")
parser.add_option("-m", "--mimetype", metavar="MIMETYPE",
help="Add MIMETYPE to list of whitelisted mimetypes.",
dest="whitelisted_mimetypes", action="append",
default=default_whitelisted_mimetypes)
parser.add_option("-e", "--extension", metavar="EXTENSION",
help="Add EXTENSION to list of whitelisted extensions.",
dest="whitelisted_extensions", action="append",
default=default_whitelisted_extensions)
parser.add_option("-v", "--verbose", help="print more information",
dest="verbose", action="store_true", default=False)
parser.add_option("-d", "--directory",
help="check the files in the specified directory",
dest="directory", default=".")
parser.add_option("-m", "--mimetype", metavar="MIMETYPE",
help="Add MIMETYPE to list of whitelisted mimetypes.",
dest="whitelisted_mimetypes", action="append",
default=default_whitelisted_mimetypes)
parser.add_option("-e", "--extension", metavar="EXTENSION",
help="Add EXTENSION to list of whitelisted extensions.",
dest="whitelisted_extensions", action="append",
default=default_whitelisted_extensions)
(options, args) = parser.parse_args()
(options, args) = parser.parse_args()
if len(args) != 0:
print >> sys.stderr, "%s: This script does not take any additional parameters." % \
(script_name)
sys.exit(1)
if len(args) != 0:
Logger.error("This script does not take any additional parameters.")
sys.exit(1)
whitelisted_extensions = map(lambda x: x.lower(), options.whitelisted_extensions)
main(options.whitelisted_mimetypes, whitelisted_extensions,
options.directory, options.verbose)
whitelisted_extensions = map(lambda x: x.lower(),
options.whitelisted_extensions)
main(options.whitelisted_mimetypes, whitelisted_extensions,
options.directory, options.verbose)

View File

@ -37,7 +37,7 @@ usage = "%s [options]" % (script_name)
epilog = "See %s(1) for more info." % (script_name)
parser = optparse.OptionParser(usage=usage, epilog=epilog)
parser.add_option("-q", "--quiet", help="print no informational messages",
dest="quiet", action="store_true", default=False)
dest="quiet", action="store_true", default=False)
(options, args) = parser.parse_args()
sys.exit(ubuntutools.update_maintainer.update_maintainer(not options.quiet))