summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec2011-02-18 05:19:08 (GMT)
committerBrian Dolbec2011-02-18 05:19:08 (GMT)
commit3eaca0340384122c5d83e0aa2d0a8b6dc1165487 (patch)
tree18d97383394e545138746eb5fbcb9d05b61ccc3b
parent4872509aab4693638c957fcd8e9d38af06357769 (diff)
Add per repo type postsync options.
Some minor long lines cleanup.
-rw-r--r--etc/layman.cfg23
-rw-r--r--layman/overlays/bzr.py14
-rw-r--r--layman/overlays/cvs.py11
-rw-r--r--layman/overlays/darcs.py14
-rw-r--r--layman/overlays/g_common.py20
-rw-r--r--layman/overlays/git.py12
-rw-r--r--layman/overlays/mercurial.py15
-rw-r--r--layman/overlays/rsync.py7
-rw-r--r--layman/overlays/source.py28
-rw-r--r--layman/overlays/svn.py14
-rw-r--r--layman/overlays/tar.py27
11 files changed, 141 insertions, 44 deletions
diff --git a/etc/layman.cfg b/etc/layman.cfg
index f345fe1..741da11 100644
--- a/etc/layman.cfg
+++ b/etc/layman.cfg
@@ -124,3 +124,26 @@ nocheck : yes
#g-common_generateopts :
#g-common_syncopts :
+
+#-----------------------------------------------------------
+# Per VCS Post Sync/Add hooks
+#
+# The listed commands will be run after every add/sync operation.
+# All on one line If the repo path is needed, use a %cwd= in
+# where you want the path substituted in. It will be detected
+# and replaced with the correct path.
+#
+# eg: git_postsync : git-set-file-times
+# eg: git_postsync : git-set-file-times %cwd=
+# eg: git_postsync : git-set-file-times path=%cwd=
+#
+#bzr_postsync :
+#cvs_postsync :
+#darcs_postsync :
+#git_postsync :
+#mercurial_postsync :
+#rsync_postsync :
+#svn_postsync :
+#tar_postsync :
+#g-common_postsync :
+
diff --git a/layman/overlays/bzr.py b/layman/overlays/bzr.py
index a236210..6f1b560 100644
--- a/layman/overlays/bzr.py
+++ b/layman/overlays/bzr.py
@@ -51,14 +51,17 @@ class BzrOverlay(OverlaySource):
self.supported()
cfg_opts = self.config["bzr_addopts"]
+ target = path([base, self.parent.name])
# bzr get SOURCE TARGET
if cfg_opts:
args = ['get', cfg_opts,
- self.src + '/', path([base, self.parent.name])]
+ self.src + '/', target]
else:
- args = ['get', self.src + '/', path([base, self.parent.name])]
- return self.run_command(*args)
+ args = ['get', self.src + '/', target]
+ return self.postsync(
+ self.run_command(self.command(), *args, cmd=self.type),
+ cwd=target)
def sync(self, base, quiet = False):
'''Sync overlay.'''
@@ -66,13 +69,16 @@ class BzrOverlay(OverlaySource):
self.supported()
cfg_opts = self.config["bzr_syncopts"]
+ target = path([base, self.parent.name])
# bzr pull --overwrite SOURCE
if cfg_opts:
args = ['pull', cfg_opts, '--overwrite', self.src]
else:
args = ['pull', '--overwrite', self.src]
- return self.run_command(*args, cwd=path([base, self.parent.name]))
+ return self.postsync(
+ self.run_command(self.command(), *args, cwd=target, cmd=self.type),
+ cwd=target)
def supported(self):
'''Overlay type supported?'''
diff --git a/layman/overlays/cvs.py b/layman/overlays/cvs.py
index e4ee5eb..7d3f28f 100644
--- a/layman/overlays/cvs.py
+++ b/layman/overlays/cvs.py
@@ -75,6 +75,7 @@ class CvsOverlay(OverlaySource):
self.supported()
cfg_opts = self.config["cvs_addopts"]
+ target = path([base, self.parent.name])
# cvs [-q] co -d SOURCE SCOPE
args = []
@@ -87,7 +88,10 @@ class CvsOverlay(OverlaySource):
args.append(self.parent.name)
args.append(self.subpath)
- return self.run_command(*args, cwd=base, env=dict(CVSROOT=self.src))
+ return self.postsync(
+ self.run_command(self.command(), *args, cwd=base,
+ env=dict(CVSROOT=self.src), cmd=self.type),
+ cwd=target)
def sync(self, base, quiet = False):
'''Sync overlay.'''
@@ -95,6 +99,7 @@ class CvsOverlay(OverlaySource):
self.supported()
cfg_opts = self.config["cvs_syncopts"]
+ target = path([base, self.parent.name])
# cvs [-q] update -d
args = []
@@ -104,7 +109,9 @@ class CvsOverlay(OverlaySource):
args.append('-d')
if cfg_opts:
args.append(cfg_opts)
- return self.run_command(*args, cwd=path([base, self.parent.name]))
+ return self.postsync(
+ self.run_command(self.command(), *args, cwd=target, cmd=self.type),
+ cwd=target)
def supported(self):
'''Overlay type supported?'''
diff --git a/layman/overlays/darcs.py b/layman/overlays/darcs.py
index cfaba51..d393be7 100644
--- a/layman/overlays/darcs.py
+++ b/layman/overlays/darcs.py
@@ -50,16 +50,19 @@ class DarcsOverlay(OverlaySource):
self.supported()
cfg_opts = self.config["darcs_addopts"]
+ target = path([base, self.parent.name])
# darcs get --partial SOURCE TARGET
if cfg_opts:
args = ['get', '--partial', cfg_opts,
- self.src + '/', path([base, self.parent.name])]
+ self.src + '/', target]
else:
args = ['get', '--partial',
- self.src + '/', path([base, self.parent.name])]
+ self.src + '/', target]
- return self.run_command(*args)
+ return self.postsync(
+ self.run_command(self.command(), *args, cmd=self.type),
+ cwd=target)
def sync(self, base, quiet = False):
'''Sync overlay.'''
@@ -67,13 +70,16 @@ class DarcsOverlay(OverlaySource):
self.supported()
cfg_opts = self.config["darcs_addopts"]
+ target = path([base, self.parent.name])
# darcs pull --all SOURCE
if cfg_opts:
args = ['pull', '--all', cfg_opts, self.src]
else:
args = ['pull', '--all', self.src]
- return self.run_command(*args, cwd=path([base, self.parent.name]))
+ return self.postsync(
+ self.run_command(self.command(), *args, cwd=target, cmd=self.type),
+ cwd=target)
def supported(self):
'''Overlay type supported?'''
diff --git a/layman/overlays/g_common.py b/layman/overlays/g_common.py
index 80d0742..5367c69 100644
--- a/layman/overlays/g_common.py
+++ b/layman/overlays/g_common.py
@@ -40,7 +40,7 @@ class GCommonOverlay(OverlaySource):
def __init__(self, parent, xml, config, _location, ignore = 0, quiet = False):
super(GCommonOverlay, self).__init__(parent, xml, config, _location, ignore, quiet)
- #split source into driver and remote uri.
+ #split source into driver and remote uri.
self.driver=self.src[:self.src.find(' ')]
self.remote_uri=self.src[self.src.find(' ')+1:]
@@ -48,20 +48,26 @@ class GCommonOverlay(OverlaySource):
'''Add overlay.'''
self.supported()
+ target = path([base, self.parent.name])
+
+ os.makedirs(target)
- os.makedirs(os.path.join(base,self.parent.name))
return self.sync(base, quiet)
def sync(self, base, quiet = False):
'''Sync overlay.'''
self.supported()
+ target = path([base, self.parent.name])
- args = [os.path.join(base,self.parent.name), 'sync', self.driver, self.remote_uri]
- returncode=self.run_command(*args,cwd=path([base,self.parent.name]))
- if returncode: return returncode
- args = [os.path.join(base,self.parent.name), 'generate-tree']
- return self.run_command(*args,cwd=path([base,self.parent.name]))
+ args = [target, 'sync', self.driver, self.remote_uri]
+ returncode = self.run_command(self.command(), *args, cwd=target)
+ if returncode:
+ return returncode
+ args = [target, 'generate-tree']
+ return self.postsync(
+ self.run_command(self.command(), *args, cwd=target, cmd=self.type),
+ cwd=target)
def supported(self):
'''Overlay type supported?'''
diff --git a/layman/overlays/git.py b/layman/overlays/git.py
index 9517398..23103f6 100644
--- a/layman/overlays/git.py
+++ b/layman/overlays/git.py
@@ -55,6 +55,7 @@ class GitOverlay(OverlaySource):
return source
cfg_opts = self.config["git_addopts"]
+ target = path([base, self.parent.name])
# git clone [-q] SOURCE TARGET
args = ['clone']
@@ -63,8 +64,10 @@ class GitOverlay(OverlaySource):
if cfg_opts:
args.append(cfg_opts)
args.append(fix_git_source(self.src))
- args.append(path([base, self.parent.name]))
- return self.run_command(*args)
+ args.append(target)
+ return self.postsync(
+ self.run_command(self.command(), *args, cmd=self.type),
+ cwd=target)
def sync(self, base, quiet = False):
'''Sync overlay.'''
@@ -72,13 +75,16 @@ class GitOverlay(OverlaySource):
self.supported()
cfg_opts = self.config["git_syncopts"]
+ target = path([base, self.parent.name])
args = ['pull']
if quiet:
args.append('-q')
if cfg_opts:
args.append(cfg_opts)
- return self.run_command(*args, cwd=path([base, self.parent.name]))
+ return self.postsync(
+ self.run_command(self.command(), *args, cwd=target, cmd=self.type),
+ cwd=target)
def supported(self):
'''Overlay type supported?'''
diff --git a/layman/overlays/mercurial.py b/layman/overlays/mercurial.py
index 377ad4c..df4f789 100644
--- a/layman/overlays/mercurial.py
+++ b/layman/overlays/mercurial.py
@@ -50,15 +50,17 @@ class MercurialOverlay(OverlaySource):
self.supported()
cfg_opts = self.config["mercurial_addopts"]
+ target = path([base, self.parent.name])
# hg clone SOURCE TARGET
if cfg_opts:
- args = ['clone', cfg_opts,
- self.src + '/', path([base, self.parent.name])]
+ args = ['clone', cfg_opts, self.src + '/', target]
else:
- args = ['clone', self.src + '/', path([base, self.parent.name])]
+ args = ['clone', self.src + '/', target]
- return self.run_command(*args)
+ return self.postsync(
+ self.run_command(self.command(), *args, cmd=self.type),
+ cwd=target)
def sync(self, base, quiet = False):
'''Sync overlay.'''
@@ -66,6 +68,7 @@ class MercurialOverlay(OverlaySource):
self.supported()
cfg_opts = self.config["mercurial_syncopts"]
+ target = path([base, self.parent.name])
# hg pull -u SOURCE
if cfg_opts:
@@ -73,7 +76,9 @@ class MercurialOverlay(OverlaySource):
else:
args = ['pull', '-u', self.src]
- return self.run_command(*args, cwd=path([base, self.parent.name]))
+ return self.postsync(
+ self.run_command(self.command(), *args, cwd=target, cmd=self.type),
+ cwd=target)
def supported(self):
'''Overlay type supported?'''
diff --git a/layman/overlays/rsync.py b/layman/overlays/rsync.py
index d6f3281..84836dd 100644
--- a/layman/overlays/rsync.py
+++ b/layman/overlays/rsync.py
@@ -63,15 +63,18 @@ class RsyncOverlay(OverlaySource):
'--exclude=distfiles/*', '--exclude=local/*', '--exclude=packages/*']
cfg_opts = self.config["rsync_syncopts"]
+ target = path([base, self.parent.name])
if quiet:
args.append('-q')
if cfg_opts:
args.append(cfg_opts)
args.append(self.src + '/')
- args.append(path([base, self.parent.name]))
+ args.append(target)
- return self.run_command(*args)
+ return self.postsync(
+ self.run_command(self.command(), *args, cmd=self.type),
+ cwd=target)
def supported(self):
'''Overlay type supported?'''
diff --git a/layman/overlays/source.py b/layman/overlays/source.py
index e5cd880..b0bc9a3 100644
--- a/layman/overlays/source.py
+++ b/layman/overlays/source.py
@@ -111,8 +111,8 @@ class OverlaySource(object):
def command(self):
return self.config['%s_command' % self.__class__.type_key]
- def run_command(self, *args, **kwargs):
- file_to_run = _resolve_command(self.command())[1]
+ def run_command(self, command, *args, **kwargs):
+ file_to_run = _resolve_command(command)[1]
args = (file_to_run, ) + args
assert('pwd' not in kwargs) # Bug detector
@@ -132,7 +132,8 @@ class OverlaySource(object):
if cwd:
command_repr = '( cd %s && %s )' % (cwd, command_repr)
- self.output.info('Running... # %s' % command_repr, 2)
+ cmd = kwargs.get('cmd', '')
+ self.output.info('Running %s... # %s' % (cmd, command_repr), 2)
if self.quiet:
input_source = subprocess.PIPE
@@ -162,7 +163,28 @@ class OverlaySource(object):
if self.quiet:
output_target.close()
+ if result:
+ self.output.info('Failure result returned from %s' % cmd , 2)
+
return result
+ def postsync(self, failed_sync, **kwargs):
+ """Runs any repo specific postsync operations
+ """
+ # check if the add/sync operation succeeded
+ if failed_sync:
+ return failed_sync
+ # good to continue
+ postsync_opt = self.config['%s_postsync' % self.__class__.type_key]
+ if postsync_opt:
+ # repalce "%cwd=" while it's still a string'
+ _opt = postsync_opt.replace('%cwd=',
+ kwargs.get('cwd', '')).split()
+ command = _opt[0]
+ args = _opt[1:]
+ return self.run_command(command, *args,
+ cmd='%s_postsync' % self.__class__.type_key)
+ return failed_sync
+
def to_xml_hook(self, repo_elem):
pass
diff --git a/layman/overlays/svn.py b/layman/overlays/svn.py
index 69d7b05..c237ea4 100644
--- a/layman/overlays/svn.py
+++ b/layman/overlays/svn.py
@@ -53,6 +53,7 @@ class SvnOverlay(OverlaySource):
super(SvnOverlay, self).add(base)
cfg_opts = self.config["svn_addopts"]
+ target = path([base, self.parent.name])
args = ['co']
if quiet:
@@ -60,9 +61,11 @@ class SvnOverlay(OverlaySource):
if cfg_opts:
args.append(cfg_opts)
args.append(self.src + '/@')
- args.append(path([base, self.parent.name]))
+ args.append(target)
- return self.run_command(*args)
+ return self.postsync(
+ self.run_command(self.command(),*args, cmd=self.type),
+ cwd=target)
def sync(self, base, quiet = False):
'''Sync overlay.'''
@@ -78,6 +81,7 @@ class SvnOverlay(OverlaySource):
return path([base, repo_part])
cfg_opts = self.config["svn_syncopts"]
+ target = checkout_location()
# svn up [-q] TARGET
args = ['up']
@@ -85,9 +89,11 @@ class SvnOverlay(OverlaySource):
args.append('-q')
if cfg_opts:
args.append(cfg_opts)
- args.append(checkout_location())
+ args.append(target)
- return self.run_command(*args)
+ return self.postsync(
+ self.run_command(self.command(),*args, cmd=self.type),
+ cwd=target)
def supported(self):
'''Overlay type supported?'''
diff --git a/layman/overlays/tar.py b/layman/overlays/tar.py
index 4916b77..09ed979 100644
--- a/layman/overlays/tar.py
+++ b/layman/overlays/tar.py
@@ -130,7 +130,7 @@ class TarOverlay(OverlaySource):
# tar -v -x -f SOURCE -C TARGET
args = ['-v', '-x', '-f', pkg, '-C', dest_dir]
- result = self.run_command(*args)
+ result = self.run_command(self.command(), *args, cmd=self.type)
os.unlink(pkg)
return result
@@ -150,7 +150,8 @@ class TarOverlay(OverlaySource):
final_path = path([base, self.parent.name])
temp_path = tempfile.mkdtemp(dir=base)
try:
- result = self._extract(base=base, tar_url=self.src, dest_dir=temp_path)
+ result = self._extract(base=base, tar_url=self.src,
+ dest_dir=temp_path)
except Exception, error:
try_to_wipe(temp_path)
raise error
@@ -169,8 +170,8 @@ class TarOverlay(OverlaySource):
os.rename(source, final_path)
except Exception, error:
raise Exception('Failed to rename tar subdirectory ' +
- source + ' to ' + final_path + '\nError was:'
- + str(error))
+ source + ' to ' + final_path +
+ '\nError was:' + str(error))
os.chmod(final_path, 0755)
else:
raise Exception('Given subpath "' + source + '" does not exist '
@@ -184,18 +185,24 @@ class TarOverlay(OverlaySource):
self.supported()
- final_path = path([base, self.parent.name])
+ target = path([base, self.parent.name])
- if os.path.exists(final_path):
- raise Exception('Directory ' + final_path + ' already exists. Will not ov'
- 'erwrite its contents!')
+ if os.path.exists(target):
+ raise Exception('Directory ' + target + ' already exists.' +\
+ ' Will not overwrite its contents!')
- return self._add_unchecked(base, quiet)
+ return self.postsync(
+ self._add_unchecked(base, quiet),
+ cwd=target)
def sync(self, base, quiet = False):
'''Sync overlay.'''
self.supported()
- self._add_unchecked(base, quiet)
+ target = path([base, self.parent.name])
+
+ return self.postsync(
+ self._add_unchecked(base, quiet),
+ cwd=target)
def supported(self):
'''Overlay type supported?'''