147.1.3
by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded |
1 |
# Copyright (C) 2004 Aaron Bentley
|
2 |
# <aaron.bentley@utoronto.ca>
|
|
3 |
#
|
|
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.
|
|
8 |
#
|
|
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.
|
|
13 |
#
|
|
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
|
|
17 |
||
18 |
import sys |
|
19 |
import os |
|
20 |
||
21 |
#ensure that the parent directory is in the path (for epydoc)
|
|
22 |
sys.path=[os.path.realpath(os.path.dirname(__file__)+"/..")]+sys.path |
|
23 |
||
24 |
import commands |
|
25 |
import cmdutil |
|
26 |
import arch |
|
27 |
import pylon |
|
28 |
||
29 |
__docformat__ = "restructuredtext" |
|
30 |
__doc__ = "command template" |
|
31 |
||
32 |
class SnapConfig(commands.BaseCommand): |
|
33 |
"""Generates a config using the current tree root"""
|
|
34 |
def __init__(self): |
|
35 |
self.description = self.__doc__ |
|
36 |
||
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) |
|
42 |
if show_revision: |
|
43 |
ver_or_rev = str(pylon.tree_latest(root)) |
|
44 |
else: |
|
45 |
ver_or_rev = str(root.tree_version) |
|
46 |
dir_string = dir |
|
47 |
if dir_string is not None: |
|
48 |
tree_pairs = [(dir_string, ver_or_rev)] |
|
49 |
else: |
|
50 |
tree_pairs = [] |
|
51 |
if dir is not None: |
|
52 |
dir_spec = (dir,) |
|
53 |
else: |
|
54 |
dir_spec = None |
|
55 |
for child_dir in pylon.iter_inventory_filter(None, dir_spec, |
|
56 |
control_files=True, |
|
57 |
categories=(pylon.TreeRootFile,)): |
|
58 |
tree_pairs.extend(self.get_tree_pairs(child_dir.name, |
|
59 |
show_revision)) |
|
60 |
return tree_pairs |
|
61 |
||
62 |
def do_command(self, cmdargs): |
|
63 |
parser=self.get_parser() |
|
64 |
(options, args) = parser.parse_args(cmdargs) |
|
65 |
||
66 |
if len(args) !=0: |
|
67 |
raise errors.GetHelp |
|
68 |
tree_pairs = self.get_tree_pairs(None, |
|
69 |
show_revision=options.revisions) |
|
70 |
max_len = 0 |
|
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 |
|
76 |
tabs = "" |
|
77 |
for i in range(numtabs): |
|
78 |
tabs+="\t" |
|
79 |
print "./%s%s%s" % (dir_string, tabs, ver_or_rev) |
|
80 |
return 0 |
|
81 |
||
82 |
def get_parser(self): |
|
83 |
parser = cmdutil.CmdOptionParser("snap-config [options]") |
|
84 |
parser.add_option("--revisions", action="store_true", dest="revisions", |
|
85 |
help="Use full revisions, not versions") |
|
86 |
return parser |
|
87 |
||
88 |
def help(self, parser=None): |
|
89 |
"""
|
|
90 |
Prints a help message.
|
|
91 |
||
92 |
:param parser: If supplied, the parser to use for generating help. If \
|
|
93 |
not supplied, it is retrieved.
|
|
94 |
:type parser: cmdutil.CmdOptionParser
|
|
95 |
"""
|
|
96 |
if parser==None: |
|
97 |
parser=self.get_parser() |
|
98 |
parser.print_help() |
|
99 |
print """ |
|
100 |
Verbose help text goes here.
|
|
101 |
"""
|
|
102 |
||
103 |
||
104 |
#This function assigns the command class to a user command name
|
|
105 |
def add_command(commands): |
|
106 |
commands["snap-config"] = SnapConfig |
|
107 |
||
108 |
# arch-tag: 83934814-b626-4653-9874-520abef4642e
|