diff options
author | Sascha Silbe <sascha@silbe.org> | 2009-08-26 18:45:08 (GMT) |
---|---|---|
committer | Sascha Silbe <sascha@silbe.org> | 2009-08-26 18:45:08 (GMT) |
commit | ebfb8e24f5ce0f8db1432fb3f8dd871f257a5b89 (patch) | |
tree | 9a2975f16a74dce7894be3722042bf47f48dfd86 | |
parent | 46716ae1fc7e9dcee1919186f232a7cc413121d0 (diff) |
PEP8 fixes
-rw-r--r-- | sjhbuild/bundlemodule.py | 5 | ||||
-rw-r--r-- | sjhbuild/config.py | 43 | ||||
-rw-r--r-- | sjhbuild/depscheck.py | 1 | ||||
-rw-r--r-- | sjhbuild/main.py | 38 | ||||
-rw-r--r-- | sjhbuild/sysdeps.py | 64 |
5 files changed, 97 insertions, 54 deletions
diff --git a/sjhbuild/bundlemodule.py b/sjhbuild/bundlemodule.py index 16b36cc..f6071de 100644 --- a/sjhbuild/bundlemodule.py +++ b/sjhbuild/bundlemodule.py @@ -5,9 +5,12 @@ import os from jhbuild.errors import BuildStateError from jhbuild.modtypes import Package, get_branch, register_module_type -__all__ = [ 'BundleModule' ] + +__all__ = ['BundleModule'] + class BundleModule(Package): + type = 'bundle' PHASE_CHECKOUT = 'checkout' diff --git a/sjhbuild/config.py b/sjhbuild/config.py index 8d3ce29..defbca5 100644 --- a/sjhbuild/config.py +++ b/sjhbuild/config.py @@ -6,24 +6,28 @@ import distutils.sysconfig import sysdeps + class Config(jhbuild.config.Config): + def __init__(self, base_dir, rc_file): self.base_dir = base_dir - jhbuild.config.Config.__init__(self, os.path.join(self.base_dir, 'sugar.jhbuildrc')) + jhbuild.config.Config.__init__(self, os.path.join(self.base_dir, + 'sugar.jhbuildrc')) self._setup() def _setup(self): self.autogenargs = '' self.checkoutroot = os.path.join(self.base_dir, 'source') - self.tarballdir = os.path.join(self.base_dir, 'source') + self.tarballdir = os.path.join(self.base_dir, 'source') deps = sysdeps.get_packages() if not deps: - sys.stderr.write("ERROR: Dependencies information is missing (unknown distribution/version).\n") + sys.stderr.write('ERROR: Dependencies information is missing ' + '(unknown distribution/version).\n') sys.exit(126) - for package, source in deps : + for package, source in deps: if source and source not in self.skip: self.skip.append(source) @@ -36,13 +40,16 @@ class Config(jhbuild.config.Config): MY_PATH = os.getenv('PATH', 'Error') os.environ["PATH"] = MY_PATH + ':' + self.base_dir - + jhbuild.config.Config.setup_env(self) jhbuild.config.addpath('XDG_DATA_DIRS', '/usr/share') - jhbuild.config.addpath('XDG_DATA_DIRS', os.path.join(self.prefix, 'share')) + jhbuild.config.addpath('XDG_DATA_DIRS', + os.path.join(self.prefix, 'share')) - jhbuild.config.addpath('GTK_PATH', os.path.join(self.prefix, ['lib', 'lib64'][self.use_lib64], 'gtk-2.0', '')) + jhbuild.config.addpath('GTK_PATH', + os.path.join(self.prefix, ['lib', 'lib64'][self.use_lib64], + 'gtk-2.0', '')) jhbuild.config.addpath('GTK_DATA_PREFIX', self.prefix) os.environ['SUGAR_PREFIX'] = self.prefix @@ -57,21 +64,27 @@ class Config(jhbuild.config.Config): # We need to add the gtk-2.0 directory explicitly to # the Python path since '.pth' files (here pygtk.pth) # only work properly in system directories - pythonpath_basic = distutils.sysconfig.get_python_lib(prefix='').split('/', 1)[1] - jhbuild.config.addpath('PYTHONPATH', os.path.join(self.prefix, "lib", pythonpath_basic, 'gtk-2.0')) - jhbuild.config.addpath('PYTHONPATH', os.path.join(self.prefix, "lib64", pythonpath_basic, 'gtk-2.0')) + pythonlib = distutils.sysconfig.get_python_lib(prefix='') + pythonpath_basic = pythonlib.split('/', 1)[1] + jhbuild.config.addpath('PYTHONPATH', + os.path.join(self.prefix, 'lib', pythonpath_basic, 'gtk-2.0')) + jhbuild.config.addpath('PYTHONPATH', + os.path.join(self.prefix, 'lib64', pythonpath_basic, 'gtk-2.0')) # workaround for bug in jhbuild - # note: even for use_lib64 we need "lib" here as that's where distutils installs to - pythonpath_lib = os.path.join(self.prefix, "lib", pythonpath_basic) + # note: even for use_lib64 we need "lib" here as that's where + # distutils installs to + pythonpath_lib = os.path.join(self.prefix, 'lib', pythonpath_basic) jhbuild.config.addpath('PYTHONPATH', pythonpath_lib) - os.environ['PYTHON_LIB'] = distutils.sysconfig.get_python_lib(prefix=self.prefix) + os.environ['PYTHON_LIB'] = distutils.sysconfig.get_python_lib( + prefix=self.prefix) - os.environ['PYLINTRC'] = os.path.join(self.base_dir, 'scripts', 'data', 'pylintrc') + os.environ['PYLINTRC'] = os.path.join(self.base_dir, 'scripts', + 'data', 'pylintrc') if 'DBUS_SESSION_BUS_ADDRESS' in os.environ: - del os.environ['DBUS_SESSION_BUS_ADDRESS'] + del os.environ['DBUS_SESSION_BUS_ADDRESS'] if not 'SUGAR_PROFILE' in os.environ: os.environ['SUGAR_PROFILE'] = 'default' diff --git a/sjhbuild/depscheck.py b/sjhbuild/depscheck.py index f68a31a..7a22632 100644 --- a/sjhbuild/depscheck.py +++ b/sjhbuild/depscheck.py @@ -5,6 +5,7 @@ from jhbuild.commands import Command, register_command import sysdeps + class cmd_depscheck(Command): name = 'depscheck' diff --git a/sjhbuild/main.py b/sjhbuild/main.py index d758834..67ea70b 100644 --- a/sjhbuild/main.py +++ b/sjhbuild/main.py @@ -18,8 +18,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -import sys, os, errno +import errno import optparse +import os +import sys import traceback import gettext @@ -56,12 +58,14 @@ try: except (locale.Error, AssertionError): _encoding = 'ascii' + def uencode(s): if type(s) is unicode: return s.encode(_encoding, 'replace') else: return s + def uprint(*args): '''Print Unicode string encoded for the terminal''' for s in args[:-1]: @@ -69,14 +73,16 @@ def uprint(*args): s = args[-1] print uencode(s) + __builtin__.__dict__['uprint'] = uprint __builtin__.__dict__['uencode'] = uencode + def help_commands(option, opt_str, value, parser): thisdir = os.path.abspath(os.path.dirname(__file__)) thisdir = os.path.split(thisdir)[0] thisdir = os.path.join(thisdir, 'jhbuild', 'jhbuild') - + # import all available commands for fname in os.listdir(os.path.join(thisdir, 'commands')): name, ext = os.path.splitext(fname) @@ -86,9 +92,10 @@ def help_commands(option, opt_str, value, parser): __import__('jhbuild.commands.%s' % name) except ImportError: pass - + uprint(_('JHBuild commands are:')) - commands = [(x.name, x.doc) for x in jhbuild.commands.get_commands().values()] + commands = [(x.name, x.doc) + for x in jhbuild.commands.get_commands().values()] commands.sort() for name, description in commands: uprint(' %-15s %s' % (name, description)) @@ -96,17 +103,20 @@ def help_commands(option, opt_str, value, parser): uprint(_('For more information run "jhbuild <command> --help"')) parser.exit() + def main(base_dir, args): parser = optparse.OptionParser( usage=_('%prog [ -f config ] command [ options ... ]'), - description=_('Build a set of modules from diverse repositories in correct dependency order (such as GNOME).')) + description=_('Build a set of modules from diverse repositories in ' + 'correct dependency order (such as GNOME).')) parser.disable_interspersed_args() parser.add_option('--help-commands', action='callback', callback=help_commands, help=_('Information about available jhbuild commands')) parser.add_option('-f', '--file', action='store', metavar='CONFIG', type='string', dest='configfile', - default=os.environ.get("JHBUILDRC", os.path.join(os.environ['HOME'], '.jhbuildrc')), + default=os.environ.get('JHBUILDRC', + os.path.join(os.environ['HOME'], '.jhbuildrc')), help=_('use a non default configuration file')) parser.add_option('-m', '--moduleset', action='store', metavar='URI', type='string', dest='moduleset', default=None, @@ -120,11 +130,14 @@ def main(base_dir, args): try: config = Config(base_dir, options.configfile) except FatalError, exc: - sys.stderr.write('sugar-jhbuild: %s\n' % exc.args[0].encode(_encoding, 'replace')) + sys.stderr.write('sugar-jhbuild: %s\n' % \ + exc.args[0].encode(_encoding, 'replace')) sys.exit(1) - if options.moduleset: config.moduleset = options.moduleset - if options.nointeract: config.interact = False + if options.moduleset: + config.moduleset = options.moduleset + if options.nointeract: + config.interact = False if not args or args[0][0] == '-': command = 'build' # default to cvs update + compile @@ -140,11 +153,13 @@ def main(base_dir, args): try: rc = jhbuild.commands.run(command, config, args) except UsageError, exc: - sys.stderr.write('sugar-jhbuild %s: %s\n' % (command, exc.args[0].encode(_encoding, 'replace'))) + sys.stderr.write('sugar-jhbuild %s: %s\n' % (command, + exc.args[0].encode(_encoding, 'replace'))) parser.print_usage() sys.exit(1) except FatalError, exc: - sys.stderr.write('sugar-jhbuild %s: %s\n' % (command, exc.args[0].encode(_encoding, 'replace'))) + sys.stderr.write('sugar-jhbuild %s: %s\n' % (command, + exc.args[0].encode(_encoding, 'replace'))) sys.exit(1) except KeyboardInterrupt: uprint(_('Interrupted')) @@ -158,4 +173,3 @@ def main(base_dir, args): sys.exit(0) if rc: sys.exit(rc) - diff --git a/sjhbuild/sysdeps.py b/sjhbuild/sysdeps.py index eaeeb9b..a4887c9 100644 --- a/sjhbuild/sysdeps.py +++ b/sjhbuild/sysdeps.py @@ -9,20 +9,30 @@ scripts_dir = os.path.dirname(__file__) base_dir = os.path.dirname(scripts_dir) _cached_dname, _cached_dversion = None, None +_cached_packages = None +_UNSTABLE_NAMES = { + 'debian': 'unstable', + 'fedora': 'rawhide', + 'mandrivalinux': 'cooker', + 'ubuntu': 'unstable', +} + -def _pipe_lower(args) : +def _pipe_lower(args): out, err = subprocess.Popen(args, stdout=subprocess.PIPE).communicate() return out.strip().lower() + def get_distribution(): global _cached_dname, _cached_dversion - if _cached_dname : - return _cached_dname, _cached_dversion + if _cached_dname: + return _cached_dname, _cached_dversion if 'SJH_DISTRIBUTION' in os.environ: - _cached_dname, _cached_dversion = os.environ['SJH_DISTRIBUTION'].split('-') + _cached_dname, _cached_dversion = \ + os.environ['SJH_DISTRIBUTION'].split('-') return _cached_dname, _cached_dversion try: @@ -34,6 +44,7 @@ def get_distribution(): return _cached_dname, _cached_dversion + def check_package(package): name, version = get_distribution() if name in ['fedora', 'mandrivalinux']: @@ -46,23 +57,19 @@ def check_package(package): return None -def _check_suffix(name, suffixes) : - """ - Returns a list of all matching suffixes for <name>. - """ - return [name for suffix in suffixes if name.endswith(suffix)] -_unstable_names = { - 'debian': 'unstable', - 'fedora': 'rawhide', - 'mandrivalinux': 'cooker', - 'ubuntu': 'unstable', -} +def _check_suffix(name, suffixes): + """ + Returns a list of all matching suffixes for <name>. + """ + return [name for suffix in suffixes if name.endswith(suffix)] + + def _parse_dependencies(dname, dversion): if not (dname and dversion): return [] - suffixes = ['alldistros.xml', '%s-allversions.xml' % (dname,), + suffixes = ['alldistros.xml', '%s-allversions.xml' % (dname, ), '%s-%s.xml' % (dname, dversion)] dirname = os.path.join(base_dir, 'config', 'sysdeps') @@ -71,40 +78,45 @@ def _parse_dependencies(dname, dversion): if _check_suffix(fname, suffixes)] # check whether we have a file matching the exact distro version - if not [name for name in filenames if name.endswith(suffixes[-1])] : - if dname not in _unstable_names : - sys.stderr.write("ERROR: %r is not a supported distro. If you think it is sufficiently recent to contain everything the latest development version of Sugar needs and would like to see it supported, please file a ticket at dev.sugarlabs.org.\n" % (dname,)) + if not [name for name in filenames if name.endswith(suffixes[-1])]: + if dname not in _UNSTABLE_NAMES: + sys.stderr.write('ERROR: %r is not a supported distro. If you ' + 'think it is sufficiently recent to contain everything the ' + 'latest development version of Sugar needs and would like to ' + 'see it supported, please file a ticket at dev.sugarlabs.org.' + '\n' % (dname, )) return [] - uversion = _unstable_names[dname] - if (dversion == uversion) : + uversion = _UNSTABLE_NAMES[dname] + if (dversion == uversion): # no config for unstable return [] - sys.stderr.write("Warning: unknown distro version, automatic fallback to %s.\n" % (uversion,)) + sys.stderr.write('Warning: unknown distro version, automatic fallback ' + 'to %s.\n' % (uversion, )) return _parse_dependencies(dname, uversion) return [minidom.parse(fname) for fname in filenames if os.path.exists(fname)] -_cached_packages = None + def get_packages(): global _cached_packages - if _cached_packages is not None : + if _cached_packages is not None: return _cached_packages dname, dversion = get_distribution() documents = _parse_dependencies(dname, dversion) _cached_packages = [] - if not documents : + if not documents: return _cached_packages roots = [doc.childNodes[0] for doc in documents] - for node in reduce(operator.add, [root.childNodes for root in roots]) : + for node in reduce(operator.add, [root.childNodes for root in roots]): if node.nodeType == node.ELEMENT_NODE: if node.nodeName == 'package': name = node.getAttribute('name') |