# Fedora Developer Shell # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # Authors: Yaakov M. Nemoy # from __future__ import with_statement import re from contextlib import contextmanager from os import getcwd from os.path import join from subprocess import Popen, PIPE from base.util import pwd, log, rm, log_file, copy, move 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): super(RevisionControl, self).load_dir(dir) @property def vc_url(self): return self.cfg['vc_url'] def source_dir(self, *args): return self.cfg['source'] @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 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): 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 @contextmanager def tag(self, tag): with self.src('--tag', tag): yield @property def sourceball(self): with pwd(self.source_dir()): name = self.pkg_name ver = self.ver() date = self.date full_name = '%s-%s.%sdarcs' % (name, ver, date) with log_file('darcs.log') as darcs_out: p = Popen(['darcs', 'dist', '-d', full_name, '--repodir', self.source_dir()], stdout=darcs_out, stderr=darcs_out) log.info('generating tarball %s.tar.gz, please wait...' % full_name) p.wait() sourceball = full_name + 'tar.gz' mv(join(self.source_dir(), sourceball), sourceball) return sourceball __all__ = ['Darcs']