Merge lp:~mew/config-manager/directories-verbosity into lp:config-manager

Proposed by Matthew Wedgwood
Status: Needs review
Proposed branch: lp:~mew/config-manager/directories-verbosity
Merge into: lp:config-manager
Diff against target: 130 lines (+24/-9)
1 file modified
lib/config_manager/__init__.py (+24/-9)
To merge this branch: bzr merge lp:~mew/config-manager/directories-verbosity
Reviewer Review Type Date Requested Status
Robert Collins Pending
Review via email: mp+170917@code.launchpad.net

Description of the change

Add a "-v" flag for more verbosity about progress.
Add a "(directory)" url syntax to allow creation of empty directories (as is sometimes needed for parents of other trees)

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

Sorry for the (terrible) latency here in replying. Rather than passing verbose about everywhere, what do you think about using python logging and just increasing the logging verbosity?

Unmerged revisions

170. By Matthew Wedgwood

Add verbose option and config syntax for creation of empty directories.

'cm.py -v' will print the path currently being built or updated.
A url of "(directory)" will create an empty directory at the specified path.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/config_manager/__init__.py'
2--- lib/config_manager/__init__.py 2009-08-29 00:51:24 +0000
3+++ lib/config_manager/__init__.py 2013-06-21 23:03:25 +0000
4@@ -64,14 +64,14 @@
5 assert (entry.path not in self._entries)
6 self._entries[entry.path] = entry
7
8- def build(self, dir):
9+ def build(self, dir, verbose=False):
10 """Perform a build of this config with base dir dir, which must exist
11 already.
12 """
13 to_process = self._entries.items()
14 to_process.sort(key=lambda x:len(x[0]))
15 for path, entry in to_process:
16- entry.build(dir)
17+ entry.build(dir, verbose=verbose)
18
19 def get_entries(self):
20 """Return a diction of ConfigEntries."""
21@@ -81,14 +81,14 @@
22 # internal one though ...
23 return self._entries.copy()
24
25- def update(self, dir):
26+ def update(self, dir, verbose=False):
27 """Perform a update of this config with base dir dir, which must exist
28 already.
29 """
30 to_process = self._entries.items()
31 to_process.sort(key=lambda x:len(x[0]))
32 for path, entry in to_process:
33- entry.update(dir)
34+ entry.update(dir, verbose=verbose)
35
36
37 class ConfigEntry(object):
38@@ -210,6 +210,12 @@
39 # bare except because I havn't tested a bad url yet.
40 return False
41
42+ def _build_dir_url(self, path):
43+ if self.url == "(directory)":
44+ os.mkdir(os.path.join(path, self.path))
45+ return True
46+ return False
47+
48 def get_implementations(self):
49 """Get the implementations represented by the url in this entry."""
50 for scheme, implementations in \
51@@ -245,7 +251,7 @@
52 raise RuntimeError("Failed to update.")
53 return False
54
55- def build(self, path):
56+ def build(self, path, verbose=False):
57 """Build this element from root path."""
58 ## FIXME: the C++ version uses a ConfigSource to abstract out
59 ## the url types, we should do that once we have a couple of
60@@ -254,6 +260,8 @@
61 if not os.path.isdir(os.path.dirname(target)):
62 raise KeyError("Cannot build to target %s"
63 ", its parent does not exists" % target)
64+ if verbose:
65+ print "Building %s" % self.path
66 # protocol specific urls
67 if (self.url.startswith("arch://") or
68 self.url.startswith("fake://")):
69@@ -276,6 +284,8 @@
70 return
71 elif self._build_bzr_url(path):
72 return
73+ elif self._build_dir_url(path):
74+ return
75 else:
76 raise ValueError("unknown url type '%s'" % self.url)
77
78@@ -293,7 +303,7 @@
79 return False
80 return True
81
82- def update(self, path):
83+ def update(self, path, verbose=False):
84 """Update this entry (from root path)."""
85 ## FIXME: the C++ version uses a ConfigSource to abstract out
86 ## the url types, we should do that once we have a couple of
87@@ -303,7 +313,9 @@
88 raise KeyError("Cannot build to target %s"
89 ", its parent does not exists" % target)
90 if not os.path.exists(os.path.join(path, self.path)):
91- return self.build(path)
92+ return self.build(path, verbose=verbose)
93+ if verbose:
94+ print "Updating %s" % self.path
95 # protocol specific urls
96 if self.url.startswith("arch://"):
97 try:
98@@ -335,6 +347,8 @@
99 repo=os.path.dirname(url)
100 print "cd %s && cvs -d %s%s update -Pd" % (self.path, scheme, repo)
101 os.system("cd %s && cvs -d %s%s update -Pd" % (self.path, scheme, repo))
102+ elif self.url == "(directory)":
103+ return
104 # autodetection
105 elif self._update_pybaz(path):
106 return
107@@ -358,6 +372,7 @@
108 def main(argv):
109 """The entry point for main()."""
110 parser = OptionParser(prog="cm")
111+ parser.add_option("-v", action="store_true", default=False)
112 parser.set_arguments(Sequence((CommandArgument(), Optional(UrlArgument()),
113 TerminalElement())))
114 parser.set_usage("cm [options] %s" % parser.arguments.rule())
115@@ -372,7 +387,7 @@
116 stream = urllib.urlopen(args[1])
117 config = Config(fromStream=stream)
118 if args[0] == "build":
119- config.build(os.path.abspath(os.curdir))
120+ config.build(os.path.abspath(os.curdir), verbose=options.v)
121 return 0
122 if args[0] == "show":
123 entries = config.get_entries().items()
124@@ -381,7 +396,7 @@
125 print "%s\t%s" % (path, entry.url)
126 return 0
127 if args[0] == "update":
128- config.update(os.path.abspath(os.curdir))
129+ config.update(os.path.abspath(os.curdir), verbose=options.v)
130 return 0
131
132

Subscribers

People subscribed via source and target branches