Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Unified Diff: gclient_scm.py

Issue 215022: gclient_scm: add test for unsupported scm (Closed)
Patch Set: converted to create_scm to CreateSCM Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gclient.py ('k') | tests/gclient_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient_scm.py
diff --git a/gclient_scm.py b/gclient_scm.py
index 148855c89ffc597d645314df55274da19909f303..c560cd853ba2bc0d2712d1248331355d686ce071 100644
--- a/gclient_scm.py
+++ b/gclient_scm.py
@@ -27,6 +27,20 @@ SVN_COMMAND = "svn"
### SCM abstraction layer
+# Factory Method for SCM wrapper creation
+
+def CreateSCM(url=None, root_dir=None, relpath=None, scm_name='svn'):
+ # TODO(maruel): Deduce the SCM from the url.
+ scm_map = {
+ 'svn' : SVNWrapper,
+ }
+ if not scm_name in scm_map:
+ raise gclient_utils.Error('Unsupported scm %s' % scm_name)
+ return scm_map[scm_name](url, root_dir, relpath, scm_name)
+
+
+# SCMWrapper base class
+
class SCMWrapper(object):
"""Add necessary glue between all the supported SCM.
@@ -35,7 +49,6 @@ class SCMWrapper(object):
once another SCM is supported."""
def __init__(self, url=None, root_dir=None, relpath=None,
scm_name='svn'):
- # TODO(maruel): Deduce the SCM from the url.
self.scm_name = scm_name
self.url = url
self._root_dir = root_dir
@@ -54,21 +67,21 @@ class SCMWrapper(object):
if file_list is None:
file_list = []
- commands = {
- 'cleanup': self.cleanup,
- 'export': self.export,
- 'update': self.update,
- 'revert': self.revert,
- 'status': self.status,
- 'diff': self.diff,
- 'pack': self.pack,
- 'runhooks': self.status,
- }
+ commands = ['cleanup', 'export', 'update', 'revert',
+ 'status', 'diff', 'pack', 'runhooks']
if not command in commands:
raise gclient_utils.Error('Unknown command %s' % command)
- return commands[command](options, args, file_list)
+ if not command in dir(self):
+ raise gclient_utils.Error('Command %s not implemnted in %s wrapper' % (
+ command, self.scm_name))
+
+ return getattr(self, command)(options, args, file_list)
+
+
+class SVNWrapper(SCMWrapper):
+ """ Wrapper for SVN """
def cleanup(self, options, args, file_list):
"""Cleanup working copy."""
@@ -258,6 +271,9 @@ class SCMWrapper(object):
RunSVN(command + accumulated_paths,
os.path.join(self._root_dir, self.relpath))
+ def runhooks(self, options, args, file_list):
+ self.status(options, args, file_list)
+
def status(self, options, args, file_list):
"""Display status information."""
path = os.path.join(self._root_dir, self.relpath)
« no previous file with comments | « gclient.py ('k') | tests/gclient_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698