Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def upload_split(self):
"""Uploads the individual results recursively to GCS."""
self.report.populate_upload_directory(output_dir=self._upload_dir)
# 1. Copy [ID]-summary.json.gz to gs://wptd/[SHA]/[ID]-summary.json.gz.
gsutil.copy(
os.path.join(self._upload_dir, self.report.sha_summary_path),
self.results_gs_url,
gzipped=True)
# 2. Copy the individual results recursively if there is any (i.e. if
# the report is not empty).
results_dir = os.path.join(
self._upload_dir, self.report.sha_product_path)
if os.path.exists(results_dir):
# gs://wptd/[SHA] is guaranteed to exist after 1, so copying foo to
# gs://wptd/[SHA] will create gs://wptd/[SHA]/foo according to
# `gsutil cp --help`.
gsutil.copy(
results_dir,
self.results_gs_url[:self.results_gs_url.rfind('/')],
gzipped=True)
# 1. Copy [ID]-summary.json.gz to gs://wptd/[SHA]/[ID]-summary.json.gz.
gsutil.copy(
os.path.join(self._upload_dir, self.report.sha_summary_path),
self.results_gs_url,
gzipped=True)
# 2. Copy the individual results recursively if there is any (i.e. if
# the report is not empty).
results_dir = os.path.join(
self._upload_dir, self.report.sha_product_path)
if os.path.exists(results_dir):
# gs://wptd/[SHA] is guaranteed to exist after 1, so copying foo to
# gs://wptd/[SHA] will create gs://wptd/[SHA]/foo according to
# `gsutil cp --help`.
gsutil.copy(
results_dir,
self.results_gs_url[:self.results_gs_url.rfind('/')],
gzipped=True)
def _download_gcs(self, gcs):
assert gcs.startswith('gs://')
ext = self.known_extension(gcs)
fd, path = tempfile.mkstemp(suffix=ext, dir=self._temp_dir)
os.close(fd)
# gsutil will log itself.
gsutil.copy(gcs, path)
return path
def upload_raw(self):
"""Uploads the merged raw JSON report to GCS."""
with tempfile.NamedTemporaryFile(
suffix='.json.gz', dir=self._temp_dir) as temp:
self.report.serialize_gzip(temp.name)
gsutil.copy(temp.name, self.raw_results_gs_url, gzipped=True)