summaryrefslogtreecommitdiff
path: root/obalie/commands
diff options
context:
space:
mode:
Diffstat (limited to 'obalie/commands')
-rw-r--r--obalie/commands/__init__.py47
-rw-r--r--obalie/commands/info.py54
2 files changed, 101 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"""
3Subversion Commands
4
5@author: Mike Crute (mcrute@ag.com)
6@organization: SoftGroup Interactive, Inc.
7@date: April 20, 2010
8"""
9
10
11import os
12import sys
13from obalie.log import inject_logger
14
15
16# Commands are relative to this directory by default
17__dir__ = os.path.dirname(__file__)
18
19
20def 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
42class BaseCommand(object):
43
44 @inject_logger
45 def __init__(self, client, logger=None):
46 self.client = client
47 self.logger = logger
diff --git a/obalie/commands/info.py b/obalie/commands/info.py
new file mode 100644
index 0000000..5bd29fd
--- /dev/null
+++ b/obalie/commands/info.py
@@ -0,0 +1,54 @@
1# vim: set filencoding=utf8
2"""
3Subversion Info
4
5@author: Mike Crute (mcrute@ag.com)
6@organization: SoftGroup Interactive, Inc.
7@date: April 20, 2010
8"""
9
10
11import os
12from xml.dom import pulldom
13from obalie.utils import join_url
14from obalie.commands import BaseCommand
15
16
17class RepositoryInfo(object):
18
19 def __init__(self, path=None, root=None, uuid=None, revision=None):
20 self.path = path
21 self.root = root
22 self.uuid = uuid
23 self.revision = revision
24
25 @property
26 def relative_path(self):
27 return self.path[len(self.root):]
28
29
30class InfoCommand(BaseCommand):
31
32 def __call__(self, path='/'):
33 path = join_url(self.client.repo_url, path)
34 self.logger.info('Running info for path: %s', path)
35
36 repo_info = RepositoryInfo()
37
38 xml = self.client.get_xml_output('info', path)
39 for event, node in xml:
40 if event != pulldom.START_ELEMENT:
41 continue
42
43 if node.tagName in ('url', 'root', 'uuid'):
44 xml.expandNode(node)
45
46 if node.tagName == 'url':
47 repo_info.path = node.firstChild.data
48 elif node.tagName == 'root':
49 repo_info.root = node.firstChild.data
50 elif node.tagName == 'uuid':
51 repo_info.uuid = node.firstChild.data
52
53 return repo_info
54