aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-01-03 16:31:40 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-01-03 16:31:40 +0100
commitdc3bc4bbfda933d3c5d6687011550dc3d1fdb305 (patch)
tree1a330cccefc385b5070c01c9f6b2acff7e7eb347
parente45baf278cb3e52e1cbd0281228a5f0727d25635 (diff)
Convert to use the existing guacamole instead of my own gadona
-rw-r--r--lesana/command.py74
-rwxr-xr-xscripts/lesana26
-rw-r--r--setup.py2
3 files changed, 60 insertions, 42 deletions
diff --git a/lesana/command.py b/lesana/command.py
index 0662d93..0f8ca9a 100644
--- a/lesana/command.py
+++ b/lesana/command.py
@@ -8,7 +8,7 @@ try:
except ImportError:
git_available = False
-import gadona
+import guacamole
from . import Collection, Entry
@@ -63,16 +63,18 @@ def edit_file_in_external_editor(filepath):
-class New(gadona.Command):
- name = 'new'
+class New(guacamole.Command):
arguments = [
(['--collection', '-c'], dict(
help='The collection to work on (default .)'
)),
]
+ def register_arguments(self, parser):
+ for arg in self.arguments:
+ parser.add_argument(*arg[0], **arg[1])
- def main(self):
- collection = Collection(self.settings.collection)
+ def invoked(self, ctx):
+ collection = Collection(ctx.args.collection)
new_entry = Entry(collection)
collection.save_entries([new_entry])
filepath = os.path.join(
@@ -84,8 +86,7 @@ class New(gadona.Command):
print(new_entry)
-class Edit(gadona.Command):
- name = 'edit'
+class Edit(guacamole.Command):
arguments = [
(['--collection', '-c'], dict(
help='The collection to work on (default .)'
@@ -94,10 +95,14 @@ class Edit(gadona.Command):
help='uid of an entry to edit',
)),
]
+ def register_arguments(self, parser):
+ for arg in self.arguments:
+ parser.add_argument(*arg[0], **arg[1])
- def main(self):
- collection = Collection(self.settings.collection)
- entry = collection.entry_from_uid(self.settings.uid)
+
+ def invoked(self, ctx):
+ collection = Collection(ctx.args.collection)
+ entry = collection.entry_from_uid(ctx.args.uid)
filepath = os.path.join(
collection.itemdir,
entry.fname
@@ -107,8 +112,7 @@ class Edit(gadona.Command):
print(entry)
-class Index(gadona.Command):
- name = 'index'
+class Index(guacamole.Command):
arguments = [
(['--collection', '-c'], dict(
help='The collection to work on (default .)'
@@ -119,19 +123,22 @@ class Index(gadona.Command):
nargs='*'
)),
]
+ def register_arguments(self, parser):
+ for arg in self.arguments:
+ parser.add_argument(*arg[0], **arg[1])
+
- def main(self):
- collection = Collection(self.settings.collection)
- if self.settings.files:
- files = (os.path.basename(f) for f in self.settings.files)
+ def invoked(self, ctx):
+ collection = Collection(ctx.args.collection)
+ if ctx.args.files:
+ files = (os.path.basename(f) for f in ctx.args.files)
else:
files = None
indexed = collection.update_cache(fnames=files)
print("Found and indexed {} entries".format(indexed))
-class Search(gadona.Command):
- name = 'search'
+class Search(guacamole.Command):
arguments = [
(['--collection', '-c'], dict(
help='The collection to work on (default .)'
@@ -148,32 +155,35 @@ class Search(gadona.Command):
nargs='+'
)),
]
+ def register_arguments(self, parser):
+ for arg in self.arguments:
+ parser.add_argument(*arg[0], **arg[1])
- def main(self):
+
+ def invoked(self, ctx):
# TODO: implement "searching" for everything
- if self.settings.offset:
+ if ctx.args.offset:
logging.warning(
"offset exposes an internal knob and MAY BE" +
" REMOVED from a future release of lesana"
)
- if self.settings.pagesize:
+ if ctx.args.pagesize:
logging.warning(
"pagesize exposes an internal knob and MAY BE" +
" REMOVED from a future release of lesana"
)
- offset = self.settings.offset or 0
- pagesize = self.settings.pagesize or 12
- collection = Collection(self.settings.collection)
+ offset = ctx.args.offset or 0
+ pagesize = ctx.args.pagesize or 12
+ collection = Collection(ctx.args.collection)
#TODO: pass the entries to a proper template
for entry in collection.search(
- ' '.join(self.settings.query),
+ ' '.join(ctx.args.query),
offset,
pagesize):
print(entry)
-class Init(gadona.Command):
- name = 'init'
+class Init(guacamole.Command):
arguments = [
(['--collection', '-c'], dict(
help='The directory to work on (default .)',
@@ -185,10 +195,14 @@ class Init(gadona.Command):
dest='git'
)),
]
+ def register_arguments(self, parser):
+ for arg in self.arguments:
+ parser.add_argument(*arg[0], **arg[1])
+
- def main(self):
+ def invoked(self, ctx):
Collection.init(
- self.settings.collection,
- git_enabled=self.settings.git,
+ ctx.args.collection,
+ git_enabled=ctx.args.git,
edit_file=edit_file_in_external_editor
)
diff --git a/scripts/lesana b/scripts/lesana
index a500bb8..da9b833 100755
--- a/scripts/lesana
+++ b/scripts/lesana
@@ -1,16 +1,20 @@
#!/usr/bin/env python3
-import gadona
+import guacamole
from lesana.command import New, Edit, Index, Search, Init
+class Lesana(guacamole.Command):
+ """
+ Manage collections
+ """
+
+ sub_commands = (
+ ('new', New),
+ ('edit', Edit),
+ ('index', Index),
+ ('search', Search),
+ ('init', Init),
+ )
+
if __name__ == '__main__':
- app = gadona.App()
- app.description = "Manage collections"
- app.commands = [
- New(),
- Edit(),
- Index(),
- Search(),
- Init(),
- ]
- app.main()
+ Lesana().main()
diff --git a/setup.py b/setup.py
index 8566c95..8e17659 100644
--- a/setup.py
+++ b/setup.py
@@ -6,7 +6,7 @@ setup(
scripts=['scripts/lesana'],
install_requires = [
- 'gadona',
+ 'guacamole',
'xapian >= 1.4',
'ruamel.yaml',
'jinja2',