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

Side by Side Diff: third_party/gsutil/gslib/command_runner.py

Issue 2280023003: depot_tools: Remove third_party/gsutil (Closed)
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « third_party/gsutil/gslib/command.py ('k') | third_party/gsutil/gslib/commands/__init__.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # coding=utf8
3 # Copyright 2011 Google Inc. All Rights Reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 """Class that runs a named gsutil command."""
18
19 import boto
20 import os
21
22 from boto.storage_uri import BucketStorageUri
23 from gslib.command import Command
24 from gslib.command import COMMAND_NAME
25 from gslib.command import COMMAND_NAME_ALIASES
26 from gslib.exception import CommandException
27
28
29 class CommandRunner(object):
30
31 def __init__(self, gsutil_bin_dir, boto_lib_dir, config_file_list,
32 gsutil_ver, bucket_storage_uri_class=BucketStorageUri):
33 """
34 Args:
35 gsutil_bin_dir: Bin dir from which gsutil is running.
36 boto_lib_dir: Lib dir where boto runs.
37 config_file_list: Config file list returned by _GetBotoConfigFileList().
38 gsutil_ver: Version string of currently running gsutil command.
39 bucket_storage_uri_class: Class to instantiate for cloud StorageUris.
40 Settable for testing/mocking.
41 """
42 self.gsutil_bin_dir = gsutil_bin_dir
43 self.boto_lib_dir = boto_lib_dir
44 self.config_file_list = config_file_list
45 self.gsutil_ver = gsutil_ver
46 self.bucket_storage_uri_class = bucket_storage_uri_class
47 self.command_map = self._LoadCommandMap()
48
49 def _LoadCommandMap(self):
50 """Returns dict mapping each command_name to implementing class."""
51 # Walk gslib/commands and find all commands.
52 commands_dir = os.path.join(self.gsutil_bin_dir, 'gslib', 'commands')
53 for f in os.listdir(commands_dir):
54 # Handles no-extension files, etc.
55 (module_name, ext) = os.path.splitext(f)
56 if ext == '.py':
57 __import__('gslib.commands.%s' % module_name)
58 command_map = {}
59 # Only include Command subclasses in the dict.
60 for command in Command.__subclasses__():
61 command_map[command.command_spec[COMMAND_NAME]] = command
62 for command_name_aliases in command.command_spec[COMMAND_NAME_ALIASES]:
63 command_map[command_name_aliases] = command
64 return command_map
65
66 def RunNamedCommand(self, command_name, args=None, headers=None, debug=0,
67 parallel_operations=False, test_method=None,
68 bypass_prodaccess=True):
69 """Runs the named command. Used by gsutil main, commands built atop
70 other commands, and tests .
71
72 Args:
73 command_name: The name of the command being run.
74 args: Command-line args (arg0 = actual arg, not command name ala bash).
75 headers: Dictionary containing optional HTTP headers to pass to boto.
76 debug: Debug level to pass in to boto connection (range 0..3).
77 parallel_operations: Should command operations be executed in parallel?
78 test_method: Optional general purpose method for testing purposes.
79 Application and semantics of this method will vary by
80 command and test type.
81
82 Raises:
83 CommandException: if errors encountered.
84 """
85 if not args:
86 args = []
87
88 # Include api_version header in all commands.
89 api_version = boto.config.get_value('GSUtil', 'default_api_version', '1')
90 if not headers:
91 headers = {}
92 headers['x-goog-api-version'] = api_version
93
94 if command_name not in self.command_map:
95 raise CommandException('Invalid command "%s".' % command_name)
96 command_class = self.command_map[command_name]
97 command_inst = command_class(self, args, headers, debug,
98 parallel_operations, self.gsutil_bin_dir,
99 self.boto_lib_dir, self.config_file_list,
100 self.gsutil_ver, self.bucket_storage_uri_class,
101 test_method, bypass_prodaccess)
102 return command_inst.RunCommand()
OLDNEW
« no previous file with comments | « third_party/gsutil/gslib/command.py ('k') | third_party/gsutil/gslib/commands/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698