diff options
Diffstat (limited to 'obalie/commands/__init__.py')
-rw-r--r-- | obalie/commands/__init__.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/obalie/commands/__init__.py b/obalie/commands/__init__.py index e69de29..f0e3682 100644 --- a/obalie/commands/__init__.py +++ b/obalie/commands/__init__.py | |||
@@ -0,0 +1,47 @@ | |||
1 | # vim: set filencoding=utf8 | ||
2 | """ | ||
3 | Subversion Commands | ||
4 | |||
5 | @author: Mike Crute (mcrute@ag.com) | ||
6 | @organization: SoftGroup Interactive, Inc. | ||
7 | @date: April 20, 2010 | ||
8 | """ | ||
9 | |||
10 | |||
11 | import os | ||
12 | import sys | ||
13 | from obalie.log import inject_logger | ||
14 | |||
15 | |||
16 | # Commands are relative to this directory by default | ||
17 | __dir__ = os.path.dirname(__file__) | ||
18 | |||
19 | |||
20 | def load_commands(from_path=__dir__, package=__name__): | ||
21 | commands = {} | ||
22 | |||
23 | for filename in os.listdir(from_path): | ||
24 | name = filename[:-len('.py')] | ||
25 | import_path = '.'.join([package, name]) | ||
26 | |||
27 | mod = __import__(import_path, globals(), locals(), [name]) | ||
28 | |||
29 | command_catalog = getattr(mod, 'COMMANDS', None) | ||
30 | if command_catalog: | ||
31 | commands.update(command_catalog) | ||
32 | continue | ||
33 | |||
34 | impl_name = "{0}Command".format(name.capitalize()) | ||
35 | command_impl = getattr(mod, impl_name, None) | ||
36 | if command_impl: | ||
37 | commands[name] = command_impl | ||
38 | |||
39 | return commands | ||
40 | |||
41 | |||
42 | class BaseCommand(object): | ||
43 | |||
44 | @inject_logger | ||
45 | def __init__(self, client, logger=None): | ||
46 | self.client = client | ||
47 | self.logger = logger | ||