1
# Copyright (C) 2004 Aaron Bentley
2
# <aaron.bentley@utoronto.ca>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#ensure that the parent directory is in the path (for epydoc)
22
sys.path=[os.path.realpath(os.path.dirname(__file__)+"/..")]+sys.path
29
__docformat__ = "restructuredtext"
30
__doc__ = "command template"
32
class SnapConfig(commands.BaseCommand):
33
"""Generates a config using the current tree root"""
35
self.description = self.__doc__
37
# override get_completer if you want custom completion
38
# def get_completer(self, arg, index):
39
# return cmdutil.iter_dir_completions(arg)
40
def get_tree_pairs(self, dir, show_revision=True):
41
root = arch.tree_root(dir)
43
ver_or_rev = str(pylon.tree_latest(root))
45
ver_or_rev = str(root.tree_version)
47
if dir_string is not None:
48
tree_pairs = [(dir_string, ver_or_rev)]
55
for child_dir in pylon.iter_inventory_filter(None, dir_spec,
57
categories=(pylon.TreeRootFile,)):
58
tree_pairs.extend(self.get_tree_pairs(child_dir.name,
62
def do_command(self, cmdargs):
63
parser=self.get_parser()
64
(options, args) = parser.parse_args(cmdargs)
68
tree_pairs = self.get_tree_pairs(None,
69
show_revision=options.revisions)
71
for dir_string, ver_or_rev in tree_pairs:
72
if len(dir_string) > max_len:
73
max_len = len(dir_string)
74
for dir_string, ver_or_rev in tree_pairs:
75
numtabs=(max_len - len(dir_string)+7)/8+1
77
for i in range(numtabs):
79
print "./%s%s%s" % (dir_string, tabs, ver_or_rev)
83
parser = cmdutil.CmdOptionParser("snap-config [options]")
84
parser.add_option("--revisions", action="store_true", dest="revisions",
85
help="Use full revisions, not versions")
88
def help(self, parser=None):
90
Prints a help message.
92
:param parser: If supplied, the parser to use for generating help. If \
93
not supplied, it is retrieved.
94
:type parser: cmdutil.CmdOptionParser
97
parser=self.get_parser()
100
Verbose help text goes here.
104
#This function assigns the command class to a user command name
105
def add_command(commands):
106
commands["snap-config"] = SnapConfig
108
# arch-tag: 83934814-b626-4653-9874-520abef4642e