9import importlib.machinery
14DART_DIR = os.path.abspath(
15 os.path.normpath(os.path.join(__file__,
'..',
'..',
'..')))
19 loader = importlib.machinery.SourceFileLoader(modname, filename)
20 spec = importlib.util.spec_from_file_location(modname,
23 module = importlib.util.module_from_spec(spec)
27 loader.exec_module(module)
32 '''Dynamically load the tools/utils.py python module.'''
33 return load_source(
'utils', os.path.join(DART_DIR,
'tools',
'utils.py'))
36def run(command, env=None, shell=False, throw_on_error=True):
37 print(
"Running command: ", command)
39 p = subprocess.Popen(command,
40 stdout=subprocess.PIPE,
41 stderr=subprocess.PIPE,
44 universal_newlines=
True)
45 (stdout, stderr) = p.communicate()
46 if throw_on_error
and p.returncode != 0:
47 print(
"Failed to execute '%s'. Exit code: %s." %
48 (command, p.returncode),
50 print(
"stdout: ", stdout, file=sys.stderr)
51 print(
"stderr: ", stderr, file=sys.stderr)
52 raise Exception(
"Failed to execute %s." % command)
53 return (stdout, stderr, p.returncode)
58 USE_DART_REPO_VERSION =
False
60 def _layzCalculateGSUtilPath(self):
61 if not GSUtil.GSUTIL_PATH:
62 dart_gsutil = os.path.join(DART_DIR,
'third_party',
'gsutil',
64 if os.path.isfile(dart_gsutil):
65 GSUtil.GSUTIL_PATH = dart_gsutil
66 elif GSUtil.USE_DART_REPO_VERSION:
67 raise Exception(
"Dart repository version of gsutil required, "
71 possible_locations = list(os.environ[
'PATH'].split(os.pathsep))
72 for directory
in possible_locations:
73 location = os.path.join(directory,
'gsutil')
74 if os.path.isfile(location):
75 GSUtil.GSUTIL_PATH = location
77 assert GSUtil.GSUTIL_PATH
82 gsutil_command = [sys.executable, GSUtil.GSUTIL_PATH]
84 return run(gsutil_command + gsutil_args)
91 assert remote_path.startswith(
'gs://')
99 args += [local_path, remote_path]
102 def cat(self, remote_path):
103 assert remote_path.startswith(
'gs://')
105 args = [
'cat', remote_path]
106 (stdout, _, _) = self.
execute(args)
110 args = [
'acl',
'ch',
'-g',
'%s:R' % group, remote_path]
114 args = [
'setmeta',
'-h',
'Content-Type:%s' % content_type, remote_path]
117 def remove(self, remote_path, recursive=False):
118 assert remote_path.startswith(
'gs://')
123 args += [remote_path]
def setContentType(self, remote_path, content_type)
def upload(self, local_path, remote_path, recursive=False, multithread=False)
def execute(self, gsutil_args)
def cat(self, remote_path)
def _layzCalculateGSUtilPath(self)
def setGroupReadACL(self, remote_path, group)
def remove(self, remote_path, recursive=False)
def run(command, env=None, shell=False, throw_on_error=True)
def load_source(modname, filename)
def print(*args, **kwargs)