summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Dolbec <brian.dolbec@gmail.com>2011-02-25 18:46:44 -0800
committerBrian Dolbec <brian.dolbec@gmail.com>2011-03-26 19:39:13 -0700
commit0a82306f384ab032a30cce35513a7a4a7c194991 (patch)
treea53a90cb85c0295359ae386d6dd3246a404ac3c9
parentd9de33168cfe46be2e269d04ec52afe003f7ba6d (diff)
downloadlayman-0a82306f384ab032a30cce35513a7a4a7c194991.tar.gz
layman-0a82306f384ab032a30cce35513a7a4a7c194991.tar.bz2
layman-0a82306f384ab032a30cce35513a7a4a7c194991.zip
replace more exception raising with error reporting and proper return values.
some long line cleanup.
-rw-r--r--layman/overlays/bzr.py5
-rw-r--r--layman/overlays/cvs.py5
-rw-r--r--layman/overlays/darcs.py8
-rw-r--r--layman/overlays/g_common.py15
-rw-r--r--layman/overlays/git.py8
-rw-r--r--layman/overlays/mercurial.py5
-rw-r--r--layman/overlays/rsync.py13
-rw-r--r--layman/overlays/source.py23
-rw-r--r--layman/overlays/svn.py4
-rw-r--r--layman/overlays/tar.py7
10 files changed, 52 insertions, 41 deletions
diff --git a/layman/overlays/bzr.py b/layman/overlays/bzr.py
index 1c2c702..957f9e7 100644
--- a/layman/overlays/bzr.py
+++ b/layman/overlays/bzr.py
@@ -84,5 +84,6 @@ class BzrOverlay(OverlaySource):
def supported(self):
'''Overlay type supported?'''
- return require_supported([(self.command(), 'bzr',
- 'dev-vcs/bzr'),])
+ return require_supported(
+ [(self.command(), 'bzr', 'dev-vcs/bzr'),],
+ self.output.error)
diff --git a/layman/overlays/cvs.py b/layman/overlays/cvs.py
index 2e76aa5..69e0dd1 100644
--- a/layman/overlays/cvs.py
+++ b/layman/overlays/cvs.py
@@ -109,5 +109,6 @@ class CvsOverlay(OverlaySource):
def supported(self):
'''Overlay type supported?'''
- return require_supported([(self.command(), 'cvs',
- 'dev-vcs/cvs'),])
+ return require_supported(
+ [(self.command(), 'cvs', 'dev-vcs/cvs'),],
+ self.output.error)
diff --git a/layman/overlays/darcs.py b/layman/overlays/darcs.py
index 566d6ba..14a415b 100644
--- a/layman/overlays/darcs.py
+++ b/layman/overlays/darcs.py
@@ -42,7 +42,8 @@ class DarcsOverlay(OverlaySource):
def __init__(self, parent, config, _location, ignore = 0, quiet = False):
- super(DarcsOverlay, self).__init__(parent, config, _location, ignore, quiet)
+ super(DarcsOverlay, self).__init__(parent, config,
+ _location, ignore, quiet)
def add(self, base, quiet = False):
'''Add overlay.'''
@@ -84,5 +85,6 @@ class DarcsOverlay(OverlaySource):
def supported(self):
'''Overlay type supported?'''
- return require_supported([(self.command(), 'darcs',
- 'dev-vcs/darcs'),])
+ return require_supported(
+ [(self.command(), 'darcs', 'dev-vcs/darcs'),],
+ self.output.error)
diff --git a/layman/overlays/g_common.py b/layman/overlays/g_common.py
index 5be191d..fae11df 100644
--- a/layman/overlays/g_common.py
+++ b/layman/overlays/g_common.py
@@ -39,7 +39,8 @@ class GCommonOverlay(OverlaySource):
type_key = 'g-common'
def __init__(self, parent, config, _location, ignore = 0, quiet = False):
- super(GCommonOverlay, self).__init__(parent, config, _location, ignore, quiet)
+ super(GCommonOverlay, self).__init__(parent, config,
+ _location, ignore, quiet)
#split source into driver and remote uri.
self.driver=self.src[:self.src.find(' ')]
self.remote_uri=self.src[self.src.find(' ')+1:]
@@ -73,9 +74,9 @@ class GCommonOverlay(OverlaySource):
'''Overlay type supported?'''
return require_supported(
- [(self.command(),
- 'g-common',
- 'app-portage/g-common'),
- ('/usr/share/g-common/drivers/'+self.driver+'.cfg',
- 'g-common for '+self.driver,
- 'app-portage/g-'+self.driver),])
+ [(self.command(),
+ 'g-common',
+ 'app-portage/g-common'),
+ ('/usr/share/g-common/drivers/'+self.driver+'.cfg',
+ 'g-common for '+self.driver,
+ 'app-portage/g-'+self.driver),], self.output.error)
diff --git a/layman/overlays/git.py b/layman/overlays/git.py
index 0c0404f..d65a5d3 100644
--- a/layman/overlays/git.py
+++ b/layman/overlays/git.py
@@ -46,7 +46,8 @@ class GitOverlay(OverlaySource):
def add(self, base, quiet = False):
'''Add overlay.'''
- self.supported()
+ if not self.supported():
+ return False
def fix_git_source(source):
# http:// should get trailing slash, other protocols shouldn't
@@ -89,5 +90,6 @@ class GitOverlay(OverlaySource):
def supported(self):
'''Overlay type supported?'''
- return require_supported([(self.command(), 'git',
- 'dev-vcs/git'),])
+ return require_supported(
+ [(self.command(), 'git', 'dev-vcs/git'),],
+ self.output.error)
diff --git a/layman/overlays/mercurial.py b/layman/overlays/mercurial.py
index 1d0cb92..748588b 100644
--- a/layman/overlays/mercurial.py
+++ b/layman/overlays/mercurial.py
@@ -85,5 +85,6 @@ class MercurialOverlay(OverlaySource):
def supported(self):
'''Overlay type supported?'''
- return require_supported([(self.command(), 'mercurial',
- 'dev-vcs/mercurial'),])
+ return require_supported(
+ [(self.command(), 'mercurial', 'dev-vcs/mercurial'),],
+ self.output.error)
diff --git a/layman/overlays/rsync.py b/layman/overlays/rsync.py
index 1d6e831..76b289e 100644
--- a/layman/overlays/rsync.py
+++ b/layman/overlays/rsync.py
@@ -42,7 +42,8 @@ class RsyncOverlay(OverlaySource):
def __init__(self, parent, config, _location, ignore = 0, quiet = False):
- super(RsyncOverlay, self).__init__(parent, config, _location, ignore, quiet)
+ super(RsyncOverlay, self).__init__(parent, config,
+ _location, ignore, quiet)
def add(self, base, quiet = False):
'''Add overlay.'''
@@ -59,8 +60,9 @@ class RsyncOverlay(OverlaySource):
self.supported()
# rsync OPTIONS [-q] SOURCE TARGET
- args = ['-rlptDvz', '--progress', '--delete', '--delete-after', '--timeout=180',
- '--exclude=distfiles/*', '--exclude=local/*', '--exclude=packages/*']
+ args = ['-rlptDvz', '--progress', '--delete', '--delete-after',
+ '--timeout=180', '--exclude=distfiles/*', '--exclude=local/*',
+ '--exclude=packages/*']
cfg_opts = self.config["rsync_syncopts"]
target = path([base, self.parent.name])
@@ -79,5 +81,6 @@ class RsyncOverlay(OverlaySource):
def supported(self):
'''Overlay type supported?'''
- return require_supported([(self.command(), 'rsync',
- 'net-misc/rsync'),])
+ return require_supported(
+ [(self.command(), 'rsync', 'net-misc/rsync'),],
+ self.output.error)
diff --git a/layman/overlays/source.py b/layman/overlays/source.py
index be7b639..b88131f 100644
--- a/layman/overlays/source.py
+++ b/layman/overlays/source.py
@@ -21,10 +21,11 @@ import subprocess
from layman.utils import path
-def _resolve_command(command):
+def _resolve_command(command, error_output):
if os.path.isabs(command):
if not os.path.exists(command):
- raise Exception('Program "%s" not found' % command)
+ error_output('Program "%s" not found' % command)
+ return ('File', None)
return ('File', command)
else:
kind = 'Command'
@@ -33,18 +34,19 @@ def _resolve_command(command):
f = os.path.join(d, command)
if os.path.exists(f):
return ('Command', f)
- raise Exception('Cound not resolve command ' +\
+ error_output('Cound not resolve command ' +\
'"%s" based on PATH "%s"' % (command, env_path))
+ return ('Command', None)
-def require_supported(binaries):
+def require_supported(binaries, error_output):
for command, mtype, package in binaries:
- found = False
- kind, path = _resolve_command(command)
+ kind, path = _resolve_command(command, error_output)
if not path:
- raise Exception(kind + ' ' + command + ' seems to be missing!'
+ error_output(kind + ' ' + command + ' seems to be missing!'
' Overlay type "' + mtype + '" not support'
'ed. Did you emerge ' + package + '?')
+ return False
return True
@@ -104,12 +106,7 @@ class OverlaySource(object):
def is_supported(self):
'''Is the overlay type supported?'''
-
- try:
- self.supported()
- return True
- except:
- return False
+ return self.supported()
def command(self):
return self.config['%s_command' % self.__class__.type_key]
diff --git a/layman/overlays/svn.py b/layman/overlays/svn.py
index 147a641..e0eb632 100644
--- a/layman/overlays/svn.py
+++ b/layman/overlays/svn.py
@@ -99,5 +99,5 @@ class SvnOverlay(OverlaySource):
'''Overlay type supported?'''
return require_supported(
- [(self.command(), 'svn','dev-vcs/subversion'),]
- )
+ [(self.command(), 'svn','dev-vcs/subversion'),],
+ self.output.error)
diff --git a/layman/overlays/tar.py b/layman/overlays/tar.py
index 5f1f606..9d59b71 100644
--- a/layman/overlays/tar.py
+++ b/layman/overlays/tar.py
@@ -75,7 +75,8 @@ class TarOverlay(OverlaySource):
def __init__(self, parent, config, _location, ignore = 0, quiet = False):
- super(TarOverlay, self).__init__(parent, config, _location, ignore, quiet)
+ super(TarOverlay, self).__init__(parent,
+ config, _location, ignore, quiet)
self.output = config['output']
@@ -199,7 +200,9 @@ class TarOverlay(OverlaySource):
def supported(self):
'''Overlay type supported?'''
- return require_supported([(self.command(), 'tar', 'app-arch/tar'), ])
+ return require_supported(
+ [(self.command(), 'tar', 'app-arch/tar'), ],
+ self.output.error)
if __name__ == '__main__':
import doctest