From 49a7771336ce09f6d42c7699ef32aecea0e83182 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 7 Dec 2009 20:07:55 -0500 Subject: Initial directory restructuring to clarify dependencies --- libbe/command/init.py | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 libbe/command/init.py (limited to 'libbe/command/init.py') diff --git a/libbe/command/init.py b/libbe/command/init.py new file mode 100644 index 0000000..ab9255b --- /dev/null +++ b/libbe/command/init.py @@ -0,0 +1,104 @@ +# Copyright (C) 2005-2009 Aaron Bentley and Panometrics, Inc. +# Gianluca Montecchi +# 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. +"""Assign the root directory for bug tracking""" +import os.path +from libbe import cmdutil, bugdir +__desc__ = __doc__ + +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): + """ + >>> from libbe import utility, vcs + >>> import os + >>> dir = utility.Dir() + >>> try: + ... bugdir.BugDir(dir.path) + ... except bugdir.NoBugDir, e: + ... True + True + >>> execute([], manipulate_encodings=False, dir=dir.path) + No revision control detected. + Directory initialized. + >>> dir.cleanup() + + >>> dir = utility.Dir() + >>> os.chdir(dir.path) + >>> _vcs = vcs.installed_vcs() + >>> _vcs.init('.') + >>> _vcs.name in vcs.VCS_ORDER + True + >>> execute([], manipulate_encodings=False) # doctest: +ELLIPSIS + Using ... for revision control. + Directory initialized. + >>> _vcs.cleanup() + + >>> try: + ... execute([], manipulate_encodings=False, dir=".") + ... except cmdutil.UserError, e: + ... str(e).startswith("Directory already initialized: ") + True + >>> execute([], manipulate_encodings=False, + ... dir='/highly-unlikely-to-exist') + Traceback (most recent call last): + UserError: No such directory: /highly-unlikely-to-exist + >>> os.chdir('/') + >>> dir.cleanup() + """ + parser = get_parser() + options, args = parser.parse_args(args) + cmdutil.default_complete(options, args, parser) + if len(args) > 0: + raise cmdutil.UsageError + try: + bd = bugdir.BugDir(from_disk=False, + sink_to_existing_root=False, + assert_new_BugDir=True, + manipulate_encodings=manipulate_encodings, + root=dir) + except bugdir.NoRootEntry: + raise cmdutil.UserError("No such directory: %s" % dir) + except bugdir.AlreadyInitialized: + 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 + else: + print "No revision control detected." + print "Directory initialized." + +def get_parser(): + parser = cmdutil.CmdOptionParser("be init") + return parser + +longhelp=""" +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, 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 +subdirectory, then only bugs created in that subdirectory (and its children) +will appear there. +""" + +def help(): + return get_parser().help_str() + longhelp -- cgit From 2f0ceedba5b6619faf476cd1aa67e826e91d5c7c Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 14 Dec 2009 03:29:20 -0500 Subject: Transitioned init to Command format --- libbe/command/init.py | 152 ++++++++++++++++++++++++++++---------------------- 1 file changed, 85 insertions(+), 67 deletions(-) (limited to 'libbe/command/init.py') diff --git a/libbe/command/init.py b/libbe/command/init.py index ab9255b..cdaa149 100644 --- a/libbe/command/init.py +++ b/libbe/command/init.py @@ -15,90 +15,108 @@ # 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. -"""Assign the root directory for bug tracking""" + import os.path -from libbe import cmdutil, bugdir -__desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False, - dir="."): - """ - >>> from libbe import utility, vcs - >>> import os - >>> dir = utility.Dir() +import libbe +import libbe.bugdir +import libbe.command +import libbe.command.util +import libbe.storage + +class Init (libbe.command.Command): + """Create an on-disk bug repository + + >>> import os, sys + >>> import libbe.storage.vcs + >>> import libbe.storage.vcs.base + >>> import libbe.util.utility + >>> cmd = Init() + >>> cmd._setup_io = lambda i_enc,o_enc : None + >>> cmd.stdout = sys.stdout + + >>> dir = libbe.util.utility.Dir() + >>> vcs = libbe.storage.vcs.vcs_by_name('None') + >>> vcs.repo = dir.path >>> try: - ... bugdir.BugDir(dir.path) - ... except bugdir.NoBugDir, e: + ... vcs.connect() + ... except libbe.storage.ConnectionError: ... True True - >>> execute([], manipulate_encodings=False, dir=dir.path) + >>> cmd.run(vcs) No revision control detected. - Directory initialized. + BE repository initialized. + >>> bd = libbe.bugdir.BugDir(vcs) + >>> vcs.disconnect() + >>> vcs.destroy() >>> dir.cleanup() - >>> dir = utility.Dir() - >>> os.chdir(dir.path) - >>> _vcs = vcs.installed_vcs() - >>> _vcs.init('.') - >>> _vcs.name in vcs.VCS_ORDER - True - >>> execute([], manipulate_encodings=False) # doctest: +ELLIPSIS + >>> dir = libbe.util.utility.Dir() + >>> vcs = libbe.storage.vcs.installed_vcs() + >>> if vcs.name in libbe.storage.vcs.base.VCS_ORDER: + ... vcs.repo = dir.path + ... vcs._vcs_init(vcs.repo) + ... cmd.run(vcs) # doctest: +ELLIPSIS + ... else: + ... print 'Using ... for revision control.\\nDirectory initialized.' Using ... for revision control. - Directory initialized. - >>> _vcs.cleanup() - - >>> try: - ... execute([], manipulate_encodings=False, dir=".") - ... except cmdutil.UserError, e: - ... str(e).startswith("Directory already initialized: ") - True - >>> execute([], manipulate_encodings=False, - ... dir='/highly-unlikely-to-exist') - Traceback (most recent call last): - UserError: No such directory: /highly-unlikely-to-exist - >>> os.chdir('/') + BE repository initialized. + >>> vcs.disconnect() + >>> vcs.destroy() >>> dir.cleanup() """ - parser = get_parser() - options, args = parser.parse_args(args) - cmdutil.default_complete(options, args, parser) - if len(args) > 0: - raise cmdutil.UsageError - try: - bd = bugdir.BugDir(from_disk=False, - sink_to_existing_root=False, - assert_new_BugDir=True, - manipulate_encodings=manipulate_encodings, - root=dir) - except bugdir.NoRootEntry: - raise cmdutil.UserError("No such directory: %s" % dir) - except bugdir.AlreadyInitialized: - 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 - else: - print "No revision control detected." - print "Directory initialized." + + name = 'init' -def get_parser(): - parser = cmdutil.CmdOptionParser("be init") - return parser + def __init__(self, *args, **kwargs): + libbe.command.Command.__init__(self, *args, **kwargs) + self.requires_unconnected_storage = True -longhelp=""" + def _run(self, storage, bugdir=None, **params): + if not os.path.isdir(storage.repo): + raise libbe.command.UserError( + 'No such directory: %s' % storage.repo) + try: + storage.connect() + raise libbe.command.UserError( + 'Directory already initialized: %s' % storage.repo) + except libbe.storage.ConnectionError: + pass + storage.init() + storage.connect() + bd = libbe.bugdir.BugDir(storage, from_storage=False) + bd.save() + if bd.storage.name is not 'None': + print >> self.stdout, \ + 'Using %s for revision control.' % storage.name + else: + print >> self.stdout, 'No revision control detected.' + print >> self.stdout, 'BE repository initialized.' + + def _long_help(self): + return """ 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, but you can -change that by passing the --dir option to be - $ be --dir path/to/new/bug/root init +change that by passing the --repo option to be + $ be --repo 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 -subdirectory, then only bugs created in that subdirectory (and its children) -will appear there. +When initialized in a version-controlled directory, BE sinks to the +version-control root. In that case, the BE repository will be created +under that directory, rather than the current directory or the one +passed in --repo. Consider the following tree, versioned in Git. + ~ + `--projectX + |-- .git + `-- src +Calling + ~$ be --repo ./projectX/src init +will create the BE repository rooted in projectX: + ~ + `--projectX + |-- .be + |-- .git + `-- src """ - -def help(): - return get_parser().help_str() + longhelp -- cgit From 19fe0817ba7c2cd04caea3adfa82d4490288a548 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 14 Dec 2009 07:37:51 -0500 Subject: Transitioned comment to Command format --- libbe/command/init.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libbe/command/init.py') diff --git a/libbe/command/init.py b/libbe/command/init.py index cdaa149..017cdc3 100644 --- a/libbe/command/init.py +++ b/libbe/command/init.py @@ -21,7 +21,6 @@ import os.path import libbe import libbe.bugdir import libbe.command -import libbe.command.util import libbe.storage class Init (libbe.command.Command): @@ -53,11 +52,13 @@ class Init (libbe.command.Command): >>> dir = libbe.util.utility.Dir() >>> vcs = libbe.storage.vcs.installed_vcs() + >>> vcs.repo = dir.path + >>> vcs._vcs_init(vcs.repo) >>> if vcs.name in libbe.storage.vcs.base.VCS_ORDER: - ... vcs.repo = dir.path - ... vcs._vcs_init(vcs.repo) ... cmd.run(vcs) # doctest: +ELLIPSIS ... else: + ... vcs.init() + ... vcs.connect() ... print 'Using ... for revision control.\\nDirectory initialized.' Using ... for revision control. BE repository initialized. @@ -65,7 +66,6 @@ class Init (libbe.command.Command): >>> vcs.destroy() >>> dir.cleanup() """ - name = 'init' def __init__(self, *args, **kwargs): -- cgit From 1b9c628529848af370adbc67b5ba298236a1b86d Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 14 Dec 2009 23:15:58 -0500 Subject: Transitioned severity to Command-format, also added Command._get_*() The old .requires_* thing was rediculous. The new ._get_*() callbacks allow the caller to provide a means for getting the expensive structures, which the command can use, or not, as required. This will also make it easier to implement the completion callbacks. The callbacks should probably have matching .set_*() methods, to avoid the current cache tweaking cmd._storage = ... etc. But that can wait for now... --- libbe/command/init.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'libbe/command/init.py') diff --git a/libbe/command/init.py b/libbe/command/init.py index 017cdc3..b52d8e8 100644 --- a/libbe/command/init.py +++ b/libbe/command/init.py @@ -42,7 +42,8 @@ class Init (libbe.command.Command): ... except libbe.storage.ConnectionError: ... True True - >>> cmd.run(vcs) + >>> cmd._unconnected_storage = vcs + >>> cmd.run() No revision control detected. BE repository initialized. >>> bd = libbe.bugdir.BugDir(vcs) @@ -54,8 +55,9 @@ class Init (libbe.command.Command): >>> vcs = libbe.storage.vcs.installed_vcs() >>> vcs.repo = dir.path >>> vcs._vcs_init(vcs.repo) + >>> cmd._unconnected_storage = vcs >>> if vcs.name in libbe.storage.vcs.base.VCS_ORDER: - ... cmd.run(vcs) # doctest: +ELLIPSIS + ... cmd.run() # doctest: +ELLIPSIS ... else: ... vcs.init() ... vcs.connect() @@ -70,9 +72,9 @@ class Init (libbe.command.Command): def __init__(self, *args, **kwargs): libbe.command.Command.__init__(self, *args, **kwargs) - self.requires_unconnected_storage = True - def _run(self, storage, bugdir=None, **params): + def _run(self, **params): + storage = self._get_unconnected_storage() if not os.path.isdir(storage.repo): raise libbe.command.UserError( 'No such directory: %s' % storage.repo) -- cgit From cfae8a8302f06a84196700138d7ddbb25e91ea31 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 31 Dec 2009 14:32:39 -0500 Subject: Added UserInterface and other improved abstractions for command handling --- libbe/command/init.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'libbe/command/init.py') diff --git a/libbe/command/init.py b/libbe/command/init.py index b52d8e8..2a78147 100644 --- a/libbe/command/init.py +++ b/libbe/command/init.py @@ -30,9 +30,10 @@ class Init (libbe.command.Command): >>> import libbe.storage.vcs >>> import libbe.storage.vcs.base >>> import libbe.util.utility + >>> io = libbe.command.StringInputOutput() + >>> io.stdout = sys.stdout + >>> ui = libbe.command.UserInterface(io=io) >>> cmd = Init() - >>> cmd._setup_io = lambda i_enc,o_enc : None - >>> cmd.stdout = sys.stdout >>> dir = libbe.util.utility.Dir() >>> vcs = libbe.storage.vcs.vcs_by_name('None') @@ -40,10 +41,10 @@ class Init (libbe.command.Command): >>> try: ... vcs.connect() ... except libbe.storage.ConnectionError: - ... True - True - >>> cmd._unconnected_storage = vcs - >>> cmd.run() + ... 'got error' + 'got error' + >>> ui.storage_callbacks.set_unconnected_storage(vcs) + >>> ui.run(cmd) No revision control detected. BE repository initialized. >>> bd = libbe.bugdir.BugDir(vcs) @@ -55,9 +56,9 @@ class Init (libbe.command.Command): >>> vcs = libbe.storage.vcs.installed_vcs() >>> vcs.repo = dir.path >>> vcs._vcs_init(vcs.repo) - >>> cmd._unconnected_storage = vcs + >>> ui.storage_callbacks.set_unconnected_storage(vcs) >>> if vcs.name in libbe.storage.vcs.base.VCS_ORDER: - ... cmd.run() # doctest: +ELLIPSIS + ... ui.run(cmd) # doctest: +ELLIPSIS ... else: ... vcs.init() ... vcs.connect() -- cgit From 4d4283ecd654f1efb058cd7f7dba6be88b70ee92 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 1 Jan 2010 08:11:08 -0500 Subject: Updated copyright information --- libbe/command/init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libbe/command/init.py') diff --git a/libbe/command/init.py b/libbe/command/init.py index 2a78147..7fdbdae 100644 --- a/libbe/command/init.py +++ b/libbe/command/init.py @@ -1,4 +1,4 @@ -# Copyright (C) 2005-2009 Aaron Bentley and Panometrics, Inc. +# Copyright (C) 2005-2010 Aaron Bentley and Panometrics, Inc. # Gianluca Montecchi # W. Trevor King # -- cgit From 2cd6b109becedafa7aab4060ab4fee66a624bf59 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 22 Jan 2010 09:15:36 -0500 Subject: Added tests to Init to check for empty settings file --- libbe/command/init.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'libbe/command/init.py') diff --git a/libbe/command/init.py b/libbe/command/init.py index 7fdbdae..4e8bfc2 100644 --- a/libbe/command/init.py +++ b/libbe/command/init.py @@ -49,6 +49,10 @@ class Init (libbe.command.Command): BE repository initialized. >>> bd = libbe.bugdir.BugDir(vcs) >>> vcs.disconnect() + >>> vcs.connect() + >>> bugdir = libbe.bugdir.BugDir(vcs, from_storage=True) + >>> bugdir.settings + >>> vcs.disconnect() >>> vcs.destroy() >>> dir.cleanup() @@ -66,6 +70,10 @@ class Init (libbe.command.Command): Using ... for revision control. BE repository initialized. >>> vcs.disconnect() + >>> vcs.connect() + >>> bugdir = libbe.bugdir.BugDir(vcs, from_storage=True) + >>> bugdir.settings + >>> vcs.disconnect() >>> vcs.destroy() >>> dir.cleanup() """ @@ -88,7 +96,6 @@ class Init (libbe.command.Command): storage.init() storage.connect() bd = libbe.bugdir.BugDir(storage, from_storage=False) - bd.save() if bd.storage.name is not 'None': print >> self.stdout, \ 'Using %s for revision control.' % storage.name -- cgit From bda68bb5d93f4b608fb1dd17c5a0cf1bb406daf9 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 22 Jan 2010 11:30:26 -0500 Subject: Reworked settings_object module, but command.init tests still fail: $ python test.py libbe.command.init Doctest: libbe.command.init.Init ... FAIL ... ----------------------- File ".../libbe/command/init.py", line 47, in libbe.command.init.Init Failed example: ui.run(cmd) Exception raised: Traceback (most recent call last): ... File "/tmp/be.wtk/libbe/command/init.py", line 97, in _run bd = libbe.bugdir.BugDir(storage, from_storage=False) File "/tmp/be.wtk/libbe/bugdir.py", line 185, in __init__ self.save() File "/tmp/be.wtk/libbe/bugdir.py", line 228, in save self.save_settings() File "/tmp/be.wtk/libbe/bugdir.py", line 204, in save_settings mf = mapfile.generate(self._get_saved_settings()) File "/tmp/be.wtk/libbe/storage/util/settings_object.py", line 230, in _get_saved_settings self, self._setting_name_to_attr_name(k)) File "/tmp/be.wtk/libbe/storage/util/properties.py", line 194, in _fget value = fget(self) File "/tmp/be.wtk/libbe/storage/util/properties.py", line 329, in _fget primer(self) File "/tmp/be.wtk/libbe/storage/util/settings_object.py", line 69, in prop_load_settings self.load_settings() File "/tmp/be.wtk/libbe/bugdir.py", line 194, in load_settings self.settings = mapfile.parse(settings_mapfile) File "/tmp/be.wtk/libbe/storage/util/mapfile.py", line 123, in parse c = yaml.load(contents) ... File "/usr/lib/python2.6/site-packages/yaml/reader.py", line 213, in update_raw data = self.stream.read(size) AttributeError: 'NoneType' object has no attribute 'read' ... --- libbe/command/init.py | 1 - 1 file changed, 1 deletion(-) (limited to 'libbe/command/init.py') diff --git a/libbe/command/init.py b/libbe/command/init.py index 4e8bfc2..aadc0c7 100644 --- a/libbe/command/init.py +++ b/libbe/command/init.py @@ -72,7 +72,6 @@ class Init (libbe.command.Command): >>> vcs.disconnect() >>> vcs.connect() >>> bugdir = libbe.bugdir.BugDir(vcs, from_storage=True) - >>> bugdir.settings >>> vcs.disconnect() >>> vcs.destroy() >>> dir.cleanup() -- cgit From e2507e15c2a7b46bfd2bd76056368e4a3398472f Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 22 Jan 2010 14:05:01 -0500 Subject: Minor cleanups + remove debuging line in Init doctest --- libbe/command/init.py | 1 - 1 file changed, 1 deletion(-) (limited to 'libbe/command/init.py') diff --git a/libbe/command/init.py b/libbe/command/init.py index aadc0c7..4821000 100644 --- a/libbe/command/init.py +++ b/libbe/command/init.py @@ -51,7 +51,6 @@ class Init (libbe.command.Command): >>> vcs.disconnect() >>> vcs.connect() >>> bugdir = libbe.bugdir.BugDir(vcs, from_storage=True) - >>> bugdir.settings >>> vcs.disconnect() >>> vcs.destroy() >>> dir.cleanup() -- cgit From c8afe57fdc1111bdf5f053c0f2a9f4c38599c6de Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 23 Jan 2010 10:05:00 -0500 Subject: Init should tell the UI about its connected storage and bugdir. --- libbe/command/init.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libbe/command/init.py') diff --git a/libbe/command/init.py b/libbe/command/init.py index 4821000..7b83645 100644 --- a/libbe/command/init.py +++ b/libbe/command/init.py @@ -93,7 +93,9 @@ class Init (libbe.command.Command): pass storage.init() storage.connect() + self.ui.storage_callbacks.set_storage(storage) bd = libbe.bugdir.BugDir(storage, from_storage=False) + self.ui.storage_callbacks.set_bugdir(bd) if bd.storage.name is not 'None': print >> self.stdout, \ 'Using %s for revision control.' % storage.name -- cgit