当前位置: 首页>>代码示例>>Python>>正文


Python app_identity.get_default_gcs_bucket_name方法代码示例

本文整理汇总了Python中google.appengine.api.app_identity.get_default_gcs_bucket_name方法的典型用法代码示例。如果您正苦于以下问题:Python app_identity.get_default_gcs_bucket_name方法的具体用法?Python app_identity.get_default_gcs_bucket_name怎么用?Python app_identity.get_default_gcs_bucket_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.appengine.api.app_identity的用法示例。


在下文中一共展示了app_identity.get_default_gcs_bucket_name方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_gcs_bucket_name [as 别名]
def get(self):
        # Get the default Cloud Storage Bucket name and create a file name for
        # the object in Cloud Storage.
        bucket = app_identity.get_default_gcs_bucket_name()

        # Cloud Storage file names are in the format /bucket/object.
        filename = '/{}/blobstore_serving_demo'.format(bucket)

        # Create a file in Google Cloud Storage and write something to it.
        with cloudstorage.open(filename, 'w') as filehandle:
            filehandle.write('abcde\n')

        # In order to read the contents of the file using the Blobstore API,
        # you must create a blob_key from the Cloud Storage file name.
        # Blobstore expects the filename to be in the format of:
        # /gs/bucket/object
        blobstore_filename = '/gs{}'.format(filename)
        blob_key = blobstore.create_gs_key(blobstore_filename)

        # BlobstoreDownloadHandler serves the file from Google Cloud Storage to
        # your computer using blob_key.
        self.send_blob(blob_key) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:24,代码来源:main.py

示例2: run

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_gcs_bucket_name [as 别名]
def run(self,
          job_name,
          mapper_spec,
          reducer_spec,
          input_reader_spec,
          output_writer_spec=None,
          mapper_params=None,
          reducer_params=None,
          shards=None,
          combiner_spec=None):


    if mapper_params.get("bucket_name") is None:
      try:
        mapper_params["bucket_name"] = (
            app_identity.get_default_gcs_bucket_name())
      except Exception, e:
        raise errors.Error("Unable to get the GCS default bucket name. "
                           "Check to see that GCS is properly activated. "
                           + str(e)) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:22,代码来源:mapreduce_pipeline.py

示例3: get

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_gcs_bucket_name [as 别名]
def get(self):
    user = users.get_current_user()
    username = user.nickname()

    first = FileMetadata.getFirstKeyForUser(username)
    last = FileMetadata.getLastKeyForUser(username)

    q = FileMetadata.all()
    q.filter("__key__ >", first)
    q.filter("__key__ < ", last)
    results = q.fetch(10)

    items = [result for result in results]
    length = len(items)

    bucket_name = app_identity.get_default_gcs_bucket_name()
    upload_url = blobstore.create_upload_url("/upload",
                                             gs_bucket_name=bucket_name)

    self.response.out.write(self.template_env.get_template("index.html").render(
        {"username": username,
         "items": items,
         "length": length,
         "upload_url": upload_url})) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:26,代码来源:main.py

示例4: run

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_gcs_bucket_name [as 别名]
def run(self, filekey, blobkey):
    logging.debug("filename is %s" % filekey)
    bucket_name = app_identity.get_default_gcs_bucket_name()
    output = yield mapreduce_pipeline.MapreducePipeline(
        "word_count",
        "main.word_count_map",
        "main.word_count_reduce",
        "mapreduce.input_readers.BlobstoreZipInputReader",
        "mapreduce.output_writers.GoogleCloudStorageOutputWriter",
        mapper_params={
            "blob_key": blobkey,
        },
        reducer_params={
            "output_writer": {
                "bucket_name": bucket_name,
                "content_type": "text/plain",
            }
        },
        shards=16)
    yield StoreOutput("WordCount", filekey, output) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:22,代码来源:main.py

示例5: run

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_gcs_bucket_name [as 别名]
def run(self,
          job_name,
          mapper_spec,
          reducer_spec,
          input_reader_spec,
          output_writer_spec=None,
          mapper_params=None,
          reducer_params=None,
          shards=None,
          combiner_spec=None):
    # Check that you have a bucket_name set in the mapper_params and set it
    # to the default if not.
    if mapper_params.get("bucket_name") is None:
      try:
        mapper_params["bucket_name"] = (
            app_identity.get_default_gcs_bucket_name())
      except Exception, e:
        raise errors.Error("Unable to get the GCS default bucket name. "
                           "Check to see that GCS is properly activated. "
                           + str(e)) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:22,代码来源:mapreduce_pipeline.py

示例6: __init__

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_gcs_bucket_name [as 别名]
def __init__(self):
        self.bucket_name = os.environ.get(
            'BUCKET_NAME', app_identity.get_default_gcs_bucket_name()) 
开发者ID:duo-labs,项目名称:isthislegit,代码行数:5,代码来源:storage.py

示例7: _bucket_name

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_gcs_bucket_name [as 别名]
def _bucket_name():
	return app_identity.get_default_gcs_bucket_name() 
开发者ID:einaregilsson,项目名称:MyLife,代码行数:4,代码来源:filestore.py

示例8: get

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_gcs_bucket_name [as 别名]
def get(self):
        bucket_name = os.environ.get(
            'BUCKET_NAME', app_identity.get_default_gcs_bucket_name())

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write(
            'Demo GCS Application running from Version: {}\n'.format(
                os.environ['CURRENT_VERSION_ID']))
        self.response.write('Using bucket name: {}\n\n'.format(bucket_name))
# [END get_default_bucket]

        bucket = '/' + bucket_name
        filename = bucket + '/demo-testfile'
        self.tmp_filenames_to_clean_up = []

        self.create_file(filename)
        self.response.write('\n\n')

        self.read_file(filename)
        self.response.write('\n\n')

        self.stat_file(filename)
        self.response.write('\n\n')

        self.create_files_for_list_bucket(bucket)
        self.response.write('\n\n')

        self.list_bucket(bucket)
        self.response.write('\n\n')

        self.list_bucket_directory_mode(bucket)
        self.response.write('\n\n')

        self.delete_files()
        self.response.write('\n\nThe demo ran successfully!\n')

# [START write] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:39,代码来源:main.py

示例9: get_storage

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_gcs_bucket_name [as 别名]
def get_storage(self):
        bucket_name = os.environ.get('BUCKET_NAME', app_identity.get_default_gcs_bucket_name())
        return GCStorage(bucket_name)


# Handlers 
开发者ID:ml2grow,项目名称:GAEPyPI,代码行数:8,代码来源:_handlers.py

示例10: __init__

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_gcs_bucket_name [as 别名]
def __init__(self):
        credentials = GoogleCredentials.get_application_default()
        self.service = build('storage', 'v1', credentials=credentials)
        self.bucket_name = (
            config.get('gcs_bucket_name') or
            app_identity.get_default_gcs_bucket_name()).encode('utf-8') 
开发者ID:google,项目名称:personfinder,代码行数:8,代码来源:cloud_storage.py

示例11: get

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_gcs_bucket_name [as 别名]
def get(self):
        # Get the default Cloud Storage Bucket name and create a file name for
        # the object in Cloud Storage.
        bucket = app_identity.get_default_gcs_bucket_name()

        # Cloud Storage file names are in the format /bucket/object.
        filename = '/{}/blobreader_demo'.format(bucket)

        # Create a file in Google Cloud Storage and write something to it.
        with cloudstorage.open(filename, 'w') as filehandle:
            filehandle.write('abcde\n')

        # In order to read the contents of the file using the Blobstore API,
        # you must create a blob_key from the Cloud Storage file name.
        # Blobstore expects the filename to be in the format of:
        # /gs/bucket/object
        blobstore_filename = '/gs{}'.format(filename)
        blob_key = blobstore.create_gs_key(blobstore_filename)

        # [START gae_blobstore_reader]
        # Instantiate a BlobReader for a given Blobstore blob_key.
        blob_reader = blobstore.BlobReader(blob_key)

        # Instantiate a BlobReader for a given Blobstore blob_key, setting the
        # buffer size to 1 MB.
        blob_reader = blobstore.BlobReader(blob_key, buffer_size=1048576)

        # Instantiate a BlobReader for a given Blobstore blob_key, setting the
        # initial read position.
        blob_reader = blobstore.BlobReader(blob_key, position=0)

        # Read the entire value into memory. This may take a while depending
        # on the size of the value and the size of the read buffer, and is not
        # recommended for large values.
        blob_reader_data = blob_reader.read()

        # Write the contents to the response.
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write(blob_reader_data)

        # Set the read position back to 0, then read and write 3 bytes.
        blob_reader.seek(0)
        blob_reader_data = blob_reader.read(3)
        self.response.write(blob_reader_data)
        self.response.write('\n')

        # Set the read position back to 0, then read and write one line (up to
        # and including a '\n' character) at a time.
        blob_reader.seek(0)
        for line in blob_reader:
            self.response.write(line)
        # [END gae_blobstore_reader]

        # Delete the file from Google Cloud Storage using the blob_key.
        blobstore.delete(blob_key) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:57,代码来源:main.py


注:本文中的google.appengine.api.app_identity.get_default_gcs_bucket_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。