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
=== modified file 'renamer/application.py'
--- renamer/application.py 2011-09-12 21:12:16 +0000
+++ renamer/application.py 2011-12-06 09:20:31 +0000
@@ -30,10 +30,6 @@
30 optParameters = [30 optParameters = [
31 ('config', 'c', '~/.renamer/renamer.conf',31 ('config', 'c', '~/.renamer/renamer.conf',
32 'Configuration file path.'),32 'Configuration file path.'),
33 ('name', 'e', None,
34 'Formatted filename.', string.Template),
35 ('prefix', 'p', None,
36 'Formatted path to prefix to files before renaming.', string.Template),
37 ('concurrency', 'l', 10,33 ('concurrency', 'l', 10,
38 'Maximum number of asynchronous tasks to perform concurrently.', int)]34 'Maximum number of asynchronous tasks to perform concurrently.', int)]
3935
@@ -56,6 +52,7 @@
56 def __init__(self, config):52 def __init__(self, config):
57 super(Options, self).__init__()53 super(Options, self).__init__()
58 self['verbosity'] = 154 self['verbosity'] = 1
55 self['name'] = self['prefix'] = None
59 self.config = config56 self.config = config
6057
6158
@@ -65,11 +62,22 @@
65 os.path.basename(sys.argv[0]),)62 os.path.basename(sys.argv[0]),)
6663
6764
68 def postOptions(self):65 def opt_name(self, option):
69 if self['name'] is not None:66 """
70 self['name'] = self.decodeCommandLine(self['name'])67 Formatted filename.
71 if self['prefix'] is not None:68 """
72 self['prefix'] = self.decodeCommandLine(self['prefix'])69 self['name'] = string.Template(self.decodeCommandLine(option))
70
71 opt_e = opt_name
72
73
74 def opt_prefix(self, option):
75 """
76 Formatted path to prefix to files before renaming.
77 """
78 self['prefix'] = string.Template(self.decodeCommandLine(option))
79
80 opt_p = opt_prefix
7381
7482
75 def opt_verbose(self):83 def opt_verbose(self):
7684
=== added file 'renamer/test/test_application.py'
--- renamer/test/test_application.py 1970-01-01 00:00:00 +0000
+++ renamer/test/test_application.py 2011-12-06 09:20:31 +0000
@@ -0,0 +1,38 @@
1import string
2
3from twisted.python.filepath import FilePath
4from twisted.trial.unittest import TestCase
5
6from renamer import config
7from renamer.application import Options
8
9
10
11class OptionsTests(TestCase):
12 """
13 Tests for L{renamer.application.Options}.
14 """
15 def setUp(self):
16 path = FilePath(__file__).sibling('data').child('test.conf')
17 self.config = config.ConfigFile(path)
18 self.options = Options(self.config)
19
20
21 def test_parsePrefix(self):
22 """
23 Prefix options are decoded to C{unicode} before being wrapped in
24 C{string.Template}.
25 """
26 self.options.parseOptions(['--prefix=foo'])
27 self.assertIdentical(string.Template, type(self.options['prefix']))
28 self.assertIdentical(unicode, type(self.options['prefix'].template))
29
30
31 def test_parseName(self):
32 """
33 Name options are decoded to C{unicode} before being wrapped in
34 C{string.Template}.
35 """
36 self.options.parseOptions(['--name=foo'])
37 self.assertIdentical(string.Template, type(self.options['name']))
38 self.assertIdentical(unicode, type(self.options['name'].template))

Subscribers

People subscribed via source and target branches