Add export command to gclient.py

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@20990 0039d316-1c4b-4281-b951-d872f2087c98
parent b3b00a41
......@@ -92,6 +92,7 @@ subcommands:
cleanup
config
diff
export
revert
status
sync
......@@ -187,6 +188,9 @@ Examples:
use 'svn diff -x -b' to suppress whitespace-only differences
gclient diff -- -r HEAD -x -b
diff versus the latest version of each module
""",
"export":
"""Wrapper for svn export for all managed directories
""",
"revert":
"""Revert every file in every managed directory in the client view.
......@@ -720,6 +724,7 @@ class SCMWrapper(object):
commands = {
'cleanup': self.cleanup,
'export': self.export,
'update': self.update,
'revert': self.revert,
'status': self.status,
......@@ -744,6 +749,18 @@ class SCMWrapper(object):
command.extend(args)
RunSVN(command, os.path.join(self._root_dir, self.relpath))
def export(self, options, args, file_list):
assert len(args) == 1
export_path = os.path.abspath(os.path.join(args[0], self.relpath))
try:
os.makedirs(export_path)
except OSError:
pass
assert os.path.exists(export_path)
command = ['export', '--force', '.']
command.append(export_path)
RunSVN(command, os.path.join(self._root_dir, self.relpath))
def update(self, options, args, file_list):
"""Runs SCM to update or transparently checkout the working copy.
......@@ -928,7 +945,7 @@ class GClient(object):
"""Object that represent a gclient checkout."""
supported_commands = [
'cleanup', 'diff', 'revert', 'status', 'update', 'runhooks'
'cleanup', 'diff', 'export', 'revert', 'status', 'update', 'runhooks'
]
def __init__(self, root_dir, options):
......@@ -1525,6 +1542,25 @@ def DoConfig(options, args):
client.SaveConfig()
def DoExport(options, args):
"""Handle the export subcommand.
Raises:
Error: on usage error
"""
if len(args) != 1:
raise Error("Need directory name")
client = GClient.LoadCurrentConfig(options)
if not client:
raise Error("client not configured; see 'gclient config'")
if options.verbose:
# Print out the .gclient file. This is longer than if we just printed the
# client dict, but more legible, and it might contain helpful comments.
print(client.ConfigContent())
return client.RunOnDeps('export', args)
def DoHelp(options, args):
"""Handle the help subcommand giving help for another subcommand.
......@@ -1653,6 +1689,7 @@ gclient_command_map = {
"cleanup": DoCleanup,
"config": DoConfig,
"diff": DoDiff,
"export": DoExport,
"help": DoHelp,
"status": DoStatus,
"sync": DoUpdate,
......
......@@ -107,8 +107,9 @@ class GclientTestCase(GClientBaseTestCase):
class GClientCommandsTestCase(GClientBaseTestCase):
def testCommands(self):
known_commands = [gclient.DoCleanup, gclient.DoConfig, gclient.DoDiff,
gclient.DoHelp, gclient.DoStatus, gclient.DoUpdate,
gclient.DoRevert, gclient.DoRunHooks, gclient.DoRevInfo]
gclient.DoExport, gclient.DoHelp, gclient.DoStatus,
gclient.DoUpdate, gclient.DoRevert, gclient.DoRunHooks,
gclient.DoRevInfo]
for (k,v) in gclient.gclient_command_map.iteritems():
# If it fails, you need to add a test case for the new command.
self.assert_(v in known_commands)
......@@ -288,6 +289,18 @@ class TestDoDiff(GenericCommandTestCase):
self.Verbose('diff', gclient.DoDiff)
class TestDoExport(GenericCommandTestCase):
def testBasic(self):
self.args = ['dir']
self.ReturnValue('export', gclient.DoExport, 0)
def testError(self):
self.args = ['dir']
self.ReturnValue('export', gclient.DoExport, 42)
def testBadClient(self):
self.args = ['dir']
self.BadClient(gclient.DoExport)
class TestDoRevert(GenericCommandTestCase):
def testBasic(self):
self.ReturnValue('revert', gclient.DoRevert, 0)
......@@ -1004,8 +1017,8 @@ class SCMWrapperTestCase(GClientBaseTestCase):
def testDir(self):
members = [
'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'relpath',
'revert', 'scm_name', 'status', 'update', 'url',
'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export',
'relpath', 'revert', 'scm_name', 'status', 'update', 'url',
]
# If you add a member, be sure to add the relevant test!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment