From bb03630434d8eb74b57789141a1ea286ffbeb961 Mon Sep 17 00:00:00 2001 From: Aurelio Sanabria Date: Wed, 29 Jun 2016 10:05:26 -0600 Subject: [PATCH 1/8] Modify .gitignore Add *~ to the .gitignore file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 1828a69..41a4101 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.pyc *.egg-info __pycache__ + +*~ From af3b37e1ebe5a41d5a9892dd4c7082318384001b Mon Sep 17 00:00:00 2001 From: Aurelio Sanabria Date: Wed, 29 Jun 2016 10:10:13 -0600 Subject: [PATCH 2/8] Change prints Chance prints from python2 to python3 --- compago/__init__.py | 2 +- compago/application.py | 10 +++++----- compago/command.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compago/__init__.py b/compago/__init__.py index 1162a14..cf48cfe 100644 --- a/compago/__init__.py +++ b/compago/__init__.py @@ -1,4 +1,4 @@ -__version__ = (1, 3, 0) +__version__ = (1, 5, 0) from option import Option from command import Command, CommandError diff --git a/compago/application.py b/compago/application.py index 65e548e..4caf303 100644 --- a/compago/application.py +++ b/compago/application.py @@ -8,7 +8,7 @@ try: import compago_plugins -except ImportError, e: +except ImportError as e: compago_plugins = None DEFAULT_PLUGINS = [] else: @@ -117,7 +117,7 @@ def run(self, args=None, default=None): if cmd not in self.commands: logger.debug('Command:%s not in app.commands:%s' % ( cmd, self.commands)) - print self.usage + print(self.usage) sys.exit(0) logger.debug('Removing command:%s from args:%s' % (cmd, args)) @@ -133,9 +133,9 @@ def run(self, args=None, default=None): result = self.commands[cmd].run(*args) self.plugin_manager.run_hook('after_command_run', self.commands[cmd]) return result - except CommandError, e: + except CommandError as e: logger.error('Command failed: %s' % e) logger.error(traceback.format_exc()) - print self.usage - print '\nERROR: %s' % e + print(self.usage) + print('\nERROR: %s' % e) sys.exit(1) diff --git a/compago/command.py b/compago/command.py index 927bb99..db97f42 100644 --- a/compago/command.py +++ b/compago/command.py @@ -35,7 +35,7 @@ def run(self, *args): try: logger.debug('Running target:%s' % self.target) return self.target(**kwargs) - except TypeError, e: + except TypeError as e: raise CommandError('Invalid command args: %s' % e) def default_options(self): From 3d66ca8a48c533518c4e07993c7fcb10a88af596 Mon Sep 17 00:00:00 2001 From: Aurelio Sanabria Date: Wed, 29 Jun 2016 10:12:30 -0600 Subject: [PATCH 3/8] Move compago_plugins folder Move compago_plugins folder inside the compago folder as default --- {compago_plugins => compago/compago_plugins}/__init__.py | 0 {compago_plugins => compago/compago_plugins}/config_plugin.py | 0 {compago_plugins => compago/compago_plugins}/logging_plugin.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {compago_plugins => compago/compago_plugins}/__init__.py (100%) rename {compago_plugins => compago/compago_plugins}/config_plugin.py (100%) rename {compago_plugins => compago/compago_plugins}/logging_plugin.py (100%) diff --git a/compago_plugins/__init__.py b/compago/compago_plugins/__init__.py similarity index 100% rename from compago_plugins/__init__.py rename to compago/compago_plugins/__init__.py diff --git a/compago_plugins/config_plugin.py b/compago/compago_plugins/config_plugin.py similarity index 100% rename from compago_plugins/config_plugin.py rename to compago/compago_plugins/config_plugin.py diff --git a/compago_plugins/logging_plugin.py b/compago/compago_plugins/logging_plugin.py similarity index 100% rename from compago_plugins/logging_plugin.py rename to compago/compago_plugins/logging_plugin.py From b02bb06c57e549d2582b35c9f9f81a9492c33e7d Mon Sep 17 00:00:00 2001 From: Aurelio Sanabria Date: Wed, 29 Jun 2016 10:28:21 -0600 Subject: [PATCH 4/8] Add vim swap files to the .gitignore file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 41a4101..ee694df 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __pycache__ *~ +*.sw[a-z] From d8e23b974f007f7ef20b185a3c662d9ed3dc37bb Mon Sep 17 00:00:00 2001 From: Aurelio Sanabria Date: Wed, 29 Jun 2016 10:28:44 -0600 Subject: [PATCH 5/8] Change import statements Change import statements to respect python3 packages diferences --- compago/__init__.py | 6 +++--- compago/application.py | 3 ++- compago/command.py | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compago/__init__.py b/compago/__init__.py index cf48cfe..b64df54 100644 --- a/compago/__init__.py +++ b/compago/__init__.py @@ -1,5 +1,5 @@ __version__ = (1, 5, 0) -from option import Option -from command import Command, CommandError -from application import Application, ApplicationError +from compago.option import Option +from compago.command import Command, CommandError +from compago.application import Application, ApplicationError diff --git a/compago/application.py b/compago/application.py index 4caf303..773580e 100644 --- a/compago/application.py +++ b/compago/application.py @@ -3,7 +3,8 @@ import sys import traceback -from compago import Option, Command, CommandError +from compago.option import Option +from compago.command import Command, CommandError from compago.plugin import PluginManager try: diff --git a/compago/command.py b/compago/command.py index db97f42..58fbb7b 100644 --- a/compago/command.py +++ b/compago/command.py @@ -2,8 +2,7 @@ import inspect import logging -from compago import Option - +from compago.option import Option logger = logging.getLogger(__name__) From 93346f1653cc58029d191157a4c1d68eea7d89b1 Mon Sep 17 00:00:00 2001 From: Aurelio Sanabria Date: Wed, 29 Jun 2016 15:10:07 -0600 Subject: [PATCH 6/8] Move default plugins array position --- compago/application.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/compago/application.py b/compago/application.py index 773580e..ee39832 100644 --- a/compago/application.py +++ b/compago/application.py @@ -7,15 +7,17 @@ from compago.command import Command, CommandError from compago.plugin import PluginManager +DEFAULT_PLUGINS = [] + try: - import compago_plugins + from compago_plugins import * + + DEFAULT_PLUGINS = [logging_plugin.LoggingPlugin(), + config_plugin.ConfigPlugin()] + except ImportError as e: compago_plugins = None DEFAULT_PLUGINS = [] -else: - DEFAULT_PLUGINS = [compago_plugins.LoggingPlugin(), - compago_plugins.ConfigPlugin()] - logger = logging.getLogger(__name__) From da7dc61d6ffffddaa496cc08cc5ace776ba49a56 Mon Sep 17 00:00:00 2001 From: Aurelio Sanabria Date: Wed, 29 Jun 2016 15:10:44 -0600 Subject: [PATCH 7/8] Change parameter for python3 support --- compago/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compago/command.py b/compago/command.py index 58fbb7b..7948c25 100644 --- a/compago/command.py +++ b/compago/command.py @@ -55,7 +55,7 @@ def default_options(self): action=action, dest=arg, required=False, default=default) else: - option = Option(arg, type=unicode) + option = Option(arg, type=str) if not option.dest in [o.dest for o in self.options]: logger.debug('Option:%s not already found in options:%s' % ( option, self.options)) From 5400339521c013aa115897bffbe96fdc4b17f3ef Mon Sep 17 00:00:00 2001 From: Aurelio Sanabria Date: Wed, 29 Jun 2016 15:13:02 -0600 Subject: [PATCH 8/8] Once again, compago_plugins moved and changed to support python3 --- compago/compago_plugins/__init__.py | 2 -- compago_plugins/__init__.py | 4 +++ .../config_plugin.py | 31 +++++++++++++++++-- .../logging_plugin.py | 0 4 files changed, 33 insertions(+), 4 deletions(-) delete mode 100644 compago/compago_plugins/__init__.py create mode 100644 compago_plugins/__init__.py rename {compago/compago_plugins => compago_plugins}/config_plugin.py (61%) rename {compago/compago_plugins => compago_plugins}/logging_plugin.py (100%) diff --git a/compago/compago_plugins/__init__.py b/compago/compago_plugins/__init__.py deleted file mode 100644 index 72af32c..0000000 --- a/compago/compago_plugins/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from logging_plugin import LoggingPlugin -from config_plugin import ConfigPlugin diff --git a/compago_plugins/__init__.py b/compago_plugins/__init__.py new file mode 100644 index 0000000..6bc836b --- /dev/null +++ b/compago_plugins/__init__.py @@ -0,0 +1,4 @@ +__version__ = (1, 0, 0) + +from compago_plugins.config_plugin import ConfigPlugin +from compago_plugins.logging_plugin import LoggingPlugin diff --git a/compago/compago_plugins/config_plugin.py b/compago_plugins/config_plugin.py similarity index 61% rename from compago/compago_plugins/config_plugin.py rename to compago_plugins/config_plugin.py index 377b374..0bb6017 100644 --- a/compago/compago_plugins/config_plugin.py +++ b/compago_plugins/config_plugin.py @@ -1,10 +1,11 @@ -from UserDict import DictMixin import os import yaml + +from collections import MutableMapping from compago.plugin import Plugin -class Config(DictMixin): +class Config(MutableMapping): @staticmethod def load(path): @@ -21,12 +22,38 @@ def __init__(self, **kwargs): def __getitem__(self, key): try: return self.attributes[key] + except KeyError: raise Exception('{0} is not configured.'.format(key)) def keys(self): return self.attributes.keys() + def empty(self): + return True if self else False + + def __setitem__(self, key, value): + self.__dict__[key] = value + + def __delitem__(self, key): + del self.__dict__[key] + + def __iter__(self): + return iter(self.__dict__) + + def __len__(self): + return len(self.__dict__) + + # The final two methods aren't required, but nice for demo purposes: + def __str__(self): + '''returns simple dict representation of the mapping''' + return str(self.__dict__) + + def __repr__(self): + '''echoes class, id, & reproducible representation in the REPL''' + return '{}, D({})'.format(super(D, self).__repr__(), + self.__dict__) + class ConfigPlugin(Plugin): diff --git a/compago/compago_plugins/logging_plugin.py b/compago_plugins/logging_plugin.py similarity index 100% rename from compago/compago_plugins/logging_plugin.py rename to compago_plugins/logging_plugin.py