in gslib/command.py [0:0]
def __init__(self,
command_runner,
args,
headers,
debug,
trace_token,
parallel_operations,
bucket_storage_uri_class,
gsutil_api_class_map_factory,
logging_filters=None,
command_alias_used=None,
perf_trace_token=None,
user_project=None):
"""Instantiates a Command.
Args:
command_runner: CommandRunner (for commands built atop other commands).
args: Command-line args (arg0 = actual arg, not command name ala bash).
headers: Dictionary containing optional HTTP headers to pass to boto.
debug: Debug level to pass in to boto connection (range 0..3).
trace_token: Trace token to pass to the API implementation.
parallel_operations: Should command operations be executed in parallel?
bucket_storage_uri_class: Class to instantiate for cloud StorageUris.
Settable for testing/mocking.
gsutil_api_class_map_factory: Creates map of cloud storage interfaces.
Settable for testing/mocking.
logging_filters: Optional list of logging. Filters to apply to this
command's logger.
command_alias_used: The alias that was actually used when running this
command (as opposed to the "official" command name,
which will always correspond to the file name).
perf_trace_token: Performance measurement trace token to use when making
API calls.
user_project: Project to be billed for this request.
Implementation note: subclasses shouldn't need to define an __init__
method, and instead depend on the shared initialization that happens
here. If you do define an __init__ method in a subclass you'll need to
explicitly call super().__init__(). But you're encouraged not to do this,
because it will make changing the __init__ interface more painful.
"""
# Save class values from constructor params.
super().__init__()
self.command_runner = command_runner
self.unparsed_args = args
self.headers = headers
self.debug = debug
self.trace_token = trace_token
self.perf_trace_token = perf_trace_token
self.parallel_operations = parallel_operations
self.user_project = user_project
self.bucket_storage_uri_class = bucket_storage_uri_class
self.gsutil_api_class_map_factory = gsutil_api_class_map_factory
self.exclude_symlinks = False
self.recursion_requested = False
self.all_versions = False
self.command_alias_used = command_alias_used
self.seek_ahead_gsutil_api = None
# pylint: disable=global-variable-not-assigned
# pylint: disable=global-variable-undefined
global ui_controller
# pylint: enable=global-variable-undefined
# pylint: enable=global-variable-not-assigned
# Global instance of a threaded logger object.
self.logger = CreateOrGetGsutilLogger(self.command_name)
if logging_filters:
for log_filter in logging_filters:
self.logger.addFilter(log_filter)
if self.headers is not None:
self.non_metadata_headers = GetNonMetadataHeaders(self.headers)
else:
self.non_metadata_headers = None
if self.command_spec is None:
raise CommandException('"%s" command implementation is missing a '
'command_spec definition.' % self.command_name)
self.quiet_mode = not self.logger.isEnabledFor(logging.INFO)
ui_controller = UIController(quiet_mode=self.quiet_mode,
dump_status_messages_file=boto.config.get(
'GSUtil', 'dump_status_messages_file',
None))
# Parse and validate args.
self.args = self._TranslateDeprecatedAliases(args)
self.ParseSubOpts()
# Named tuple public functions start with _
# pylint: disable=protected-access
self.command_spec = self.command_spec._replace(
urls_start_arg=self._CalculateUrlsStartArg())
if (len(self.args) < self.command_spec.min_args or
len(self.args) > self.command_spec.max_args):
self.RaiseWrongNumberOfArgumentsException()
if self.command_name not in self._commands_with_subcommands_and_subopts:
self.CheckArguments()
# Build the support and default maps from the command spec.
support_map = {
'gs': self.command_spec.gs_api_support,
's3': [ApiSelector.XML]
}
default_map = {
'gs': self.command_spec.gs_default_api,
's3': ApiSelector.XML
}
self.gsutil_api_map = GsutilApiMapFactory.GetApiMap(
self.gsutil_api_class_map_factory, support_map, default_map)
self.project_id = None
self.gsutil_api = CloudApiDelegator(self.bucket_storage_uri_class,
self.gsutil_api_map,
self.logger,
MainThreadUIQueue(
sys.stderr, ui_controller),
debug=self.debug,
http_headers=self.non_metadata_headers,
trace_token=self.trace_token,
perf_trace_token=self.perf_trace_token,
user_project=self.user_project)
# Cross-platform path to run gsutil binary.
self.gsutil_cmd = ''
# If running on Windows, invoke python interpreter explicitly.
if IS_WINDOWS:
self.gsutil_cmd += 'python '
# Add full path to gsutil to make sure we test the correct version.
self.gsutil_path = gslib.GSUTIL_PATH
self.gsutil_cmd += self.gsutil_path
# We're treating recursion_requested like it's used by all commands, but
# only some of the commands accept the -R option.
if self.sub_opts:
for o, unused_a in self.sub_opts:
if o == '-r' or o == '-R':
self.recursion_requested = True
break
self.multiprocessing_is_available = (
CheckMultiprocessingAvailableAndInit().is_available)