From 31cf4de9d37ffaa1c55e3d399fa997a9b4c25d03 Mon Sep 17 00:00:00 2001 From: Jonathan Grizou Date: Wed, 3 Jul 2013 23:01:47 +0200 Subject: [PATCH] Change call for command from "cmds[cmd].command(**vars(args))" to "cmds[cmd].command(args)". Applied the corresponding changes to command files. AMakes it possible to declare and use additional parser inside subparsers. May be useful for tag command. Will be implemented in texnote plugin. --- papers/commands/add_cmd.py | 9 ++++++++- papers/commands/add_library_cmd.py | 8 ++++++-- papers/commands/attach_cmd.py | 9 ++++++++- papers/commands/edit_cmd.py | 7 ++++++- papers/commands/export_cmd.py | 7 ++++++- papers/commands/import_cmd.py | 7 ++++++- papers/commands/init_cmd.py | 7 ++++++- papers/commands/list_cmd.py | 7 ++++++- papers/commands/open_cmd.py | 7 ++++++- papers/commands/remove_cmd.py | 7 ++++++- papers/commands/tag_cmd.py | 12 +++++++++--- papers/commands/update_cmd.py | 5 ++++- papers/commands/websearch_cmd.py | 7 +++++-- papers/papers_cmd.py | 2 +- papers/plugs/texnote/texnote.py | 9 ++++++++- 15 files changed, 91 insertions(+), 19 deletions(-) diff --git a/papers/commands/add_cmd.py b/papers/commands/add_cmd.py index 838e090..57f4399 100644 --- a/papers/commands/add_cmd.py +++ b/papers/commands/add_cmd.py @@ -19,11 +19,18 @@ def parser(subparsers): return parser -def command(ui, bibfile, docfile, tags, copy): +def command(args): """ :param bibfile: bibtex file (in .bib, .bibml or .yaml format. :param docfile: path (no url yet) to a pdf or ps file """ + + ui = args.ui + bibfile = args.bibfile + docfile = args.docfile + tags = args.tags + copy = args.copy + if copy is None: copy = config().import_copy rp = repo.Repository(config()) diff --git a/papers/commands/add_library_cmd.py b/papers/commands/add_library_cmd.py index 8697eef..6266df4 100644 --- a/papers/commands/add_library_cmd.py +++ b/papers/commands/add_library_cmd.py @@ -9,10 +9,14 @@ def parser(subparsers): return parser -def command(ui, bibfile): +def command(args): """ - :param bibtex bibtex file (in .bib, .bibml or .yaml format. + :param bibfile bibtex file (in .bib, .bibml or .yaml format. """ + + ui = args.ui + bibfile = args.bibfile + rp = repo.Repository(config()) for p in Paper.many_from_bib(bibfile): rp.add_paper(p) diff --git a/papers/commands/attach_cmd.py b/papers/commands/attach_cmd.py index 3b51945..e2c9741 100644 --- a/papers/commands/attach_cmd.py +++ b/papers/commands/attach_cmd.py @@ -16,11 +16,18 @@ def parser(subparsers): return parser -def command(ui, copy, reference, document): +def command(args): """ :param bibfile: bibtex file (in .bib, .bibml or .yaml format. :param docfile: path (no url yet) to a pdf or ps file """ + + ui = args.ui + copy = args.copy + reference = args.reference + document = args.document + + if copy is None: copy = config().import_copy rp = repo.Repository(config()) diff --git a/papers/commands/edit_cmd.py b/papers/commands/edit_cmd.py index 6f45cc2..c2f8bc6 100644 --- a/papers/commands/edit_cmd.py +++ b/papers/commands/edit_cmd.py @@ -14,7 +14,12 @@ def parser(subparsers): return parser -def command(ui, meta, reference): +def command(args): + + ui = args.ui + meta = args.meta + reference = args.reference + rp = repo.Repository(config()) key = parse_reference(ui, rp, reference) paper = rp.get_paper(key) diff --git a/papers/commands/export_cmd.py b/papers/commands/export_cmd.py index 4bbac80..d0422c7 100644 --- a/papers/commands/export_cmd.py +++ b/papers/commands/export_cmd.py @@ -16,10 +16,15 @@ def parser(subparsers): return parser -def command(ui, bib_format, references): +def command(args): """ :param bib_format (in 'bibtex', 'yaml') """ + + ui = args.ui + bib_format = args.bib_format + references = args.references + rp = repo.Repository(config()) papers = [rp.get_paper(c) for c in parse_references(ui, rp, references)] diff --git a/papers/commands/import_cmd.py b/papers/commands/import_cmd.py index 16eef26..ce13f2c 100644 --- a/papers/commands/import_cmd.py +++ b/papers/commands/import_cmd.py @@ -15,10 +15,15 @@ def parser(subparsers): return parser -def command(ui, bibpath, copy): +def command(args): """ :param bibpath: path (no url yet) to a bibliography file """ + + ui = args.ui + bibpath = args.bibpath + copy = agrs.copy + if copy is None: copy = config().import_copy rp = repo.Repository(config()) diff --git a/papers/commands/init_cmd.py b/papers/commands/init_cmd.py index d80f649..b758312 100644 --- a/papers/commands/init_cmd.py +++ b/papers/commands/init_cmd.py @@ -18,8 +18,13 @@ def parser(subparsers): return parser -def command(ui, path, doc_dir): +def command(args): """Create a .papers directory""" + + ui = args.ui + path = args.path + doc_dir = args.doc_dir + if path is not None: config().papers_dir = files.clean_path(os.getcwd(), path) ppd = config().papers_dir diff --git a/papers/commands/list_cmd.py b/papers/commands/list_cmd.py index 88f4f4b..ca95e80 100644 --- a/papers/commands/list_cmd.py +++ b/papers/commands/list_cmd.py @@ -15,7 +15,12 @@ def parser(subparsers): return parser -def command(ui, citekeys, query): +def command(args): + + ui = args.ui + citekeys = args.citekeys + query = args.query + rp = repo.Repository(config()) papers = [(n, p) for n, p in enumerate(rp.all_papers()) if test_paper(query, p)] diff --git a/papers/commands/open_cmd.py b/papers/commands/open_cmd.py index 0687b40..c00d4e9 100644 --- a/papers/commands/open_cmd.py +++ b/papers/commands/open_cmd.py @@ -16,7 +16,12 @@ def parser(subparsers): return parser -def command(ui, with_command, reference): +def command(args): + + ui = args.ui + with_command = args.with_command + reference = args.reference + rp = repo.Repository(config()) key = parse_reference(ui, rp, reference) paper = rp.get_paper(key) diff --git a/papers/commands/remove_cmd.py b/papers/commands/remove_cmd.py index 8c38483..22ed9c6 100644 --- a/papers/commands/remove_cmd.py +++ b/papers/commands/remove_cmd.py @@ -14,7 +14,12 @@ def parser(subparsers): return parser -def command(ui, force, references): +def command(args): + + ui = args.ui + force = args.force + references = args.references + rp = repo.Repository(config()) citekeys = parse_references(ui, rp, references) if force is None: diff --git a/papers/commands/tag_cmd.py b/papers/commands/tag_cmd.py index 0228ee3..5c6de9e 100644 --- a/papers/commands/tag_cmd.py +++ b/papers/commands/tag_cmd.py @@ -28,7 +28,7 @@ def parser(subparsers): 'tag.') parser.add_argument('tags', nargs='?', default = None, help='If the previous argument was a reference, then ' - 'then a list of tags separated by commas.') + 'then a list of tags separated by a +.') # TODO find a way to display clear help for multiple command semantics, # indistinguisable for argparse. (fabien, 201306) return parser @@ -64,8 +64,14 @@ def _tag_groups(tags): minus_tags.append(tag[1:]) return set(plus_tags), set(minus_tags) -def command(ui, referenceOrTag, tags): +def command(args): """Add, remove and show tags""" + + ui = args.ui + referenceOrTag = args.referenceOrTag + tags = args.tags + + rp = Repository(config()) if referenceOrTag is None: @@ -94,4 +100,4 @@ def command(ui, referenceOrTag, tags): papers_list.append((p, n)) ui.print_('\n'.join(helpers.paper_oneliner(p, n) - for p, n in papers_list)) \ No newline at end of file + for p, n in papers_list)) diff --git a/papers/commands/update_cmd.py b/papers/commands/update_cmd.py index 6c6eb91..0bfd1f6 100644 --- a/papers/commands/update_cmd.py +++ b/papers/commands/update_cmd.py @@ -10,7 +10,10 @@ def parser(subparsers): return parser -def command(ui): +def command(args): + + ui = args.ui + code_version = __version__ repo_version = int(config().version) diff --git a/papers/commands/websearch_cmd.py b/papers/commands/websearch_cmd.py index 1f61670..056a8ad 100644 --- a/papers/commands/websearch_cmd.py +++ b/papers/commands/websearch_cmd.py @@ -10,8 +10,11 @@ def parser(subparsers): return parser -def command(ui, search_string): - print search_string +def command(args): + + ui = args.ui + search_string = args.search_string + url = ("https://scholar.google.fr/scholar?q=%s&lr=" % (urllib.quote_plus(' '.join(search_string)))) webbrowser.open(url) diff --git a/papers/papers_cmd.py b/papers/papers_cmd.py index dfa93fa..151f8bc 100644 --- a/papers/papers_cmd.py +++ b/papers/papers_cmd.py @@ -52,4 +52,4 @@ def execute(raw_args = sys.argv): cmd = args.command del args.command - cmds[cmd].command(**vars(args)) + cmds[cmd].command(args) diff --git a/papers/plugs/texnote/texnote.py b/papers/plugs/texnote/texnote.py index bd33326..3fdc79d 100644 --- a/papers/plugs/texnote/texnote.py +++ b/papers/plugs/texnote/texnote.py @@ -29,7 +29,14 @@ class TexnotePlugin(PapersPlugin): parser.add_argument('-v', '--view', action='store_true', help='open the paper in a pdf viewer', default=None) return parser - def command(self, ui, texcmd, reference, view): + def command(self, args): + + ui = args.ui + texcmd = args.texcmd + reference = args.reference + view = args.view + + if view is not None: subprocess.Popen(['papers', 'open', reference]) if texcmd == 'edit':