summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-11-22 18:21:57 +0200
committerLars Wirzenius <liw@liw.fi>2014-11-22 18:21:57 +0200
commit70608dbf368a54be4d40c8e3fe6bfa179dd6e12f (patch)
tree86d7930952b74011a1c477d90e32016b2dfefb1c
parentc53a50f3a219d3667af0a8636d180c1efc3cd265 (diff)
downloadjt-70608dbf368a54be4d40c8e3fe6bfa179dd6e12f.tar.gz
Move command new-person to a separate class
-rwxr-xr-xjt61
1 files changed, 34 insertions, 27 deletions
diff --git a/jt b/jt
index 3e78621..74673be 100755
--- a/jt
+++ b/jt
@@ -157,6 +157,39 @@ class FinishCommand(Command):
cwd=self._app.settings['source'])
+class NewPersonCommand(Command):
+
+ def run(self, args):
+ if len(args) != 1:
+ raise cliapp.AppException(
+ 'Need the name of a person (in Last, First form)')
+
+ def normalise(name):
+ s = name.lower()
+ s = ' '.join(s.split(','))
+ s = '.'.join(s.split())
+ return s
+
+ name = args[0]
+ basename = normalise(name)
+ pathname = os.path.join(
+ self._app.settings['source'], 'people', basename + '.mdwn')
+
+ if os.path.exists(pathname):
+ raise cliapp.AppException('File %s already exists' % pathname)
+
+ with open(pathname, 'w') as f:
+ f.write('''\
+[[!meta title="%(name)s"]]
+
+[[!inline archive=yes pages="link(.)"]]
+''' %
+ {
+ 'name': name,
+ 'basename': basename,
+ })
+
+
class JournalTool(cliapp.Application):
cmd_synopsis = {
@@ -312,33 +345,7 @@ class JournalTool(cliapp.Application):
'''
- if len(args) != 1:
- raise cliapp.AppException(
- 'Need the name of a person (in Last, First form)')
-
- def normalise(name):
- s = name.lower()
- s = ' '.join(s.split(','))
- s = '.'.join(s.split())
- return s
-
- name = args[0]
- basename = normalise(name)
- pathname = os.path.join(
- self.settings['source'], 'people', basename + '.mdwn')
-
- if os.path.exists(pathname):
- raise cliapp.AppException('File %s already exists' % pathname)
-
- with open(pathname, 'w') as f:
- f.write('''\
-[[!meta title="%(name)s"]]
+ NewPersonCommand(self).run(args)
-[[!inline archive=yes pages="link(.)"]]
-''' %
- {
- 'name': name,
- 'basename': basename,
- })
JournalTool(version=__version__).run()