summaryrefslogtreecommitdiffstats
path: root/modules/darcs.py
diff options
context:
space:
mode:
authorYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-15 18:11:24 -0500
committerYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-15 18:11:24 -0500
commit7ff1ef7ad4fe00770db6fde54bb1c3c8066bc4bf (patch)
tree6ac26f5ef014883019dabcc7b470d5aa23e6d69c /modules/darcs.py
parent401c14d76893579ce2af6e7018ec4140a3541cf1 (diff)
downloadfedora-devshell-7ff1ef7ad4fe00770db6fde54bb1c3c8066bc4bf.tar.gz
fedora-devshell-7ff1ef7ad4fe00770db6fde54bb1c3c8066bc4bf.tar.xz
fedora-devshell-7ff1ef7ad4fe00770db6fde54bb1c3c8066bc4bf.zip
Refactors things around using source directories as separate directories
Diffstat (limited to 'modules/darcs.py')
-rw-r--r--modules/darcs.py113
1 files changed, 71 insertions, 42 deletions
diff --git a/modules/darcs.py b/modules/darcs.py
index 8bee4a4..943ebf0 100644
--- a/modules/darcs.py
+++ b/modules/darcs.py
@@ -18,11 +18,12 @@
from __future__ import with_statement
+import os
import re
from contextlib import contextmanager
from os import getcwd
-from os.path import join
+from os.path import join, basename, exists
from subprocess import Popen, PIPE
from base.util import pwd, log, rm, log_file, copy, move
@@ -35,6 +36,49 @@ class Darcs(RevisionControl):
'''manages single source packages where the primary source is darcs
'''
_type = 'darcs'
+ def __init__(self, name=None, url=None, *args):
+ if url:
+ #split chokes on URLs that end in a /
+ url = url[:-1] if url.endswith('/') else url
+ tgt = basename(url)
+ if not name:
+ name = tgt
+ self.get(url, tgt, *args)
+ super(Darcs, self).__init__(name)
+ if url:
+ self.cfg['vc_url'] = url
+ self.cfg['hackage_name'] = tgt
+ self.cfg['source'] = '.'
+ with pwd(self.branch_dir):
+ self.get(self.dir, 'orig')
+
+
+ def get(self, src, tgt, *args):
+ '''sets up a branch given arguments, taken from a source with a target
+
+ the idioms of branching in different VCSes vary, and a common
+ api for this in devshell has not yet been realized
+
+ currently, this creates a new temporary local branch in darcs
+ and sets the source to it
+ '''
+ with log_file('darcs.log') as darcs_out:
+ # NB: args is a tuple, must be converted
+ p = Popen(['darcs', 'get'] + list(args) + [src, tgt],
+ stdout = darcs_out, stderr = darcs_out)
+ log.info('darcs get %s %s, please wait....' % (src, tgt))
+ p.communicate()
+
+# def checkout(self, tgt, url, *args):
+# '''checks out source from an upstream url
+
+# the difference between this and get is that it reflects an initial pull
+# idiom found in other VCSes. It also handles setting vc_url and the
+# canonical name, based on tgt
+# '''
+# self.cfg['vc_url'] = url
+# self.get(url, tgt, *args)
+
@property
def vc_url(self):
'''the url where the source was fetched from originally
@@ -46,7 +90,7 @@ class Darcs(RevisionControl):
@property
def hackage_name(self):
'''assuming this package is a haskell package, what is the canonical name
-
+
this name may be changed in the future
'''
return self.cfg['hackage_name']
@@ -54,7 +98,7 @@ class Darcs(RevisionControl):
def source(self, *args):
'''the name of the directory where the source is being kept currently
- hackage_name is the canonical name of the package, this is
+ hackage_name is the canonical name of the package, this is
just for handling branching and other nasty devilish tricks
'''
return self.cfg['source']
@@ -80,45 +124,16 @@ class Darcs(RevisionControl):
if args:
rm(self.cfg['source'])
self.cfg['source'] = old_src
- self.set_current_head()
+ self.set_current_src()
- def get(self, src, tgt, *args):
- '''sets up a branch given arguments, taken from a source with a target
-
- the idioms of branching in different VCSes vary, and a common
- api for this in devshell has not yet been realized
-
- currently, this creates a new temporary local branch in darcs
- and sets the source to it
- '''
- with pwd(self.dir):
- self.cfg['source'] = 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....' % (src, tgt))
- p.wait()
- self.set_current_head()
-
- def checkout(self, tgt, url, *args):
- '''checks out source from an upstream url
-
- the difference between this and get is that it reflects an initial pull
- idiom found in other VCSes. It also handles setting vc_url and the
- canonical name, based on tgt
- '''
- self.cfg['vc_url'] = url
- self.cfg['hackage_name'] = split(tgt)[1]
- self.get(url, tgt, *args)
-
- def set_current_head(self):
+ def set_current_src(self):
'''sets the current internal state to reflect the current head
chances are, the user should rarely mess with this.
- this may change, because rather than using .patch files for rpm
- handling, we may ask the user to commit all the changes to darcs,
+ this may change, because rather than using .patch files for rpm
+ handling, we may ask the user to commit all the changes to darcs,
and then have devshell generate .patch files automatically instead
'''
log.debug(getcwd())
@@ -130,16 +145,30 @@ class Darcs(RevisionControl):
date = date_re.search(change).groups()[0]
self.cfg['head'] = (hash, date)
- def set_cur_to(self, *args):
+ def set_cur_to(self, *args, branch_name=''):
'''passes arbitrary args to darcs get and makes a branch out of it
-
+
this is not really optimal, because it only does things temporary,
- we need to look at as systematic way to handle branching.
+ we need to look at as systematic way to handle branching.
looking at a potential git and a potential cvs module may help
'''
- cur_src_dir = self.cfg['source']
- new_src_dir = cur_src_dir + '_tmp'
- self.get(cur_src_dir, new_src_dir, *args)
+ if len(args) == 1 and args[0] == 'head':
+ self.cfg['source'] = '.'
+ if len(args) == 2 and args[0] == 'branch':
+ self.cfg['source'] = join(self.branch, args[1])
+ else:
+ index = hash(args)
+ index_dir = join(self.branch, index)
+ with pwd(self.dir):
+ if not exists(index_dir):
+ self.get(self.source(), index_dir, *args)
+ self.cfg['source'] = index_dir
+ if branch_name:
+ with pwd(self.branch_dir):
+ self.get(index, branch_name)
+# 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):
'''sets the current branch to fork off a particular hash'''