# HG changeset patch # User Jeff Hammel # Date 1363038716 25200 # Node ID 2e77fc6a36e8f43186eb20a05b6a957428cc626d # Parent 321721b581f1e549436b3e77c1420c80fd3137d7 add a status command; so much shit to clean diff -r 321721b581f1 -r 2e77fc6a36e8 hq/main.py --- 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]