>>> bd.bug_from_uuid('a').assigned is None
True
- >>> cmd.run(bd, {'user-id':u'Fran\xe7ois'}, ['-', '/a'])
+ >>> cmd.run(bd.storage, bd, {'user-id':u'Fran\xe7ois'}, ['-', '/a'])
>>> bd.flush_reload()
>>> bd.bug_from_uuid('a').assigned
u'Fran\\xe7ois'
- >>> cmd.run(bd, args=['someone', '/a', '/b'])
+ >>> cmd.run(bd.storage, bd, args=['someone', '/a', '/b'])
>>> bd.flush_reload()
>>> bd.bug_from_uuid('a').assigned
'someone'
>>> bd.bug_from_uuid('b').assigned
'someone'
- >>> cmd.run(bd, args=['none', '/a'])
+ >>> cmd.run(bd.storage, bd, args=['none', '/a'])
>>> bd.flush_reload()
>>> bd.bug_from_uuid('a').assigned is None
True
completion_callback=libbe.command.util.complete_bug_id),
])
- def _run(self, bugdir, **params):
+ def _run(self, storage, bugdir, **params):
assignee = params['assignee']
if assignee == 'none':
assignee = None
self.status = None
self.result = None
self.requires_bugdir = False
+ self.requires_unconnected_storage = False
self.input_encoding = None
self.output_encoding = None
self.options = [
]
self.args = []
- def run(self, bugdir, options=None, args=None):
+ def run(self, storage=None, bugdir=None, options=None, args=None):
if options == None:
options = {}
if args == None:
if 'user-id' in options:
params['user-id'] = options.pop('user-id')
else:
- params['user-id'] = libbe.ui.util.user.get_user_id(bugdir.storage)
+ params['user-id'] = libbe.ui.util.user.get_user_id(storage)
if len(options) > 0:
raise UserError, 'Invalid option passed to command %s:\n %s' \
% (self.name, '\n '.join(['%s: %s' % (k,v)
params.pop('complete')
self._setup_io(self.input_encoding, self.output_encoding)
- self.status = self._run(bugdir, **params)
+ self.status = self._run(storage, bugdir, **params)
return self.status
- def _run(self, bugdir, **kwargs):
+ def _run(self, storage, bugdir, **kwargs):
pass
def _setup_io(self, input_encoding=None, output_encoding=None):
# 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