Merge lp:~johnf-inodes/autoppa/version_template into lp:autoppa
- version_template
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | not available | ||||
Proposed branch: | lp:~johnf-inodes/autoppa/version_template | ||||
Merge into: | lp:autoppa | ||||
Diff against target: |
446 lines 8 files modified
README (+25/-1) autoppa/application.py (+16/-5) autoppa/commands.py (+6/-2) autoppa/configuration.py (+4/-3) autoppa/help_topics.py (+43/-0) autoppa/target.py (+30/-13) autoppa/tests/test_configuration.py (+2/-0) autoppa/tests/test_target.py (+29/-5) |
||||
To merge this branch: | bzr merge lp:~johnf-inodes/autoppa/version_template | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jamu Kakar | Approve | ||
John Ferlito (community) | Abstain | ||
Review via email:
|
Commit message
Description of the change
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
John Ferlito (johnf-inodes) wrote : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
John Ferlito (johnf-inodes) wrote : | # |
Not 100% happy with the template variables but I couldn't come up with anything better.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
John Ferlito (johnf-inodes) wrote : | # |
Not 100% happy with the template variables but I couldn't come up with anything better.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
John Ferlito (johnf-inodes) wrote : | # |
Not 100% happy with the template variables but I couldn't come up with anything better.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Jamu Kakar (jkakar) wrote : | # |
[1]
+ file = open(filename, "r")
+ try:
+ expected = "version = 'AUTOPPA_
+ self.assertEqua
+ finally:
+ file.close()
+ self.builder.
The try/finally isn't really necessary here. If it leaks, the file
will be closed when it gets garbage collected. Also, the final line
isn't necessary since self.builder is created afresh for each test
case.
[2]
+ def _get_version(self, release_name):
+
+ version = self.version_
+ version = re.sub(
+ version = re.sub(
+ version = re.sub(
+
+ return version
The standard library provides builtin string template interpolation
functionality that will simplify this a bit:
def _get_version(self, release_name):
data = {"version": self.version, "release_name": release_name,
return version_
You'll need to add the following import:
from string import Template
[3]
What do you think about expanding the version variables to include
everything in this list:
version 'version' in the diff
revision The revision of the source branch
dist_codename 'release_name' in the diff
dist_version 'release_number' in the diff
now The current time in UTC formatted as YYYYMMDDHHMMSS
today Today's date formatted as YYYYMMDD
user The name from the USER environment variable
Is there anything else that should be included?
[4]
+version_template = ${version}
+${version} - The version passed on the command line
+${release_number} - 6.04, 6.10, etc
+${release_name} - dapper, gutsy, etc
'codename' should be 'release_name' above, in the README.
[5]
It'd be cool to add a help topic describing the functionality. If
you look at autoppa.help_topics you'll see an example of a topic.
If you implement a class following the same pattern called
topic_version_
you see when you run 'bin/autoppa help topics' and can be viewed by
running 'bin/autoppa help version-templates'.
[6]
+ build_target = self._configura
+ if "version_template" not in build_target:
+ build_target[
+ return build_target
I think this logic is a bit dangerous, because it will end up
injecting data into user configuration that wasn't actually provided
by the user. I recommend you revert this change and deal with the
default version template in autoppa.
definition of DEFAULT_
+ version_template = version_template or data["version_
Then the above line in AutoPPA.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
John Ferlito (johnf-inodes) wrote : | # |
On Thu, Oct 22, 2009 at 07:03:12PM -0000, Jamu Kakar wrote:
> Review: Needs Fixing
> [1]
>
> + file = open(filename, "r")
> + try:
> + expected = "version = 'AUTOPPA_
> + self.assertEqua
> + finally:
> + file.close()
> + self.builder.
>
> The try/finally isn't really necessary here. If it leaks, the file
> will be closed when it gets garbage collected. Also, the final line
> isn't necessary since self.builder is created afresh for each test
> case.
OK. I'll fix that up. I pretty much copied this test case from the
one above which does something similar.
> [2]
>
> + def _get_version(self, release_name):
> +
> + version = self.version_
> + version = re.sub(
> + version = re.sub(
> + version = re.sub(
> +
> + return version
>
> The standard library provides builtin string template interpolation
> functionality that will simplify this a bit:
>
> def _get_version(self, release_name):
> version_template = Template(
> release_number = self._get_
> data = {"version": self.version, "release_name": release_name,
> "release_number": release_number}
> return version_
>
> You'll need to add the following import:
>
> from string import Template
Ahh that is very cool. Much more elegant. Thanks!
> [3]
>
> What do you think about expanding the version variables to include
> everything in this list:
>
> version 'version' in the diff
> revision The revision of the source branch
> dist_codename 'release_name' in the diff
> dist_version 'release_number' in the diff
> now The current time in UTC formatted as YYYYMMDDHHMMSS
> today Today's date formatted as YYYYMMDD
> user The name from the USER environment variable
>
> Is there anything else that should be included?
Can't think of anything else right now.
There are a couple of TODOs and FIXMEs regarding this change.
Testing ${revision} is painful since FakeExpect doesn't deal with
grabbing output. I'll implement it after I redo the bzrlib stuff since
then we shouldn't need expect any more.
Also I'm not sure how to stub/mock time and date so that we can test
$today so I left it out for now.
> [4]
>
> +version_template = ${version}
>
> +${version} - The version passed on the command line
> +${release_number} - 6.04, 6.10, etc
> +${release_name} - dapper, gutsy, etc
>
> 'codename' should be 'release_name' above, in the README.
Done.
> [5]
>
> It'd be cool to add a help topic describing the functionality. If
> you look at autoppa.help_topics you'll see an example of a topic.
> If you implement a class following the same pattern called
> topic_version_
> you see when you r...
- 31. By John Ferlito
-
Use string template
- 32. By John Ferlito
-
Move default version template
- 33. By John Ferlito
-
Add extra substitutions to version_template
- 34. By John Ferlito
-
Add a help topic for version templates
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
John Ferlito (johnf-inodes) wrote : | # |
OK. All those changes have been pushed
- 35. By John Ferlito
-
merge in trunk
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Jamu Kakar (jkakar) wrote : | # |
[9]
+ def _get_revno(self):
+ # FIXME Can't use this until we move to using bzrlib
+ # directly as it causes to much hassle with FakeExpect
+ revno = self.expect.
+ logfile=file,
+ timeout=None)
+ print revno
+ return revno
I would remove this. We can add it when its necessary. Thanks for
adding the TODO about it in _get_version.
[10]
+ "now": time.strftime(
+ "today": datetime.
These should be changed to:
now = datetime.utcnow()
...
"now": now.strftime(
[11]
I have a test failure:
[FAIL]: autoppa.
Traceback (most recent call last):
File "/usr/lib/
testMethod()
File "/home/
self.
exceptions.
Looking great, +1 considering these comments. Have you had a chance
to sign the Canonical contributor agreement yet?
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
John Ferlito (johnf-inodes) wrote : | # |
On Wed, Oct 28, 2009 at 04:36:59AM -0000, Jamu Kakar wrote:
> Review: Approve
> [9]
>
> + def _get_revno(self):
> + # FIXME Can't use this until we move to using bzrlib
> + # directly as it causes to much hassle with FakeExpect
> + revno = self.expect.
> + logfile=file,
> + timeout=None)
> + print revno
> + return revno
>
> I would remove this. We can add it when its necessary. Thanks for
> adding the TODO about it in _get_version.
Done.
>
>
> [10]
>
> + "now": time.strftime(
> + "today": datetime.
>
> These should be changed to:
>
> now = datetime.utcnow()
> ...
> "now": now.strftime(
> "today": now.strftime(
>
>
> [11]
Done, with changes in next comment.
> I have a test failure:
>
> [FAIL]: autoppa.
>
> Traceback (most recent call last):
> File "/usr/lib/
> testMethod()
> File "/home/
> self.assertEqua
> exceptions.
Fixed. It was because it was a different day. I noticed you had some
datetime_factory code in there. I've moved that up into the
BuildTarget itself so that all date related code has access to it.
> Looking great, +1 considering these comments. Have you had a chance
> to sign the Canonical contributor agreement yet?
Yes, you should have been CC'd on the email.
- 36. By John Ferlito
-
* Remove unused _get_revision code
* Use UTC time for ${now} and ${today}
* Add a datetime_factory to BuildTarget so we can test date stuff properly.
Preview Diff
1 | === modified file 'README' |
2 | --- README 2009-09-21 03:13:54 +0000 |
3 | +++ README 2009-10-28 06:25:19 +0000 |
4 | @@ -105,7 +105,7 @@ |
5 | |
6 | AutoPPA automatically inserts a release version into package version |
7 | numbers. The conventions specified by Ubuntu's SRU [1] policy |
8 | -should be followed when generating version numbers. In the above |
9 | +are followed by default when generating version numbers. In the above |
10 | example, the smart-0.51-landscape12 would build packages with the |
11 | following versions: |
12 | |
13 | @@ -114,6 +114,30 @@ |
14 | 0.51-landscape12.7.04 |
15 | 0.51-landscape12.7.10 |
16 | |
17 | +A version_template configuration can be set in the autoppa configuration file |
18 | +or on the command line using the --version-template flag. For example: |
19 | + |
20 | +[landscape-client] |
21 | +version_template = ${version}~ppa1~${dist_codename} |
22 | + |
23 | +would produce: |
24 | + |
25 | +0.51-landscape12~ppa1~dapper |
26 | +0.51-landscape12~ppa1~edgy |
27 | +0.51-landscape12~ppa1~feisty |
28 | +0.51-landscape12~ppa1~gutsy |
29 | + |
30 | +The following environment variables are available: |
31 | + |
32 | +${version} - The version passed on the command line |
33 | +${revision} - The revision of the source branch |
34 | +${dist_codename} - dapper, gutsy, etc |
35 | +${dist_version} - 6.04, 6.10, etc |
36 | +${now} - The current time in UTC formatted as YYYYMMDDHHMMSS |
37 | +${today} - Today's date formatted as YYYYMMDD |
38 | +${user} - The name from the USER environment variable |
39 | + |
40 | + |
41 | [1] https://wiki.ubuntu.com/MOTU/SRU |
42 | |
43 | |
44 | |
45 | === modified file 'autoppa/application.py' |
46 | --- autoppa/application.py 2009-09-21 01:35:24 +0000 |
47 | +++ autoppa/application.py 2009-10-28 06:25:19 +0000 |
48 | @@ -23,6 +23,9 @@ |
49 | from autoppa.errors import BuildTargetError |
50 | from autoppa.target import BuildTarget |
51 | |
52 | +from autoppa import configuration |
53 | + |
54 | +DEFAULT_VERSION_TEMPLATE = "${version}.${dist_version}" |
55 | |
56 | class AutoPPA(object): |
57 | |
58 | @@ -36,7 +39,7 @@ |
59 | self.log_file.write("%s\n" % (message,)) |
60 | |
61 | def build(self, build_target, version, no_upload=None, no_merge=None, |
62 | - no_tag=None, no_cleanup=None): |
63 | + no_tag=None, no_cleanup=None, version_template=None): |
64 | """Process sources for C{built_target} using the current settings. |
65 | |
66 | @param build_target: The target to build. This should correspond to |
67 | @@ -44,7 +47,7 @@ |
68 | @param version: The version to for the new build. |
69 | """ |
70 | self._log_info("AutoPPA %s" % (VERSION,)) |
71 | - build_target = self._create_build_target(build_target, version) |
72 | + build_target = self._create_build_target(build_target, version, version_template) |
73 | build_target.prepare_changelog() |
74 | build_target.prepare_working_tree() |
75 | for release in build_target.releases: |
76 | @@ -66,17 +69,20 @@ |
77 | """Switch files to use a version and Ubuntu code name.""" |
78 | build_target = BuildTarget("unused-name", version, "unused@email", |
79 | "unused-branch", "unused-repository", |
80 | - "unused-ppa", [code_name]) |
81 | + "unused-ppa", [code_name], |
82 | + DEFAULT_VERSION_TEMPLATE) |
83 | build_target.working_tree = path |
84 | build_target._prepare_custom_autoppa_files(code_name) |
85 | build_target._prepare_custom_autoppa_version(code_name) |
86 | |
87 | - def _create_build_target(self, build_target, version, expect=pexpect): |
88 | + def _create_build_target(self, build_target, version, version_template, |
89 | + expect=pexpect): |
90 | """Create a L{BuildTarget} instance for C{build_target}. |
91 | |
92 | @param build_target: The target to build. This should correspond to |
93 | the name of the Debian source package being built. |
94 | @param version: The version to for the new build. |
95 | + @param version_template: The template to use to create the version. |
96 | @param expect: Optionally, a L{pexpect} like object. Defaults to |
97 | L{pexpect}. |
98 | @raises BuildTargetError: Raised when a build target is specified that |
99 | @@ -88,10 +94,15 @@ |
100 | if not data: |
101 | raise BuildTargetError("'%s' is not a known build target." |
102 | % build_target) |
103 | + if version_template is None: |
104 | + version_template = data.get("version_template", |
105 | + DEFAULT_VERSION_TEMPLATE) |
106 | + |
107 | builder = BuildTarget(build_target, version, data["email"], |
108 | data["branch"], data["repository"], |
109 | data["ppa"], data["releases"].split(), |
110 | - expect=expect, log_file=self.log_file) |
111 | + version_template, expect=expect, |
112 | + log_file=self.log_file) |
113 | if "options" in data: |
114 | options = set(data["options"].split()) |
115 | if "no-version-replacement" in options: |
116 | |
117 | === modified file 'autoppa/commands.py' |
118 | --- autoppa/commands.py 2009-09-21 01:20:28 +0000 |
119 | +++ autoppa/commands.py 2009-10-28 06:25:19 +0000 |
120 | @@ -46,10 +46,13 @@ |
121 | Option("no-cleanup", |
122 | help="Don't automatically cleanup signed sources and the " |
123 | "release branch created during a build."), |
124 | + Option("version-template", type=str, |
125 | + help="The version template to use when creating the version " |
126 | + "for each PPA."), |
127 | ] |
128 | |
129 | def run(self, build_target, version, config=None, log=None, no_upload=None, |
130 | - no_merge=None, no_tag=None, no_cleanup=None): |
131 | + no_merge=None, no_tag=None, no_cleanup=None, version_template=None): |
132 | """Run command.""" |
133 | if not config: |
134 | config = os.path.join(os.environ["HOME"], ".autoppa.conf") |
135 | @@ -57,7 +60,8 @@ |
136 | log_file = get_log_file(log, self.outf) |
137 | autoppa = AutoPPA(configuration, log_file) |
138 | autoppa.build(build_target, version, no_upload=no_upload, |
139 | - no_merge=no_merge, no_tag=no_tag, no_cleanup=no_cleanup) |
140 | + no_merge=no_merge, no_tag=no_tag, no_cleanup=no_cleanup, |
141 | + version_template=version_template) |
142 | |
143 | |
144 | class cmd_switch(Command): |
145 | |
146 | === modified file 'autoppa/configuration.py' |
147 | --- autoppa/configuration.py 2009-10-21 22:40:23 +0000 |
148 | +++ autoppa/configuration.py 2009-10-28 06:25:19 +0000 |
149 | @@ -21,7 +21,6 @@ |
150 | |
151 | from autoppa.lib.configobj import ConfigObj |
152 | |
153 | - |
154 | class Configuration(object): |
155 | """Get configuration details for named build targets. |
156 | |
157 | @@ -63,6 +62,7 @@ |
158 | repository = /home/jkakar/src/canonical/landscape-client |
159 | ppa = landscape-client-ppa |
160 | releases = dapper edgy feisty gutsy |
161 | + version_template = ~${release_name} |
162 | |
163 | [smart] |
164 | email = Jamshed Kakar <jamshed.kakar@canonical.com> |
165 | @@ -71,7 +71,7 @@ |
166 | ppa = landscape-client-ppa |
167 | releases = dapper edgy feisty gutsy |
168 | """ |
169 | - |
170 | + |
171 | def __init__(self, configuration): |
172 | self._configuration = configuration |
173 | |
174 | @@ -93,7 +93,8 @@ |
175 | def get_build_target(self, build_target): |
176 | """Get a C{dict}-like object with data related to C{build_target}.""" |
177 | try: |
178 | - return self._configuration[build_target] |
179 | + build_target = self._configuration[build_target] |
180 | + return build_target |
181 | except KeyError: |
182 | pass |
183 | return None |
184 | |
185 | === modified file 'autoppa/help_topics.py' |
186 | --- autoppa/help_topics.py 2009-09-21 03:13:54 +0000 |
187 | +++ autoppa/help_topics.py 2009-10-28 06:25:19 +0000 |
188 | @@ -59,3 +59,46 @@ |
189 | |
190 | options = no-version-replacement |
191 | """ |
192 | + |
193 | +class topic_version_template(DocstringHelpTopic): |
194 | + """Information about version templating functionality. |
195 | + |
196 | + AutoPPA automatically inserts a release version into package version |
197 | + numbers. The conventions specified by Ubuntu's SRU [1] policy |
198 | + are followed by default when generating version numbers. For example |
199 | + if you built a package which had a version of 0.51-landscape12, then you |
200 | + would get the following versions for each release: |
201 | + |
202 | + 0.51-landscape12.6.06 |
203 | + 0.51-landscape12.6.10 |
204 | + 0.51-landscape12.7.04 |
205 | + 0.51-landscape12.7.10 |
206 | + |
207 | + A version_template configuration can be set in the autoppa configuration |
208 | + file or on the command line using the --version-template flag. For example |
209 | + you could add the following to the configuration file for the |
210 | + landscape-client package: |
211 | + |
212 | + [landscape-client] |
213 | + version_template = ${version}~ppa1~${dist_codename} |
214 | + |
215 | + This would produce versions like: |
216 | + |
217 | + 0.51-landscape12~ppa1~dapper |
218 | + 0.51-landscape12~ppa1~edgy |
219 | + 0.51-landscape12~ppa1~feisty |
220 | + 0.51-landscape12~ppa1~gutsy |
221 | + |
222 | + The following environment variables are available: |
223 | + |
224 | + ${version} - The version passed on the command line |
225 | + ${revision} - The revision of the source branch |
226 | + ${dist_codename} - dapper, gutsy, etc |
227 | + ${dist_version} - 6.04, 6.10, etc |
228 | + ${now} - The current time in UTC formatted as YYYYMMDDHHMMSS |
229 | + ${today} - Today's date formatted as YYYYMMDD |
230 | + ${user} - The name from the USER environment variable |
231 | + |
232 | + |
233 | + [1] https://wiki.ubuntu.com/MOTU/SRU |
234 | + """ |
235 | |
236 | === modified file 'autoppa/target.py' |
237 | --- autoppa/target.py 2009-10-22 18:06:19 +0000 |
238 | +++ autoppa/target.py 2009-10-28 06:25:19 +0000 |
239 | @@ -18,10 +18,12 @@ |
240 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
241 | |
242 | from datetime import datetime |
243 | +import time |
244 | import tempfile |
245 | import os |
246 | |
247 | import pexpect |
248 | +from string import Template |
249 | |
250 | from autoppa.errors import ChangelogError, EditorError |
251 | from autoppa.file import ReleaseSpecificInclude, VersionReplacement |
252 | @@ -41,7 +43,8 @@ |
253 | """ |
254 | |
255 | def __init__(self, name, version, email, branch, repository, ppa, releases, |
256 | - expect=pexpect, system=os.system, log_file=None): |
257 | + version_template, expect=pexpect, system=os.system, |
258 | + datetime_factory=None, log_file=None): |
259 | """ |
260 | @param name: The package name. Note that multiple .deb files may be |
261 | produced for this package. |
262 | @@ -56,10 +59,14 @@ |
263 | @param ppa: The name of the PPA to use, as defined in C{~/.dput.cf}. |
264 | @param releases: A list of Ubuntu releases, such as |
265 | C{['hardy', 'karmic']}. |
266 | + @param version_template: A template for adding PPA sepecific version. |
267 | @param expect: Optionally, a L{pexpect}-like object. Defaults to |
268 | L{pexpect}. |
269 | @param system: Optionally, an L{os.system}-like function. Defaults to |
270 | L{os.system}. |
271 | + @param datetime_factory: Optionally, an object that yields a datetime |
272 | + instance to use as the changelog time. Defaults to |
273 | + C{datetime.utcnow}. |
274 | @param log_file: Optionally, a stream to write log output to. |
275 | """ |
276 | self.name = name |
277 | @@ -69,11 +76,13 @@ |
278 | self.repository = repository |
279 | self.ppa = ppa |
280 | self.releases = releases |
281 | + self.version_template = version_template |
282 | self.working_tree = None |
283 | self.changelog = None |
284 | self.log_file = log_file |
285 | self.expect = expect |
286 | self.system = system |
287 | + self.datetime_factory = datetime_factory or datetime.utcnow() |
288 | self.version_replacement = True |
289 | self._prepared_files = set() |
290 | |
291 | @@ -166,7 +175,7 @@ |
292 | def _get_working_tree(self): |
293 | return "%s_%s" % (self.name, self.version) |
294 | |
295 | - def prepare_custom_files(self, release, datetime_factory=None): |
296 | + def prepare_custom_files(self, release): |
297 | """Prepare the release-specific files for the new release. |
298 | |
299 | Packages often require release-specific content for files such as the |
300 | @@ -187,17 +196,14 @@ |
301 | C{debian/changelog}. A new changelog file is created if necessary. |
302 | |
303 | @param release: The name of the release to prepare package files for. |
304 | - @param datetime_factory: Optionally, an object that yields a datetime |
305 | - instance to use as the changelog time. Defaults to |
306 | C{datetime.utcnow}. |
307 | """ |
308 | self._log_info("== Preparing custom files for %s on %s ==" |
309 | % (self.name, release)) |
310 | - datetime_factory = datetime_factory or datetime.utcnow |
311 | self._prepare_custom_autoppa_files(release) |
312 | if self.version_replacement: |
313 | self._prepare_custom_autoppa_version(release) |
314 | - self._prepare_custom_changelog(release, datetime_factory) |
315 | + self._prepare_custom_changelog(release) |
316 | |
317 | def _prepare_custom_autoppa_files(self, release): |
318 | include = ReleaseSpecificInclude(release) |
319 | @@ -245,12 +251,23 @@ |
320 | "lucid": "10.04"} |
321 | return numbers[release_name] |
322 | |
323 | - def _get_version(self, release): |
324 | - parts = self.version.split("-", 1) |
325 | - return "%s-%s.%s" % (parts[0], parts[1], |
326 | - self._get_release_number(release)) |
327 | - |
328 | - def _prepare_custom_changelog(self, release, datetime_factory): |
329 | + def _get_version(self, release_name): |
330 | + version_template = Template(self.version_template) |
331 | + # TODO Implement revision when we move to bzrlib |
332 | + # "revision": self._get_revno(), |
333 | + |
334 | + data = { |
335 | + "version": self.version, |
336 | + "dist_codename": release_name, |
337 | + "dist_version": self._get_release_number(release_name), |
338 | + "now": self.datetime_factory.strftime("%Y%m%d%H%M%S"), |
339 | + "today": self.datetime_factory.strftime("%Y%m%d"), |
340 | + "user": os.environ["USER"] |
341 | + } |
342 | + |
343 | + return version_template.substitute(data) |
344 | + |
345 | + def _prepare_custom_changelog(self, release): |
346 | try: |
347 | path = os.path.join(self.working_tree, "debian/changelog") |
348 | file = open(path, "r") |
349 | @@ -262,7 +279,7 @@ |
350 | old_changelog = "" |
351 | |
352 | version = self._get_version(release) |
353 | - date = datetime_factory().strftime("%a, %-d %b %Y %H:%M:%S +0000") |
354 | + date = self.datetime_factory.strftime("%a, %-d %b %Y %H:%M:%S +0000") |
355 | changelog = """\ |
356 | %(package)s (%(version)s) %(release)s; urgency=low |
357 | |
358 | |
359 | === modified file 'autoppa/tests/test_configuration.py' |
360 | --- autoppa/tests/test_configuration.py 2009-10-21 22:40:23 +0000 |
361 | +++ autoppa/tests/test_configuration.py 2009-10-28 06:25:19 +0000 |
362 | @@ -57,6 +57,7 @@ |
363 | branch = /home/john/src/supertool/production |
364 | repository = /home/john/src/supertool |
365 | releases = dapper edgy gutsy feisty |
366 | +version-template = ~${release_name}~ppa |
367 | """ |
368 | path = self.fs.make_path(content=content) |
369 | configuration = Configuration.from_file(path) |
370 | @@ -65,6 +66,7 @@ |
371 | self.assertEquals(data["branch"], "/home/john/src/supertool/production") |
372 | self.assertEquals(data["repository"], "/home/john/src/supertool") |
373 | self.assertEquals(data["releases"], "dapper edgy gutsy feisty") |
374 | + self.assertEquals(data["version-template"], "~${release_name}~ppa") |
375 | |
376 | def test_get_missing_build_target(self): |
377 | """ |
378 | |
379 | === modified file 'autoppa/tests/test_target.py' |
380 | --- autoppa/tests/test_target.py 2009-10-21 22:20:53 +0000 |
381 | +++ autoppa/tests/test_target.py 2009-10-28 06:25:19 +0000 |
382 | @@ -33,10 +33,12 @@ |
383 | self.expect = FakeExpect() |
384 | self.fs = FilesystemPath() |
385 | self.branch_path = self.fs.make_dir("production") |
386 | + datetime_factory = datetime(2007, 8, 2, 13, 14, 15) |
387 | self.builder = BuildTarget( |
388 | "supertool", "1.3.11-upside1", "John Smith <john@upside.com>", |
389 | self.branch_path, self.fs.dirname, "supertool-ppa", |
390 | - ["dapper", "edgy", "feisty"], expect=self.expect, |
391 | + ["dapper", "edgy", "feisty"], "${version}.${dist_version}", |
392 | + expect=self.expect, datetime_factory=datetime_factory, |
393 | system=self.expect.run) |
394 | |
395 | def tearDown(self): |
396 | @@ -254,6 +256,30 @@ |
397 | finally: |
398 | file.close() |
399 | |
400 | + def test_prepare_custom_files_with_custom_version_content(self): |
401 | + """ |
402 | + L{BuildTarget.prepare_custom_files} replaces the magic |
403 | + C{AUTOPPA_VERSION()} symbol in lines found in processed files |
404 | + with a custom version template. |
405 | + """ |
406 | + filename = self.fs.make_path(content="version = 'AUTOPPA_VERSION()'", |
407 | + path="debian/version") |
408 | + original_user = os.environ.get("USER") |
409 | + os.environ["USER"] = "user_from_env" |
410 | + try: |
411 | + self.builder.version_template = ("${version}~${dist_codename}~" |
412 | + "${dist_version}~${now}~${today}~${user}") |
413 | + self.builder.working_tree = self.fs.dirname |
414 | + self.builder.prepare_custom_files("dapper") |
415 | + file = open(filename, "r") |
416 | + |
417 | + expected = ("version = 'AUTOPPA_VERSION(1.3.11-upside1~dapper~" |
418 | + "6.06~20070802131415~20070802~user_from_env)'") |
419 | + self.assertEquals(file.read(), expected) |
420 | + file.close() |
421 | + finally: |
422 | + os.environ["USER"] = original_user |
423 | + |
424 | def test_prepare_custom_files_with_version_replacement_suppressed(self): |
425 | """ |
426 | L{BuildTarget.prepare_custom_files} replaces the magic |
427 | @@ -298,8 +324,7 @@ |
428 | self.builder.changelog = " * Supertool runs 3x faster than before!" |
429 | self.builder.working_tree = self.fs.dirname |
430 | self.assertFalse(os.path.exists(changelog_filename)) |
431 | - factory = lambda: datetime(2007, 8, 2, 13, 14, 15) |
432 | - self.builder.prepare_custom_files("dapper", datetime_factory=factory) |
433 | + self.builder.prepare_custom_files("dapper") |
434 | file = open(changelog_filename, "r") |
435 | try: |
436 | changelog = file.read() |
437 | @@ -338,8 +363,7 @@ |
438 | |
439 | self.builder.changelog = " * Supertool runs 3x faster than before!" |
440 | self.builder.working_tree = self.fs.dirname |
441 | - factory = lambda: datetime(2007, 8, 2, 13, 14, 15) |
442 | - self.builder.prepare_custom_files("dapper", datetime_factory=factory) |
443 | + self.builder.prepare_custom_files("dapper") |
444 | file = open(changelog_filename, "r") |
445 | try: |
446 | changelog = file.read() |
Version templates