summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-05 00:50:36 -0500
committerYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-05 00:50:36 -0500
commit30fe0400ab1bb17b892235ae96c5e704204d4fc2 (patch)
tree4400803d6ad08ed759e57061c1e29425d3b1cf0f
parent84289bb07a5485119fd5ec758d8b410e835e173f (diff)
downloadfedora-devshell-30fe0400ab1bb17b892235ae96c5e704204d4fc2.tar.gz
fedora-devshell-30fe0400ab1bb17b892235ae96c5e704204d4fc2.tar.xz
fedora-devshell-30fe0400ab1bb17b892235ae96c5e704204d4fc2.zip
Gave darcs the ability to do operations in branches and tags.
Right now it just deletes the working space when done, could use something better
-rw-r--r--modules/cabal.py5
-rw-r--r--modules/darcs.py88
2 files changed, 85 insertions, 8 deletions
diff --git a/modules/cabal.py b/modules/cabal.py
index 89b8aad..cc82db7 100644
--- a/modules/cabal.py
+++ b/modules/cabal.py
@@ -103,6 +103,11 @@ class Cabal(Module):
p = Popen(args, stdout=cabal_out, stderr=cabal_out)
log.info('Building %s, please wait...' % self.name)
p.wait()
+
+ def install_tag(self, tag):
+ with pwd(self.package.dir):
+ with self.package.tag(tag):
+ self.install()
def install_source(self, target='home', orig=''):
self.configure(target, orig)
diff --git a/modules/darcs.py b/modules/darcs.py
index 4c73e02..2a967b3 100644
--- a/modules/darcs.py
+++ b/modules/darcs.py
@@ -18,11 +18,18 @@
from __future__ import with_statement
-from subprocess import Popen
+import re
-from base.util import pwd, log
+from contextlib import contextmanager
+from os import getcwd
+from subprocess import Popen, PIPE
+
+from base.util import pwd, log, rm, log_file
from modules.revisioncontrol import RevisionControl
+hash_re = re.compile(r'hash=\'(\w|-|.*?)\'', re.MULTILINE)
+date_re = re.compile(r'date=\'(\d*?)\'', re.MULTILINE)
+
class Darcs(RevisionControl):
_type = 'darcs'
def load_dir(self, dir):
@@ -32,14 +39,79 @@ class Darcs(RevisionControl):
def source_dir(self, *args):
return self.cfg['source']
- def checkout(self, tgt, url, *args):
+ @contextmanager
+ def src_dir(self, *args):
+ with src(*args):
+ with pwd(self.cfg['source']):
+ yield
+
+ @contextmanager
+ def src(self, *args):
+ if args:
+ old_src = self.cfg['source']
+ self.set_cur_to(*args)
+ yield
+ if args:
+ rm(self.cfg['source'])
+ self.cfg['source'] = old_src
+ self.set_current_head()
+
+
+ def get(self, src, tgt, *args):
with pwd(self.dir):
self.cfg['source'] = tgt
- self.cfg['vc_url'] = url
- with file('darcs.log', 'a') as darcs_out:
- p = Popen(['darcs', 'get'] + list(args) + [url, tgt],
+ with log_file('darcs.log') as darcs_out:
+ p = Popen(['darcs', 'get'] + list(args) + [src, tgt],
stdout = darcs_out, stderr = darcs_out)
- log.info('darcs get %s %s, please wait....' % (url, tgt))
+ log.info('darcs get %s %s, please wait....' % (src, tgt))
p.wait()
+ self.set_current_head()
+
+ def checkout(self, tgt, url, *args):
+ self.cfg['vc_url'] = url
+ self.get(url, tgt, *args)
+
+ def set_current_head(self):
+ log.debug(getcwd())
+ with pwd(self.cfg['source']):
+ p = Popen(['darcs', 'changes', '--xml-output', '--last=1'],
+ stdout = PIPE, stderr = PIPE)
+ change = p.communicate()[0]
+ hash = hash_re.search(change).groups()[0]
+ date = date_re.search(change).groups()[0]
+ self.cfg['head'] = (hash, date)
+
+ def set_cur_to(self, *args):
+ cur_src_dir = self.cfg['source']
+ new_src_dir = cur_src_dir + '_tmp'
+ self.get(cur_src_dir, new_src_dir, *args)
+
+ def set_cur_to_patch(self, hash):
+ self.set_cur_to('--to-match', 'hash ' + hash)
+
+ def set_cur_to_tag(self, tag):
+ self.set_cur_to('--tag', tag)
+
+ @property
+ def date(self):
+ return self.cfg['head'][1]
+
+ @property
+ def hash(self):
+ return self.cfg['head'][0]
+
+ def set_cur_to_patch(self, hash):
+ self.set_cur_to('--to-match', 'hash ' + hash)
+
+ def set_cur_to_tag(self, tag):
+ self.set_cur_to('--tag', tag)
+
+ @contextmanager
+ def patch(self, hash):
+ with self.src('--to-match', 'hash ' + hash):
+ yield
- pass
+ @contextmanager
+ def tag(self, tag):
+ with self.src('--tag', tag):
+ yield