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 --- libbe/cmdutil.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'libbe') 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 (limited to 'libbe') 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(-) (limited to 'libbe') 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(-) (limited to 'libbe') 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