當前位置: 首頁>>代碼示例>>Python>>正文


Python cloudstorage.delete方法代碼示例

本文整理匯總了Python中cloudstorage.delete方法的典型用法代碼示例。如果您正苦於以下問題:Python cloudstorage.delete方法的具體用法?Python cloudstorage.delete怎麽用?Python cloudstorage.delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cloudstorage的用法示例。


在下文中一共展示了cloudstorage.delete方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testNextWithMissingFiles

# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import delete [as 別名]
def testNextWithMissingFiles(self):
    reader = self.create_single_reader(["file-*"])

    # Remove the first and second to last files.
    cloudstorage.delete(self.test_filenames[0])
    cloudstorage.delete(self.test_filenames[-2])
    del self.test_filenames[0]
    del self.test_filenames[-2]

    reader_files = list(reader)
    self.assertEqual(len(self.test_filenames), len(reader_files))
    self.assertEqual(self.test_filenames, [f.name for f in reader_files])
    self.assertEqual(
        self.test_num_files - 2,
        self.slice_ctx.counter(input_reader.GCSInputReader.COUNTER_FILE_READ))
    self.assertEqual(
        2,
        self.slice_ctx.counter(
            input_reader.GCSInputReader.COUNTER_FILE_MISSING)) 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-mapreduce,代碼行數:21,代碼來源:_gcs_test.py

示例2: tearDown

# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import delete [as 別名]
def tearDown(self):
    # for gcs_object in gcs.listbucket(main.BUCKET):
    #  gcs.delete(gcs_object.filename)
    self.testbed.deactivate() 
開發者ID:googlearchive,項目名稱:billing-export-python,代碼行數:6,代碼來源:test.py

示例3: delete

# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import delete [as 別名]
def delete(filename):
	cloudstorage.delete(_path(filename)) 
開發者ID:einaregilsson,項目名稱:MyLife,代碼行數:4,代碼來源:filestore.py

示例4: delete_files

# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import delete [as 別名]
def delete_files(self):
        self.response.write('Deleting files...\n')
        for filename in self.tmp_filenames_to_clean_up:
            self.response.write('Deleting file {}\n'.format(filename))
            try:
                cloudstorage.delete(filename)
            except cloudstorage.NotFoundError:
                pass
# [END delete_files] 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:11,代碼來源:main.py

示例5: delete

# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import delete [as 別名]
def delete():
    filename = request.form.keys()[0]
    photo = ndb.Key('User', 'default', 'Photo', filename).get()
    for tag in photo.tags:
        entity = ndb.Key('User', 'default', 'Tags', tag).get()
        if entity:
            entity.count -= 1
            if entity.count == 0:
                entity.key.delete()
            else:
                entity.put()
    photo.key.delete()
    gcs.delete('/%s/%s' % (bucket_name, filename))
    return redirect(url_for('photos')) 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-photoalbum-example,代碼行數:16,代碼來源:main.py

示例6: run

# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import delete [as 別名]
def run(self, job_ids):
    for job_id in job_ids:
      db.delete(_OutputFile.all().ancestor(_OutputFile.get_root_key(job_id))) 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-mapreduce,代碼行數:5,代碼來源:shuffler.py

示例7: delete_file_or_list

# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import delete [as 別名]
def delete_file_or_list(self, filename_or_list):
    if isinstance(filename_or_list, list):
      for filename in filename_or_list:
        self.delete_file_or_list(filename)
    else:
      filename = filename_or_list
      retry_params = cloudstorage.RetryParams(min_retries=self._MIN_RETRIES,
                                              max_retries=self._MAX_RETRIES)
      # pylint: disable=bare-except
      try:
        cloudstorage.delete(filename, retry_params)
      except:
        pass 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-mapreduce,代碼行數:15,代碼來源:shuffler.py

示例8: testNextWithMissingFiles

# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import delete [as 別名]
def testNextWithMissingFiles(self):
    readers = self.READER_CLS.split_input(
        self.create_mapper_spec(num_shards=1,
                                input_params={"bucket_name": self.test_bucket,
                                              "objects": ["file-*"]}))
    self.assertEqual(1, len(readers))
    # Remove the first and second to last files.
    cloudstorage.delete(self.test_filenames[0])
    cloudstorage.delete(self.test_filenames[-2])
    del self.test_filenames[0]
    del self.test_filenames[-2]

    reader_files = list(readers[0])
    self.assertEqual(len(self.test_filenames), len(reader_files))
    self.assertEqual(self.test_filenames, [f.name for f in reader_files]) 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-mapreduce,代碼行數:17,代碼來源:input_readers_test.py

示例9: _execute

# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import delete [as 別名]
def _execute(self):
    delta = timedelta(self._params['expiration_days'])
    expiration_datetime = datetime.now() - delta
    expiration_timestamp = time.mktime(expiration_datetime.timetuple())
    stats = self._get_matching_stats(self._params['file_uris'])
    for stat in stats:
      if stat.st_ctime < expiration_timestamp:
        gcs.delete(stat.filename)
        self.log_info('gs:/%s file deleted.', stat.filename) 
開發者ID:google,項目名稱:crmint,代碼行數:11,代碼來源:workers.py

示例10: delete_file_async

# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import delete [as 別名]
def delete_file_async(bucket, filename, ignore_missing):
  """Deletes one file stored in GS.

  Arguments:
    bucket: a bucket that contains the files.
    filename: file path to delete (relative to a bucket root).
    ignore_missing: if True, will silently skip missing files, otherwise will
        print a warning to log.
  """
  retry_params = _make_retry_params()
  max_tries = 4
  # The cloudstorage library supports ndb future but for an unknown reason
  # doesn't export it properly.
  api = cloudstorage.storage_api._get_storage_api(
      retry_params=retry_params, account_id=None)
  p = cloudstorage.api_utils._quote_filename('/%s/%s' % (bucket, filename))
  for i in range(max_tries + 1):
    try:
      # The equivalent of cloudstorage.delete(p, retry_params=retry_params)
      status, resp_headers, content = yield api.delete_object_async(p)
      cloudstorage.errors.check_status(
          status, [204], p, resp_headers=resp_headers, body=content)
      return
    except cloudstorage.errors.NotFoundError:
      if not ignore_missing:
        logging.warning(
            'Trying to delete a GS file that\'s not there: /%s/%s',
            bucket, filename)
      return
    except cloudstorage.errors.TransientError as e:
      if i == max_tries:
        raise
      time.sleep(1 + i * 2)
      continue
    except cloudstorage.errors.FatalError as e:
      if 'But got status 429' in e.message:
        if i == max_tries:
          raise
        # There's a bug in cloudstorage.check_status() that mishandles HTTP
        # 429.
        time.sleep(1 + i * 2)
        continue
      raise 
開發者ID:luci,項目名稱:luci-py,代碼行數:45,代碼來源:gcs.py

示例11: testStrict

# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import delete [as 別名]
def testStrict(self):
    """Tests that fail_on_missing_input works properly."""
    gcs_files = []
    for num in range(10):
      gcs_file = "/los_buckets/file%s" % num
      with cloudstorage.open(gcs_file, "w") as buf:
        buf.write(str(num + 100))
      gcs_files.append("file%s" % num)

    input_class = (input_readers.__name__ + "." +
                   input_readers._GoogleCloudStorageInputReader.__name__)

    def _RunMR(fail_on_missing_input=None):
      """Clears the state and runs a single (strict or not) MR."""
      self._ClearMapperData()

      input_reader_dict = {
          "bucket_name": "los_buckets",
          "objects": gcs_files,
      }
      if fail_on_missing_input is not None:
        input_reader_dict["fail_on_missing_input"] = fail_on_missing_input
      mr_id = control.start_map(
          "job1",
          __name__ + "." + "_input_reader_memory_mapper",
          input_class,
          {
              "input_reader": input_reader_dict,
          },
          shard_count=10)
      test_support.execute_until_empty(self.taskqueue)
      return mr_id

    # All files are there. Default, strict and non-strict MRs should work.
    _RunMR(None)
    self.assertEqual([str(num + 100) for num in range(10)],
                     sorted(_memory_mapper_data))
    _RunMR(False)
    self.assertEqual([str(num + 100) for num in range(10)],
                     sorted(_memory_mapper_data))
    _RunMR(True)
    self.assertEqual([str(num + 100) for num in range(10)],
                     sorted(_memory_mapper_data))

    # Now remove a file.
    cloudstorage.delete("/los_buckets/file5")

    # Non-strict MR still works but some output is not there.
    mr_id = _RunMR(False)
    self.assertEqual([str(num + 100) for num in [0, 1, 2, 3, 4, 6, 7, 8, 9]],
                     sorted(_memory_mapper_data))
    self.assertEquals(model.MapreduceState.get_by_job_id(mr_id).result_status,
                      model.MapreduceState.RESULT_SUCCESS)

    # Strict MR fails.
    mr_id = _RunMR(True)
    self.assertEquals(model.MapreduceState.get_by_job_id(mr_id).result_status,
                      model.MapreduceState.RESULT_FAILED) 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-mapreduce,代碼行數:60,代碼來源:input_readers_end_to_end_test.py


注:本文中的cloudstorage.delete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。