diff options
author | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2009-02-24 10:03:53 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2009-02-24 10:03:53 +0530 |
commit | 0989c022195975311fe550d2a317f7cf759184a1 (patch) | |
tree | b0d6fc5dde69aead1c60b863f455d5ffc78c9126 /slave | |
parent | Fix setup-master.py to not suck monkey balls (diff) | |
download | autotua-0989c022195975311fe550d2a317f7cf759184a1.tar.gz autotua-0989c022195975311fe550d2a317f7cf759184a1.tar.bz2 autotua-0989c022195975311fe550d2a317f7cf759184a1.zip |
Minor changes to follow Pythonesque idioms
* try..finally instead of osp.exists()
* Explicit relative imports
Diffstat (limited to 'slave')
-rw-r--r-- | slave/autotua/config.py | 41 | ||||
-rw-r--r-- | slave/autotua/crypt/__init__.py | 10 |
2 files changed, 30 insertions, 21 deletions
diff --git a/slave/autotua/config.py b/slave/autotua/config.py index 7ab4267..704a310 100644 --- a/slave/autotua/config.py +++ b/slave/autotua/config.py @@ -1,5 +1,5 @@ # vim: set sw=4 sts=4 et : -# Copyright: 2008 Gentoo Foundation +# Copyright: 2008-2009 Gentoo Foundation # Author(s): Nirbheek Chauhan <nirbheek.chauhan@gmail.com> # License: GPL-3 # @@ -7,10 +7,12 @@ # """ -Default configuration, overriden by /etc/autotua/slave.cfg +Default configuration, overriden by const.CONFIG_PATH """ -import os, ConfigParser, const +from __future__ import with_statement +import os, ConfigParser +from . import const VERBOSE = False FULL_CLEAN = False @@ -29,21 +31,24 @@ PORTAGE_DIR = '/usr/portage' DISTFILES_DIR = '/usr/portage/distfiles' # Read settings from slave.cfg which override the above -if os.path.exists('%s/slave.cfg' % const.CONFIG_PATH): - options = locals().copy() - cfg = ConfigParser.ConfigParser() - cfg.readfp(open('%s/slave.cfg' % const.CONFIG_PATH)) - for option, value in options.iteritems(): - if not isinstance(value, (str, int, bool)): - continue - if cfg.has_option('global', option.lower()): - if isinstance(value, str): - if not option.startswith('__'): - exec('%s = %s' % (option, cfg.get('global', option.lower()))) - elif isinstance(value, bool): - exec('%s = %s' % (option, cfg.getboolean('global', option.lower()))) - elif isinstance(value, int): - exec('%s = %s' % (option, cfg.getint('global', option.lower()))) +try: + with open('%s/slave.cfg' % const.CONFIG_PATH) as slave_cfg: + options = locals().copy() + cfg = ConfigParser.ConfigParser() + cfg.readfp(slave_cfg) + for option, value in options.iteritems(): + if not isinstance(value, (str, int, bool)): + continue + if cfg.has_option('global', option.lower()): + if isinstance(value, str): + if not option.startswith('__'): + exec('%s = %s' % (option, cfg.get('global', option.lower()))) + elif isinstance(value, bool): + exec('%s = %s' % (option, cfg.getboolean('global', option.lower()))) + elif isinstance(value, int): + exec('%s = %s' % (option, cfg.getint('global', option.lower()))) +except IOError, OSError: + print "!!! Unable to read %s/slave.cfg, ignoring..." % const.CONFIG_PATH if not AUTOTUA_MASTER: print "!!! WARNING: You did not edit the autotua_master variable in slave.cfg (or AUTOTUA_MASTER in config.py)" diff --git a/slave/autotua/crypt/__init__.py b/slave/autotua/crypt/__init__.py index 29e37f3..0ee5073 100644 --- a/slave/autotua/crypt/__init__.py +++ b/slave/autotua/crypt/__init__.py @@ -1,5 +1,5 @@ # vim: set sw=4 sts=4 et : -# Copyright: 2008 Gentoo Foundation +# Copyright: 2008-2009 Gentoo Foundation # Author(s): Nirbheek Chauhan <nirbheek.chauhan@gmail.com> # License: GPL-3 # @@ -22,8 +22,12 @@ class Crypto(object): self.gpgcmd += '--homedir="%s" ' % self.gpghome def _validate_gpghome(self): - if not os.path.exists(self.gpghome+'/secring.gpg'): - raise Exception('"%s": Invalid GPG homedir' % self.gpghome) + try: + gpghome = open(self.gpghome+'/secring.gpg') + except IOError, OSError: + raise Exception('"%s": Unable to use GPG homedir' % self.gpghome) + finally: + gpghome.close() def _get_fp_from_keyid(self, keyid): gpg_args = '--with-colons --fingerprint --list-keys "%s"' % keyid |