aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2019-08-11 11:25:44 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2019-08-11 11:25:44 +0200
commit53f116abd38f47ef9f51d2fd0e65515e89c9b9be (patch)
treefd88cef4718d4b2774e672cb8de0b102f2af97a7 /scripts
parentfcd687b5d8abf51fe046b80afe5cd7d15ca880e2 (diff)
Stop using guacamole (no longer in Debian)
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/lesana36
-rwxr-xr-xscripts/tellico2lesana27
2 files changed, 37 insertions, 26 deletions
diff --git a/scripts/lesana b/scripts/lesana
index 02403dc..713f8a7 100755
--- a/scripts/lesana
+++ b/scripts/lesana
@@ -1,21 +1,39 @@
#!/usr/bin/env python3
-import guacamole
+import argparse
+
from lesana.command import New, Edit, Index, Search, Init, Remove
-class Lesana(guacamole.Command):
+class Lesana():
"""
Manage collections
"""
- sub_commands = (
- ('new', New),
- ('edit', Edit),
- ('index', Index),
- ('search', Search),
- ('init', Init),
- ('rm', Remove),
+ commands = (
+ ('new', New()),
+ ('edit', Edit()),
+ ('index', Index()),
+ ('search', Search()),
+ ('init', Init()),
+ ('rm', Remove()),
)
+ def _main(self):
+ self.parser.print_help()
+
+ def main(self):
+ self.parser = argparse.ArgumentParser()
+ self.parser.set_defaults(func=self._main)
+ self.subparsers = self.parser.add_subparsers()
+ for name, sub in self.commands:
+ s_parser = self.subparsers.add_parser(name, help=sub.help)
+ for arg in sub.arguments:
+ s_parser.add_argument(*arg[0], **arg[1])
+ s_parser.set_defaults(func=sub._main)
+ self.args = self.parser.parse_args()
+ self.args.func(self.args)
+
+
+
if __name__ == '__main__':
Lesana().main()
diff --git a/scripts/tellico2lesana b/scripts/tellico2lesana
index 6f9cc5a..0d16ad4 100755
--- a/scripts/tellico2lesana
+++ b/scripts/tellico2lesana
@@ -6,8 +6,6 @@ import zipfile
import lesana
-import guacamole
-
NS = {'tellico': 'http://periapsis.org/tellico/'}
@@ -28,21 +26,19 @@ F_TYPE_MAP = {
}
-class T2L(guacamole.Command):
+class T2L(lesana.command.Command):
"""
Manage collections
"""
-
- def register_arguments(self, parser):
- parser.add_argument(
- '-c', '--collection',
+ arguments = [
+ (['-c', '--collection'], dict(
help='Name of the new lesana collection',
default=None,
- )
- parser.add_argument(
- 'file',
+ )),
+ (['file'], dict(
help='Tellico file to convert to lesana.',
- )
+ )),
+ ]
def read_field_data(self, xfield):
if xfield.tag in self.date_fields:
@@ -69,9 +65,8 @@ class T2L(guacamole.Command):
data = xfield.text
return data
-
- def invoked(self, ctx):
- with zipfile.ZipFile(ctx.args.file, 'r') as zp:
+ def main(self):
+ with zipfile.ZipFile(self.args.file, 'r') as zp:
tree = ElementTree.parse(zp.open('tellico.xml'))
# open collection
xml_collection = tree.getroot().find('tellico:collection', NS)
@@ -109,7 +104,7 @@ class T2L(guacamole.Command):
field['list'] = l_type
fields.append(field)
# Create a collection with the settings we have loaded
- directory = ctx.args.collection or ctx.args.file.replace(
+ directory = self.args.collection or self.args.file.replace(
'.tc',
'.lesana'
)
@@ -137,7 +132,5 @@ class T2L(guacamole.Command):
self.collection.update_cache()
-
-
if __name__ == '__main__':
T2L().main()