aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/command/init.py
diff options
context:
space:
mode:
Diffstat (limited to 'libbe/command/init.py')
-rw-r--r--libbe/command/init.py152
1 files changed, 85 insertions, 67 deletions
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