Updated copyright blurbs and AUTHORS and included script for future updates
[be.git] / becommands / init.py
1 # Copyright (C) 2005-2009 Aaron Bentley and Panometrics, Inc.
2 #                         W. Trevor King <wking@drexel.edu>
3 # <abentley@panoramicfeedback.com>
4 #
5 #    This program is free software; you can redistribute it and/or modify
6 #    it under the terms of the GNU General Public License as published by
7 #    the Free Software Foundation; either version 2 of the License, or
8 #    (at your option) any later version.
9 #
10 #    This program is distributed in the hope that it will be useful,
11 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #    GNU General Public License for more details.
14 #
15 #    You should have received a copy of the GNU General Public License
16 #    along with this program; if not, write to the Free Software
17 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 """Assign the root directory for bug tracking"""
19 import os.path
20 from libbe import cmdutil, bugdir
21 __desc__ = __doc__
22
23 def execute(args, test=False):
24     """
25     >>> from libbe import utility, rcs
26     >>> import os
27     >>> dir = utility.Dir()
28     >>> try:
29     ...     bugdir.BugDir(dir.path)
30     ... except bugdir.NoBugDir, e:
31     ...     True
32     True
33     >>> execute([dir.path], test=True)
34     No revision control detected.
35     Directory initialized.
36     >>> del(dir)
37
38     >>> dir = utility.Dir()
39     >>> os.chdir(dir.path)
40     >>> rcs = rcs.installed_rcs()
41     >>> rcs.init('.')
42     >>> print rcs.name
43     Arch
44     >>> execute([], test=True)
45     Using Arch for revision control.
46     Directory initialized.
47     >>> rcs.cleanup()
48
49     >>> try:
50     ...     execute(['.'], test=True)
51     ... except cmdutil.UserError, e:
52     ...     str(e).startswith("Directory already initialized: ")
53     True
54     >>> execute(['/highly-unlikely-to-exist'], test=True)
55     Traceback (most recent call last):
56     UserError: No such directory: /highly-unlikely-to-exist
57     >>> os.chdir('/')
58     """
59     parser = get_parser()
60     options, args = parser.parse_args(args)
61     cmdutil.default_complete(options, args, parser)
62     if len(args) > 1:
63         raise cmdutil.UsageError
64     if len(args) == 1:
65         basedir = args[0]
66     else:
67         basedir = "."
68     try:
69         bd = bugdir.BugDir(basedir, from_disk=False, sink_to_existing_root=False, assert_new_BugDir=True,
70                            manipulate_encodings=not test)
71     except bugdir.NoRootEntry:
72         raise cmdutil.UserError("No such directory: %s" % basedir)
73     except bugdir.AlreadyInitialized:
74         raise cmdutil.UserError("Directory already initialized: %s" % basedir)
75     bd.save()
76     if bd.rcs.name is not "None":
77         print "Using %s for revision control." % bd.rcs.name
78     else:
79         print "No revision control detected."
80     print "Directory initialized."
81
82 def get_parser():
83     parser = cmdutil.CmdOptionParser("be init [DIRECTORY]")
84     return parser
85
86 longhelp="""
87 This command initializes Bugs Everywhere support for the specified directory
88 and all its subdirectories.  It will auto-detect any supported revision control
89 system.  You can use "be set rcs_name" to change the rcs being used.
90
91 The directory defaults to your current working directory.
92
93 It is usually a good idea to put the Bugs Everywhere root at the source code
94 root, but you can put it anywhere.  If you run "be init" in a subdirectory,
95 then only bugs created in that subdirectory (and its children) will appear
96 there.
97 """
98
99 def help():
100     return get_parser().help_str() + longhelp