Mercurial > hg > hq
changeset 7:2e77fc6a36e8
add a status command; so much shit to clean
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 11 Mar 2013 14:51:56 -0700 |
parents | 321721b581f1 |
children | d1aa54a8fd89 |
files | hq/main.py |
diffstat | 1 files changed, 33 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/hq/main.py Wed May 26 18:56:34 2010 -0700 +++ b/hq/main.py Mon Mar 11 14:51:56 2013 -0700 @@ -1,29 +1,25 @@ #!/usr/bin/env python + """ mercurial queue extension front-end policy manager """ +# TODO: migrate to http://k0s.org/hg/CommandParser/ + import os import subprocess import sys from command import CommandParser -def call(command, *args, **kw): - code = subprocess.call(command, *args, **kw) - if code: - if isinstance(command, basestring): - cmdstr = command - else: - cmdstr = ' '.join(command) - raise SystemExit("Command `%s` exited with code %d" % (cmdstr, code)) +call = subprocess.check_output class HQ(object): """ mercurial queue extension front-end policy manager """ - def __init__(self, queue_host=None, network=True): + def __init__(self, queue_host=None, network=True, root=None, binary='hg'): """initialize global options""" # TODO: look at hgrc file # for [defaults] repository_host @@ -34,6 +30,14 @@ self.queue_host = queue_host + if root is None: + root = call(['hg', 'root']).strip() + self.root = root + + self.binary = binary + + ### subcommands + def clone(self, repo, patch=None, queue=None): """ clone the repository and begin a patch queue @@ -50,7 +54,7 @@ else: # (optionally) setup a new repo pass # TODO - + if patch: # create a new patch call(['hg', 'qnew', patch]) @@ -96,6 +100,25 @@ stdout, stderr = process.communicate() return stdout + def status(self): + """ + display status + """ + + # TODO: once this is on CommandParser, there should be a utility in + # command parser to allow aliases; e.g. if you do ``st = status`` at + # the class scope, you can run through the methods and only display + # one as canon but allow aliases as such. + # Alternatively, you can allow any short non-ambiguous abbreviation. + + return '\n'.join([self._call(i).strip() for i in ('status', 'qseries')]) + + ### internals + + def _call(self, *args): + command = [self.binary] + list(args) + return call(command, cwd=self.root) + def _patch_repo(self): """the location of the patch repository""" root = subprocess.Popen(['hg', 'root'], stdout=subprocess.PIPE).communicate()[0]