Merge lp:~renamer-developers/renamer/900657-unicode-templates into lp:renamer

Proposed by Jonathan Jacobs
Status: Merged
Approved by: Jonathan Jacobs
Approved revision: 90
Merged at revision: 90
Proposed branch: lp:~renamer-developers/renamer/900657-unicode-templates
Merge into: lp:renamer
Diff against target: 93 lines (+55/-9)
2 files modified
renamer/application.py (+17/-9)
renamer/test/test_application.py (+38/-0)
To merge this branch: bzr merge lp:~renamer-developers/renamer/900657-unicode-templates
Reviewer Review Type Date Requested Status
Renamer developers Pending
Review via email: mp+84583@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'renamer/application.py'
2--- renamer/application.py 2011-09-12 21:12:16 +0000
3+++ renamer/application.py 2011-12-06 09:20:31 +0000
4@@ -30,10 +30,6 @@
5 optParameters = [
6 ('config', 'c', '~/.renamer/renamer.conf',
7 'Configuration file path.'),
8- ('name', 'e', None,
9- 'Formatted filename.', string.Template),
10- ('prefix', 'p', None,
11- 'Formatted path to prefix to files before renaming.', string.Template),
12 ('concurrency', 'l', 10,
13 'Maximum number of asynchronous tasks to perform concurrently.', int)]
14
15@@ -56,6 +52,7 @@
16 def __init__(self, config):
17 super(Options, self).__init__()
18 self['verbosity'] = 1
19+ self['name'] = self['prefix'] = None
20 self.config = config
21
22
23@@ -65,11 +62,22 @@
24 os.path.basename(sys.argv[0]),)
25
26
27- def postOptions(self):
28- if self['name'] is not None:
29- self['name'] = self.decodeCommandLine(self['name'])
30- if self['prefix'] is not None:
31- self['prefix'] = self.decodeCommandLine(self['prefix'])
32+ def opt_name(self, option):
33+ """
34+ Formatted filename.
35+ """
36+ self['name'] = string.Template(self.decodeCommandLine(option))
37+
38+ opt_e = opt_name
39+
40+
41+ def opt_prefix(self, option):
42+ """
43+ Formatted path to prefix to files before renaming.
44+ """
45+ self['prefix'] = string.Template(self.decodeCommandLine(option))
46+
47+ opt_p = opt_prefix
48
49
50 def opt_verbose(self):
51
52=== added file 'renamer/test/test_application.py'
53--- renamer/test/test_application.py 1970-01-01 00:00:00 +0000
54+++ renamer/test/test_application.py 2011-12-06 09:20:31 +0000
55@@ -0,0 +1,38 @@
56+import string
57+
58+from twisted.python.filepath import FilePath
59+from twisted.trial.unittest import TestCase
60+
61+from renamer import config
62+from renamer.application import Options
63+
64+
65+
66+class OptionsTests(TestCase):
67+ """
68+ Tests for L{renamer.application.Options}.
69+ """
70+ def setUp(self):
71+ path = FilePath(__file__).sibling('data').child('test.conf')
72+ self.config = config.ConfigFile(path)
73+ self.options = Options(self.config)
74+
75+
76+ def test_parsePrefix(self):
77+ """
78+ Prefix options are decoded to C{unicode} before being wrapped in
79+ C{string.Template}.
80+ """
81+ self.options.parseOptions(['--prefix=foo'])
82+ self.assertIdentical(string.Template, type(self.options['prefix']))
83+ self.assertIdentical(unicode, type(self.options['prefix'].template))
84+
85+
86+ def test_parseName(self):
87+ """
88+ Name options are decoded to C{unicode} before being wrapped in
89+ C{string.Template}.
90+ """
91+ self.options.parseOptions(['--name=foo'])
92+ self.assertIdentical(string.Template, type(self.options['name']))
93+ self.assertIdentical(unicode, type(self.options['name'].template))

Subscribers

People subscribed via source and target branches