Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
*.pyc
*.egg-info
__pycache__

*~
*.sw[a-z]
8 changes: 4 additions & 4 deletions compago/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__version__ = (1, 3, 0)
__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
25 changes: 14 additions & 11 deletions compago/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
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

DEFAULT_PLUGINS = []

try:
import compago_plugins
except ImportError, e:
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__)

Expand Down Expand Up @@ -117,7 +120,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))
Expand All @@ -133,9 +136,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)
7 changes: 3 additions & 4 deletions compago/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import inspect
import logging

from compago import Option

from compago.option import Option

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -35,7 +34,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):
Expand All @@ -56,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))
Expand Down
6 changes: 4 additions & 2 deletions compago_plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from logging_plugin import LoggingPlugin
from config_plugin import ConfigPlugin
__version__ = (1, 0, 0)

from compago_plugins.config_plugin import ConfigPlugin
from compago_plugins.logging_plugin import LoggingPlugin
31 changes: 29 additions & 2 deletions compago_plugins/config_plugin.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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):

Expand Down