From ba31b657c49649ee0b00663a32e907bb482270ac Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 6 Dec 2009 17:20:39 -0500 Subject: be --dir DIR COMMAND now roots the bugdir in DIR without changing directories. Previously, for the directory structure A |-- X `-- Y You could do something like A$ be --dir X diff --dir ../Y Now it's A$ be --dir X diff --dir Y The --root option to `be init` has been removed as redundant. Replace calls like be init --root DIR with be --dir DIR init --- .../79fb6ef2-176c-45c0-b898-59c3c3e0aafe/body | 13 +++++++++++ .../79fb6ef2-176c-45c0-b898-59c3c3e0aafe/values | 11 +++++++++ NEWS | 5 +++++ README.dev | 5 ++++- be | 8 +++---- becommands/assign.py | 6 +++-- becommands/close.py | 6 +++-- becommands/comment.py | 6 +++-- becommands/commit.py | 6 +++-- becommands/depend.py | 6 +++-- becommands/diff.py | 6 +++-- becommands/due.py | 6 +++-- becommands/email_bugs.py | 6 +++-- becommands/help.py | 3 ++- becommands/html.py | 6 +++-- becommands/import_xml.py | 6 +++-- becommands/init.py | 26 ++++++++++++---------- becommands/list.py | 6 +++-- becommands/merge.py | 6 +++-- becommands/new.py | 6 +++-- becommands/open.py | 6 +++-- becommands/remove.py | 6 +++-- becommands/set.py | 6 +++-- becommands/severity.py | 6 +++-- becommands/show.py | 6 +++-- becommands/status.py | 6 +++-- becommands/subscribe.py | 6 +++-- becommands/tag.py | 6 +++-- becommands/target.py | 6 +++-- libbe/cmdutil.py | 7 ++++-- 30 files changed, 145 insertions(+), 65 deletions(-) create mode 100644 .be/bugs/52034fd0-ec50-424d-b25d-2beaf2d2c317/comments/79fb6ef2-176c-45c0-b898-59c3c3e0aafe/body create mode 100644 .be/bugs/52034fd0-ec50-424d-b25d-2beaf2d2c317/comments/79fb6ef2-176c-45c0-b898-59c3c3e0aafe/values diff --git a/.be/bugs/52034fd0-ec50-424d-b25d-2beaf2d2c317/comments/79fb6ef2-176c-45c0-b898-59c3c3e0aafe/body b/.be/bugs/52034fd0-ec50-424d-b25d-2beaf2d2c317/comments/79fb6ef2-176c-45c0-b898-59c3c3e0aafe/body new file mode 100644 index 0000000..7dbeebb --- /dev/null +++ b/.be/bugs/52034fd0-ec50-424d-b25d-2beaf2d2c317/comments/79fb6ef2-176c-45c0-b898-59c3c3e0aafe/body @@ -0,0 +1,13 @@ +> * Determining what to commit. +> +> You'd have to have RCS keep a log of all versioned files it +> touched, and extend .commit() to accept the keyword list "files" +> and commit only those files. This is doable, but maybe not worth +> the trouble. + +On the other hand, just attemting to commit evverything after each +command would make it nice and easy to commit bug fixes: + be --auto-commit status XYZ fixed +which would commit whatever changes you had outstanding with an +appropriate commit message. + diff --git a/.be/bugs/52034fd0-ec50-424d-b25d-2beaf2d2c317/comments/79fb6ef2-176c-45c0-b898-59c3c3e0aafe/values b/.be/bugs/52034fd0-ec50-424d-b25d-2beaf2d2c317/comments/79fb6ef2-176c-45c0-b898-59c3c3e0aafe/values new file mode 100644 index 0000000..b3dba3f --- /dev/null +++ b/.be/bugs/52034fd0-ec50-424d-b25d-2beaf2d2c317/comments/79fb6ef2-176c-45c0-b898-59c3c3e0aafe/values @@ -0,0 +1,11 @@ +Author: W. Trevor King + + +Content-type: text/plain + + +Date: Sun, 06 Dec 2009 21:45:15 +0000 + + +In-reply-to: 4c50ca0b-a08f-4723-b00d-4bf342cf86b6 + diff --git a/NEWS b/NEWS index 0cf9aae..84256e1 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +December 6, 2009 + * be --dir DIR COMMAND now roots the bugdir in DIR _without_ changing + directories. + * `be init --root DIR` should now be `be --dir DIR init`. + December 5, 2009 * targets are now a special type of bug (severity 'target'), so you can do all the things you do with normal bugs to them as well diff --git a/README.dev b/README.dev index fb4f471..dbb97b0 100644 --- a/README.dev +++ b/README.dev @@ -10,7 +10,8 @@ To fit into the current framework, your extension module should provide the following elements: __desc__ A short string describing the purpose of your plugin - execute(args, manipulate_encodings=True, restrict_file_access=False) + execute(args, manipulate_encodings=True, restrict_file_access=False, + dir=".") The entry function for your plugin. args is everything from sys.argv after the name of your plugin (e.g. for the command `be open abc', args=['abc']). @@ -23,6 +24,8 @@ provide the following elements: before attempting to read or write a file. See the restrict_file_access documentation for details. + dir is a directory inside the repository of interest. + Note: be supports command-completion. To avoid raising errors you need to deal with possible '--complete' options and arguments. See the 'Command completion' section below for more information. diff --git a/be b/be index c5c372f..a4a3ea4 100755 --- a/be +++ b/be @@ -34,8 +34,8 @@ parser.add_option("--version", action="store_true", dest="version", help="Print version string and exit.") parser.add_option("--verbose-version", action="store_true", dest="verbose_version", help="Print verbose version information and exit.") -parser.add_option("-d", "--dir", dest="dir", metavar="DIR", - help="Run this command from DIR instead of the current directory.") +parser.add_option("-d", "--dir", dest="dir", metavar="DIR", default=".", + help="Run this command on the repository in DIR instead of the current directory.") try: options,args = parser.parse_args() @@ -56,13 +56,11 @@ except cmdutil.GetCompletions, e: if options.version == True or options.verbose_version == True: print version.version(verbose=options.verbose_version) sys.exit(0) -if options.dir != None: - os.chdir(options.dir) try: if len(args) == 0: raise cmdutil.UsageError, "must supply a command" - sys.exit(cmdutil.execute(args[0], args[1:])) + sys.exit(cmdutil.execute(args[0], args=args[1:], dir=dir)) except cmdutil.GetHelp: print cmdutil.help(args[0]) sys.exit(0) diff --git a/becommands/assign.py b/becommands/assign.py index 2c78f69..9c971ae 100644 --- a/becommands/assign.py +++ b/becommands/assign.py @@ -21,7 +21,8 @@ from libbe import cmdutil, bugdir __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os >>> bd = bugdir.SimpleBugDir() @@ -56,7 +57,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): help() raise cmdutil.UsageError("Too many arguments.") bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) bug = cmdutil.bug_from_id(bd, args[0]) bug = bd.bug_from_shortname(args[0]) if len(args) == 1: diff --git a/becommands/close.py b/becommands/close.py index a14cea8..026c605 100644 --- a/becommands/close.py +++ b/becommands/close.py @@ -21,7 +21,8 @@ from libbe import cmdutil, bugdir __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> from libbe import bugdir >>> import os @@ -44,7 +45,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): if len(args) > 1: raise cmdutil.UsageError("Too many arguments.") bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) bug = cmdutil.bug_from_id(bd, args[0]) bug.status = "closed" bd.save() diff --git a/becommands/comment.py b/becommands/comment.py index fbc994f..9919d1d 100644 --- a/becommands/comment.py +++ b/becommands/comment.py @@ -21,7 +21,8 @@ import os import sys __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import time >>> bd = bugdir.SimpleBugDir() @@ -69,7 +70,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): shortname = args[0] bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) bug, parent = cmdutil.bug_comment_from_id(bd, shortname) if len(args) == 1: # try to launch an editor for comment-body entry diff --git a/becommands/commit.py b/becommands/commit.py index 39d1e2e..cade355 100644 --- a/becommands/commit.py +++ b/becommands/commit.py @@ -18,7 +18,8 @@ from libbe import cmdutil, bugdir, editor, vcs import sys __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os >>> from libbe import bug @@ -37,7 +38,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): if len(args) != 1: raise cmdutil.UsageError("Please supply a commit message") bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) if args[0] == '-': # read summary from stdin assert options.body != "EDITOR", \ "Cannot spawn and editor when the summary is using stdin." diff --git a/becommands/depend.py b/becommands/depend.py index 6336793..c2cb2a4 100644 --- a/becommands/depend.py +++ b/becommands/depend.py @@ -35,7 +35,8 @@ class BrokenLink (Exception): self.blocking_bug = blocking_bug -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> from libbe import utility >>> bd = bugdir.SimpleBugDir() @@ -84,7 +85,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): raise cmdutil.UsageError("Only one bug id used in tree mode.") bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) if options.repair == True: good,fixed,broken = check_dependencies(bd, repair_broken_links=True) assert len(broken) == 0, broken diff --git a/becommands/diff.py b/becommands/diff.py index e844c10..c5c34f9 100644 --- a/becommands/diff.py +++ b/becommands/diff.py @@ -21,7 +21,8 @@ from libbe import cmdutil, bugdir, diff import os __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os >>> bd = bugdir.SimpleBugDir() @@ -69,7 +70,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): except ValueError, e: raise cmdutil.UsageError(e.msg) bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) if bd.vcs.versioned == False: raise cmdutil.UsageError('This directory is not revision-controlled.') if options.dir == None: diff --git a/becommands/due.py b/becommands/due.py index 6f11ad4..0b8d1e9 100644 --- a/becommands/due.py +++ b/becommands/due.py @@ -19,7 +19,8 @@ __desc__ = __doc__ DUE_TAG="DUE:" -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os >>> bd = bugdir.SimpleBugDir() @@ -43,7 +44,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): if len(args) not in (1, 2): raise cmdutil.UsageError('Incorrect number of arguments.') bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) bug = cmdutil.bug_from_id(bd, args[0]) if len(args) == 1: due_time = get_due(bug) diff --git a/becommands/email_bugs.py b/becommands/email_bugs.py index d0366df..f6641e3 100644 --- a/becommands/email_bugs.py +++ b/becommands/email_bugs.py @@ -33,7 +33,8 @@ __desc__ = __doc__ sendmail='/usr/sbin/sendmail -t' -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os >>> from libbe import bug @@ -96,7 +97,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): if len(args) == 0: raise cmdutil.UsageError bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) xml = show.output(args, bd, as_xml=True, with_comments=True) subject = options.subject if subject == None: diff --git a/becommands/help.py b/becommands/help.py index 99ab8c4..9e6d1aa 100644 --- a/becommands/help.py +++ b/becommands/help.py @@ -20,7 +20,8 @@ from libbe import cmdutil, utility __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ Print help of specified command (the manipulate_encodings argument is ignored). diff --git a/becommands/html.py b/becommands/html.py index a031188..d9e0d73 100644 --- a/becommands/html.py +++ b/becommands/html.py @@ -21,7 +21,8 @@ import xml.sax.saxutils, htmlentitydefs __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os >>> bd = bugdir.SimpleBugDir() @@ -50,7 +51,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): raise cmdutil.UsageError, 'Too many arguments.' bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) bd.load_all_bugs() html_gen = HTMLGen(bd, template=options.template, verbose=options.verbose, diff --git a/becommands/import_xml.py b/becommands/import_xml.py index d1ea026..b985193 100644 --- a/becommands/import_xml.py +++ b/becommands/import_xml.py @@ -29,7 +29,8 @@ if libbe.TESTING == True: import unittest __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import time >>> import StringIO @@ -64,7 +65,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): filename = args[0] bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) if options.comment_root != None: croot_bug,croot_comment = \ cmdutil.bug_comment_from_id(bd, options.comment_root) diff --git a/becommands/init.py b/becommands/init.py index 6085286..ab9255b 100644 --- a/becommands/init.py +++ b/becommands/init.py @@ -20,7 +20,8 @@ import os.path from libbe import cmdutil, bugdir __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> from libbe import utility, vcs >>> import os @@ -30,7 +31,7 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): ... except bugdir.NoBugDir, e: ... True True - >>> execute(['--root', dir.path], manipulate_encodings=False) + >>> execute([], manipulate_encodings=False, dir=dir.path) No revision control detected. Directory initialized. >>> dir.cleanup() @@ -47,11 +48,12 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): >>> _vcs.cleanup() >>> try: - ... execute(['--root', '.'], manipulate_encodings=False) + ... execute([], manipulate_encodings=False, dir=".") ... except cmdutil.UserError, e: ... str(e).startswith("Directory already initialized: ") True - >>> execute(['--root', '/highly-unlikely-to-exist'], manipulate_encodings=False) + >>> execute([], manipulate_encodings=False, + ... dir='/highly-unlikely-to-exist') Traceback (most recent call last): UserError: No such directory: /highly-unlikely-to-exist >>> os.chdir('/') @@ -63,14 +65,15 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): if len(args) > 0: raise cmdutil.UsageError try: - bd = bugdir.BugDir(options.root_dir, from_disk=False, + bd = bugdir.BugDir(from_disk=False, sink_to_existing_root=False, assert_new_BugDir=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) except bugdir.NoRootEntry: - raise cmdutil.UserError("No such directory: %s" % options.root_dir) + raise cmdutil.UserError("No such directory: %s" % dir) except bugdir.AlreadyInitialized: - raise cmdutil.UserError("Directory already initialized: %s" % options.root_dir) + raise cmdutil.UserError("Directory already initialized: %s" % dir) bd.save() if bd.vcs.name is not "None": print "Using %s for revision control." % bd.vcs.name @@ -80,9 +83,6 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): def get_parser(): parser = cmdutil.CmdOptionParser("be init") - parser.add_option("-r", "--root", metavar="DIR", dest="root_dir", - help="Set root dir to something other than the current directory.", - default=".") return parser longhelp=""" @@ -90,7 +90,9 @@ This command initializes Bugs Everywhere support for the specified directory and all its subdirectories. It will auto-detect any supported revision control system. You can use "be set vcs_name" to change the vcs being used. -The directory defaults to your current working directory. +The directory defaults to your current working directory, but you can +change that by passing the --dir option to be + $ be --dir path/to/new/bug/root init It is usually a good idea to put the Bugs Everywhere root at the source code root, but you can put it anywhere. If you root Bugs Everywhere in a diff --git a/becommands/list.py b/becommands/list.py index fa5647b..1c3e78d 100644 --- a/becommands/list.py +++ b/becommands/list.py @@ -26,7 +26,8 @@ __desc__ = __doc__ AVAILABLE_CMPS = [fn[4:] for fn in dir(bug) if fn[:4] == 'cmp_'] AVAILABLE_CMPS.remove("attr") # a cmp_* template. -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os >>> bd = bugdir.SimpleBugDir() @@ -52,7 +53,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): cmp_list.append(eval('bug.cmp_%s' % cmp)) bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) bd.load_all_bugs() # select status if options.status != None: diff --git a/becommands/merge.py b/becommands/merge.py index 8cf7e2f..ac09b40 100644 --- a/becommands/merge.py +++ b/becommands/merge.py @@ -19,7 +19,8 @@ from libbe import cmdutil, bugdir import os, copy __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> from libbe import utility >>> bd = bugdir.SimpleBugDir() @@ -134,7 +135,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): raise cmdutil.UsageError("Too many arguments.") bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) bugA = cmdutil.bug_from_id(bd, args[0]) bugA.load_comments() bugB = cmdutil.bug_from_id(bd, args[1]) diff --git a/becommands/new.py b/becommands/new.py index 00e8a47..30f8834 100644 --- a/becommands/new.py +++ b/becommands/new.py @@ -20,7 +20,8 @@ from libbe import cmdutil, bugdir import sys __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os, time >>> from libbe import bug @@ -47,7 +48,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): if len(args) != 1: raise cmdutil.UsageError("Please supply a summary message") bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) if args[0] == '-': # read summary from stdin summary = sys.stdin.readline() else: diff --git a/becommands/open.py b/becommands/open.py index c2c15e2..a6fe48d 100644 --- a/becommands/open.py +++ b/becommands/open.py @@ -21,7 +21,8 @@ from libbe import cmdutil, bugdir __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os >>> bd = bugdir.SimpleBugDir() @@ -43,7 +44,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): if len(args) > 1: raise cmdutil.UsageError, "Too many arguments." bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) bug = cmdutil.bug_from_id(bd, args[0]) bug.status = "open" diff --git a/becommands/remove.py b/becommands/remove.py index e4f0065..bac06c0 100644 --- a/becommands/remove.py +++ b/becommands/remove.py @@ -18,7 +18,8 @@ from libbe import cmdutil, bugdir __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> from libbe import mapfile >>> import os @@ -43,7 +44,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): if len(args) != 1: raise cmdutil.UsageError, "Please specify a bug id." bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) bug = cmdutil.bug_from_id(bd, args[0]) bd.remove_bug(bug) print "Removed bug %s" % bug.uuid diff --git a/becommands/set.py b/becommands/set.py index c8c5a2c..4d54a59 100644 --- a/becommands/set.py +++ b/becommands/set.py @@ -32,7 +32,8 @@ def _value_string(bd, setting): val = None return str(val) -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os >>> bd = bugdir.SimpleBugDir() @@ -53,7 +54,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): if len(args) > 2: raise cmdutil.UsageError, "Too many arguments" bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) if len(args) == 0: keys = bd.settings_properties keys.sort() diff --git a/becommands/severity.py b/becommands/severity.py index 524976b..804dc4e 100644 --- a/becommands/severity.py +++ b/becommands/severity.py @@ -21,7 +21,8 @@ from libbe import cmdutil, bugdir, bug __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os >>> bd = bugdir.SimpleBugDir() @@ -42,7 +43,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): if len(args) not in (1,2): raise cmdutil.UsageError bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) bug = cmdutil.bug_from_id(bd, args[0]) if len(args) == 1: print bug.severity diff --git a/becommands/show.py b/becommands/show.py index ab1708f..7757aaa 100644 --- a/becommands/show.py +++ b/becommands/show.py @@ -22,7 +22,8 @@ import sys from libbe import cmdutil, bugdir, comment, version, _version __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os >>> bd = bugdir.SimpleBugDir() @@ -66,7 +67,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): if len(args) == 0: raise cmdutil.UsageError bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) if options.only_raw_body == True: if len(args) != 1: diff --git a/becommands/status.py b/becommands/status.py index fd31c97..58b6f63 100644 --- a/becommands/status.py +++ b/becommands/status.py @@ -18,7 +18,8 @@ from libbe import cmdutil, bugdir, bug __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os >>> bd = bugdir.SimpleBugDir() @@ -39,7 +40,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): if len(args) not in (1,2): raise cmdutil.UsageError bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) bug = cmdutil.bug_from_id(bd, args[0]) if len(args) == 1: print bug.status diff --git a/becommands/subscribe.py b/becommands/subscribe.py index 19aac53..69554f7 100644 --- a/becommands/subscribe.py +++ b/becommands/subscribe.py @@ -20,7 +20,8 @@ __desc__ = __doc__ TAG="SUBSCRIBE:" -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> bd = bugdir.SimpleBugDir() >>> bd.set_sync_with_disk(True) @@ -73,7 +74,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): raise cmdutil.UsageError("Too many arguments.") bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) subscriber = options.subscriber if subscriber == None: diff --git a/becommands/tag.py b/becommands/tag.py index e22cb70..f3819bd 100644 --- a/becommands/tag.py +++ b/becommands/tag.py @@ -19,7 +19,8 @@ from libbe import cmdutil, bugdir import os, copy __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> from libbe import utility >>> bd = bugdir.SimpleBugDir() @@ -81,7 +82,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): raise cmdutil.UsageError("Too many arguments.") bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) if options.list: bd.load_all_bugs() tags = [] diff --git a/becommands/target.py b/becommands/target.py index 9ccbacc..5dd5d38 100644 --- a/becommands/target.py +++ b/becommands/target.py @@ -23,7 +23,8 @@ from libbe import cmdutil, bugdir from becommands import depend __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os, StringIO, sys >>> bd = bugdir.SimpleBugDir() @@ -60,7 +61,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): or (options.resolve == True and len(args) not in (0, 1)): raise cmdutil.UsageError('Incorrect number of arguments.') bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) if options.resolve == True: if len(args) == 0: summary = None diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py index b892bde..c567984 100644 --- a/libbe/cmdutil.py +++ b/libbe/cmdutil.py @@ -79,12 +79,15 @@ def get_command(command_name): return cmd -def execute(cmd, args, manipulate_encodings=True, restrict_file_access=False): +def execute(cmd, args, + manipulate_encodings=True, restrict_file_access=False, + dir="."): enc = encoding.get_encoding() cmd = get_command(cmd) ret = cmd.execute([a.decode(enc) for a in args], manipulate_encodings=manipulate_encodings, - restrict_file_access=restrict_file_access) + restrict_file_access=restrict_file_access, + dir=dir) if ret == None: ret = 0 return ret -- cgit From adfd866bf1fafc3832e03506a09c9b5750fe7447 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 7 Dec 2009 07:00:34 -0500 Subject: Added libbe.pager --- libbe/pager.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 libbe/pager.py diff --git a/libbe/pager.py b/libbe/pager.py new file mode 100644 index 0000000..8190b2a --- /dev/null +++ b/libbe/pager.py @@ -0,0 +1,51 @@ +# Copyright + +""" +Automatic pager for terminal output (a la Git). +""" + +import sys, os, select + +# see http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby +def run_pager(paginate=None): + """ + paginate should be one of 'never', 'auto', or 'always'. + + usage: just call this function and continue using sys.stdout like + you normally would. + """ + if paginate == 'never' \ + or sys.platform == 'win32' \ + or not hasattr(sys.stdout, 'isatty') \ + or sys.stdout.isatty() == False: + return + + if paginate == 'auto': + if 'LESS' not in os.environ: + os.environ['LESS'] = '' # += doesn't work on undefined var + # don't page if the input is short enough + os.environ['LESS'] += ' -FRX' + if 'PAGER' in os.environ: + pager = os.environ['PAGER'] + else: + pager = 'less' + + read_fd, write_fd = os.pipe() + if os.fork() == 0: + # child process + os.close(read_fd) + os.close(0) + os.dup2(write_fd, 1) + os.close(write_fd) + if hasattr(sys.stderr, 'isatty') and sys.stderr.isatty() == True: + os.dup2(1, 2) + return + + # parent process, become pager + os.close(write_fd) + os.dup2(read_fd, 0) + os.close(read_fd) + + # Wait until we have input before we start the pager + select.select([0], [], []) + os.execlp(pager, pager) -- cgit From 4e3ad6eacd83ebeac3156bc4944b8943247ffb2a Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 7 Dec 2009 07:02:15 -0500 Subject: Update libbe.pager copyright --- libbe/pager.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libbe/pager.py b/libbe/pager.py index 8190b2a..3fcae84 100644 --- a/libbe/pager.py +++ b/libbe/pager.py @@ -1,4 +1,18 @@ -# Copyright +# Copyright (C) 2009 W. Trevor King +# +# 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; either version 2 of the License, or +# (at your option) any later version. +# +# 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 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., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """ Automatic pager for terminal output (a la Git). -- cgit From 0784330491a640f4e6016342b0bc2958d36b0b40 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 7 Dec 2009 07:20:23 -0500 Subject: Use 'auto' for run_pager default rather than None --- libbe/pager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbe/pager.py b/libbe/pager.py index 3fcae84..1ddc3fa 100644 --- a/libbe/pager.py +++ b/libbe/pager.py @@ -21,7 +21,7 @@ Automatic pager for terminal output (a la Git). import sys, os, select # see http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby -def run_pager(paginate=None): +def run_pager(paginate='auto'): """ paginate should be one of 'never', 'auto', or 'always'. -- cgit From fada10afd00989bef0468373ae435234224390c1 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 7 Dec 2009 07:25:18 -0500 Subject: Added --paginate and --no-pager to be --- be | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/be b/be index a4a3ea4..f026c05 100755 --- a/be +++ b/be @@ -22,7 +22,7 @@ import os import sys -from libbe import cmdutil, version +from libbe import cmdutil, version, pager __doc__ = cmdutil.help() @@ -36,6 +36,13 @@ parser.add_option("--verbose-version", action="store_true", dest="verbose_versio help="Print verbose version information and exit.") parser.add_option("-d", "--dir", dest="dir", metavar="DIR", default=".", help="Run this command on the repository in DIR instead of the current directory.") +parser.add_option("-p", "--paginate", dest="paginate", default=False, + action='store_true', + help="Pipe all output into less (or if set, $PAGER).") +parser.add_option("--no-pager", dest="no_pager", default=False, + action='store_true', + help="Do not pipe git output into a pager.") + try: options,args = parser.parse_args() @@ -57,10 +64,17 @@ if options.version == True or options.verbose_version == True: print version.version(verbose=options.verbose_version) sys.exit(0) +paginate = 'auto' +if options.paginate == True: + paginate = 'always' +if options.no_pager== True: + paginate = 'never' +pager.run_pager(paginate) + try: if len(args) == 0: raise cmdutil.UsageError, "must supply a command" - sys.exit(cmdutil.execute(args[0], args=args[1:], dir=dir)) + sys.exit(cmdutil.execute(args[0], args=args[1:], dir=options.dir)) except cmdutil.GetHelp: print cmdutil.help(args[0]) sys.exit(0) -- cgit From a2562bc912e33fb3748be9d01771c9ae0ed6010f Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 7 Dec 2009 07:34:14 -0500 Subject: Updated NEWS --- NEWS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 84256e1..53804e6 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,5 @@ -December 6, 2009 +December 7, 2009 + * added --paginate and --no-pager to be. * be --dir DIR COMMAND now roots the bugdir in DIR _without_ changing directories. * `be init --root DIR` should now be `be --dir DIR init`. -- cgit