aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-10-29 16:32:15 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-10-29 16:32:15 +0100
commit30c4ce390a0a2d59431deb7314eadf0f9e845877 (patch)
tree264b00fd4178d14948c5c7a7eb42320599c0e27c
parent7163dfa3d0252067de90e8c088ea90d0b0f7d059 (diff)
Get the collection to work on from the command line
-rwxr-xr-xclesana58
1 files changed, 36 insertions, 22 deletions
diff --git a/clesana b/clesana
index 13c8ba7..4f654fe 100755
--- a/clesana
+++ b/clesana
@@ -1,35 +1,49 @@
#!/usr/bin/env python3
+import argparse
+import os.path
import sys
-import lesana
import cherrypy
+import guacamole
+import lesana
import cherry_lesana as cl
from pkg_resources import resource_filename
-def main():
- # TODO: read config from a file or something
- config = {
- '/': {
- 'tools.staticdir.root': resource_filename(
- 'cherry_lesana',
- 'data',
- )
- },
- '/static': {
- 'tools.staticdir.on': True,
- 'tools.staticdir.dir': 'static',
+class CherryLesana(guacamole.Command):
+ def register_arguments(self, parser):
+ parser.add_argument(
+ '--collection', '-c',
+ help='The collection to work on (default .)',
+ default='.',
+ )
+ parser.add_argument(
+ '--browser', '-b',
+ help='',
+ )
+
+ def invoked(self, ctx):
+ # TODO: read config from a file or something
+ config = {
+ '/': {
+ 'tools.staticdir.root': resource_filename(
+ 'cherry_lesana',
+ 'data',
+ )
+ },
+ '/static': {
+ 'tools.staticdir.on': True,
+ 'tools.staticdir.dir': 'static',
+ }
}
- }
- # TODO: properly read command line args
- try:
- collection = lesana.Collection(sys.argv[1])
- except IndexError:
- collection = None
- app = cl.App(collection)
- cherrypy.quickstart(app, '/', config)
+ if os.path.exists(os.path.join(ctx.args.collection, '.lesana')):
+ collection = lesana.Collection(ctx.args.collection)
+ else:
+ collection = None
+ app = cl.App(collection)
+ cherrypy.quickstart(app, '/', config)
if __name__ == '__main__':
- main()
+ CherryLesana().main()