From 7186576aef3ae67639ebd483e291b3d3e5a24a6a Mon Sep 17 00:00:00 2001 From: Fabien Benureau Date: Sat, 12 Dec 2015 15:02:59 +0100 Subject: [PATCH] Fix bug in args & less-aggressive update Without args.prog, AliasCommand fail. Alias is better documented in the readme and initial config files. Update will now only trigger with version bumps. And the plugins section is not updated. Removes the --upgrade flag. --- pubs/config/spec.py | 8 ++++++++ pubs/pubs_cmd.py | 15 ++++++++------- pubs/update.py | 7 +++++-- readme.md | 14 +++++++------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/pubs/config/spec.py b/pubs/config/spec.py index 699a26d..27cf449 100644 --- a/pubs/config/spec.py +++ b/pubs/config/spec.py @@ -71,6 +71,14 @@ pages = string(default='') # comma-separated list of the plugins to load active = list(default=list()) +[[alias]] +# new subcommands can be defined, e.g.: +# print = open --with lp +# evince = open --with evince + +# shell commands can also be defined, by prefixing them with a bang `!`, e.g: +# count = !pubs list -k | wc -l + [internal] # The version of this configuration file. Do not edit. version = string(min=5, default='{}') diff --git a/pubs/pubs_cmd.py b/pubs/pubs_cmd.py index 3193b61..b791234 100644 --- a/pubs/pubs_cmd.py +++ b/pubs/pubs_cmd.py @@ -33,15 +33,15 @@ CORE_CMDS = collections.OrderedDict([ def execute(raw_args=sys.argv): - conf_parser = argparse.ArgumentParser(add_help=False) + conf_parser = argparse.ArgumentParser(prog="pubs", add_help=False) conf_parser.add_argument("-c", "--config", help="path to config file", type=str, metavar="FILE") - conf_parser.add_argument("-u", "--update", help="update config if needed", - default=False, action='store_true') - args, remaining_args = conf_parser.parse_known_args(raw_args[1:]) + #conf_parser.add_argument("-u", "--update", help="update config if needed", + # default=False, action='store_true') + top_args, remaining_args = conf_parser.parse_known_args(raw_args[1:]) - if args.config: - conf_path = args.config + if top_args.config: + conf_path = top_args.config else: conf_path = config.get_confpath(verify=False) # will be checked on load @@ -49,7 +49,7 @@ def execute(raw_args=sys.argv): if len(remaining_args) > 0 and remaining_args[0] != 'init': try: conf = config.load_conf(path=conf_path, check=False) - if args.update and update.update_check(conf, path=conf.filename): + if update.update_check(conf, path=conf.filename): # an update happened, reload conf. conf = config.load_conf(path=conf_path, check=False) config.check_conf(conf) @@ -81,4 +81,5 @@ def execute(raw_args=sys.argv): # Parse and run appropriate command args = parser.parse_args(remaining_args) + args.prog = "pubs" # FIXME? args.func(conf, args) diff --git a/pubs/update.py b/pubs/update.py index 2a31aba..aab8879 100644 --- a/pubs/update.py +++ b/pubs/update.py @@ -69,7 +69,7 @@ def update(conf, code_version, repo_version, path=None): return True # continuous update while configuration is stabilizing - if repo_version == code_version == ['0', '6', '0']: + if repo_version == ['0', '6', '0'] and repo_version < code_version: default_conf = config.load_default_conf() for section_name, section in conf.items(): for key, value in section.items(): @@ -78,6 +78,10 @@ def update(conf, code_version, repo_version, path=None): default_conf[section_name][key] = value except KeyError: pass + # we don't update plugins + for section_name, section in conf['plugins'].items(): + default_conf[section_name]['plugins'][section_name] = section + # comparing potential changes with open(path, 'r') as f: @@ -85,7 +89,6 @@ def update(conf, code_version, repo_version, path=None): new_conf_text = io.BytesIO() default_conf.write(outfile=new_conf_text) - if new_conf_text.getvalue() != old_conf_text: backup_path = path + '.old' diff --git a/readme.md b/readme.md index cc0aaa1..9409f46 100644 --- a/readme.md +++ b/readme.md @@ -52,16 +52,16 @@ This ensure that your reference file is always up-to-date; you can cite a paper and then add `\cite{Loeb_2012}` in your manuscript. After running the bash script, the citation will correctly appear in your compiled pdf. -Customization -------------- -Pubs is designed to interact well with your command line tool chain. You can add custom commands to pubs by defining aliases in your config file. Here are a few examples. +## Customization - [alias] - print = open -w lp - count = !pubs list -k | wc -l +Pubs is designed to interact well with your command line tool chain. You can add custom commands to pubs by defining aliases in your config file. -For more advanced functionalities, pubs also support plugins. Actually *alias* is itself a plugin! + [[alias]] + evince = open --with evince + count = !pubs list -k | wc -l +The first command defines a new subcommand: `pubs open -w lp` will be executed when `pubs print` is typed. +The second starts with a bang: `!`, and is treated as a shell command. ## Requirements