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


Python BlobService.put_block_blob_from_text方法代码示例

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


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

示例1: create_blob

# 需要导入模块: from azure.storage import BlobService [as 别名]
# 或者: from azure.storage.BlobService import put_block_blob_from_text [as 别名]
def create_blob(blob, txt):
    uri = blob.uri
    host_base = cs.get_host_base_from_uri(uri)
    service = BlobService(blob.name,
                          blob.key,
                          host_base=host_base)
    
    container_name = cs.get_container_name_from_uri(uri)
    blob_name = cs.get_blob_name_from_uri(uri)
    service.put_block_blob_from_text(container_name,
                                     blob_name,
                                     txt)
开发者ID:Azure,项目名称:azure-linux-extensions,代码行数:14,代码来源:create_test_blob.py

示例2: AzureBlobStorage

# 需要导入模块: from azure.storage import BlobService [as 别名]
# 或者: from azure.storage.BlobService import put_block_blob_from_text [as 别名]
class AzureBlobStorage(StorageBase):

    def __init__(self, account_name, account_key, container_name):
        self.__container_name = container_name
        self.__blob_service = BlobService(account_name=account_name,
                                          account_key=account_key)
        self.__blob_service.create_container(container_name)

    def get(self, key, default=None):
        logger.info('get: key = %s' % key)
        return pickle.loads(self.__blob_service
                            .get_blob_to_text(self.__container_name, key))

    def set(self, key, value):
        logger.info('get: key = %s, value = %s' % (key, value))
        self.__blob_service.put_block_blob_from_text(self.__container_name,
                                                     key, pickle.dumps(value))
开发者ID:supby,项目名称:DeepSportsAnalytics,代码行数:19,代码来源:azure_storage.py

示例3: __init__

# 需要导入模块: from azure.storage import BlobService [as 别名]
# 或者: from azure.storage.BlobService import put_block_blob_from_text [as 别名]
class BlobCache:
    '''
    Simplistic cache toolkit targetting an Azure Blob Service.

    name:      the name of a storage account.
    key:       the access key for the storage account.
    container: the name of the container to use.
    '''

    def __init__(self, name, key, container):
        self.container = container
        self.blobstore = BlobService(name, key)
        self.blobstore.create_container(self.container)

    def getresponse(self, cachekey):
        '''
        Get a value from the cache.

        cachekey: The key.

        Kilroy notes that this throws an exception rather than returning a 
        value on failure.
        '''
        return self.blobstore.get_blob_to_text(self.container,str2blobname(cachekey))

    def putresponse(self, cachekey, value):
        '''
        Put a value in the cache with the given key.

        cachekey: The key.

        value: The value to associate with the key.
        '''
        return self.blobstore.put_block_blob_from_text(self.container, str2blobname(cachekey), value)

    def invalidate(self, cachekey):
        '''
        Invalidate a value in the cache. Immediate. Permanent.

        cachekey: The key.
        '''
        self.blobstore.delete_blob(self.container, str2blobname(cachekey))
开发者ID:aaarendt,项目名称:ice2oceans_api,代码行数:44,代码来源:blobcache.py

示例4: SAzure

# 需要导入模块: from azure.storage import BlobService [as 别名]
# 或者: from azure.storage.BlobService import put_block_blob_from_text [as 别名]

#.........这里部分代码省略.........
                print(blob.properties.__dict__)
                print(blob.name)
                print(blob.url)"""
            return blobs
        except Exception as e:
            print(_("Bad connection"))
            logging.warning("container {0}, path {1}".format(container, uri))
            exit(1)

    def path_list(self, path):
        try:
            logging.debug("path_list {0}".format(path))

            container, uri = self.path_split(path)
            logging.debug("Container: {0}, Uri: {1}".format(container, uri))

            self.connect()
            self.blob.create_container(container)

            blobs = self.path_list_blobs(container, uri)

            d = {}

            for b in blobs:
                spath = self.spath(container, uri, b)
                # print(b.__dict__)
                #print(str(b.properties.last_modified.__dict__))
                #print(str(spath.ModifiedTS))
                d[spath.SPath] = spath
            # print(d)
            return d
        except Exception as e:
            print(e)

    def remove(self, src: SyncPath):
        try:
            logging.debug("Removing {0}".format(src.AbsPath))
            self.connect()
            self.blob.create_container(src.BasePath)
            self.blob.delete_blob(src.BasePath, src.AbsPath)
        except:
            pass


    def copy_local2azure(self, src, base_dir):
        try:

            container, uri = self.path_split(base_dir)

            if len(src.SPath)>0 and src.SPath[0]=="/":
                path= uri+ src.SPath[1:]
            else:
                path= uri+src.SPath
            logging.debug("copy_local2azure Spath {0}. path:{1}".format(src.SPath, path))
            self.connect()
            if not src.IsDir:
                self.blob.put_block_blob_from_path (container, path, src.AbsPath)
            else:
                self.blob.put_block_blob_from_text(container, path+"/", "")
        except Exception as e:
            print("Error Copying")
            print(e)

    def copy_azure2local(self, src, base_dir):
        try:

            if len(src.SPath)>0 and (src.SPath[0] == "/" or src.SPath[0] == "\\") :
                path = src.SPath[1:]
            else:
                path = src.SPath


            path= os.path.normpath(os.path.join(base_dir, path))
            logging.debug("copy_azure2local basedir:{0} Spath {1}, path {2}, abs: {3}".format( base_dir, src.SPath, path, src.AbsPath))


            if not os.path.isdir(path):
               os.makedirs(os.path.dirname(path), exist_ok=True)
            #print( os.path.dirname(path)+"***************")

            if not (len(src.AbsPath)>0 and src.AbsPath[len(src.AbsPath)-1]=="/"):
                self.blob.get_blob_to_path(src.BasePath, src.AbsPath, path)




            """container, uri = self.path_split(base_dir)

            if len(src.SPath)>0 and src.SPath[0]=="/":
                path= uri+ src.SPath[1:]
            else:
                path= uri+src.SPath
            self.connect()
            if not src.IsDir:
                self.blob.get_blob_to_path(src.BasePath, path, src.AbsPath)
            else:
                self.blob.put_block_blob_from_text(container, path, "")"""
        except Exception as e:
            print("Error copying")
            print(e)
开发者ID:gomes-,项目名称:alx,代码行数:104,代码来源:sys.py

示例5: BlobServiceAdapter

# 需要导入模块: from azure.storage import BlobService [as 别名]
# 或者: from azure.storage.BlobService import put_block_blob_from_text [as 别名]

#.........这里部分代码省略.........

        :type container_name: str|unicode
        :param container_name: Name of existing container.

        :type blob_name: str | unicode
        :param blob_name: Name of blob to create or update.

        :type stream: file
        :param stream: Opened file/stream to upload as the blob content.
        """
        try:
            if self.create_container_in_storage(container_name, "container"):
                self.blob_service.put_block_blob_from_file(container_name, blob_name, stream)
                return self.blob_service.make_blob_url(container_name, blob_name)
            else:
                return None
        except Exception as e:
            self.log.error(e)
            return None

    def upload_file_to_azure_from_bytes(self, container_name, blob_name, blob):
        """
        Creates a new block blob from an array of bytes, or updates the content
        of an existing block blob, with automatic chunking and progress
        notifications.

        :type container_name: str|unicode
        :param container_name: Name of existing container.

        :type blob_name: str|unicode
        :param blob_name: Name of blob to create or update.

        :type blob: bytes
        :param blob: Content of blob as an array of bytes.
        """
        try:
            if self.create_container_in_storage(container_name, "container"):
                self.blob_service.put_block_blob_from_bytes(container_name, blob_name, blob)
                return self.blob_service.make_blob_url(container_name, blob_name)
            else:
                return None
        except Exception as e:
            self.log.error(e)
            return None

    def upload_file_to_azure_from_text(self, container_name, blob_name, text):
        """
        Creates a new block blob from str/unicode, or updates the content of an
        existing block blob, with automatic chunking and progress notifications.

        :type container_name: str|unicode
        :param container_name: Name of existing container.

        :type blob_name: str|unicode
        :param blob_name: Name of blob to create or update.

        :type text: str|unicode
        :param text: Text to upload to the blob.
        """
        try:
            if self.create_container_in_storage(container_name, "container"):
                self.blob_service.put_block_blob_from_text(container_name, blob_name, text)
                return self.blob_service.make_blob_url(container_name, blob_name)
            else:
                return None
        except Exception as e:
            self.log.error(e)
            return None

    def upload_file_to_azure_from_path(self, container_name, blob_name, path):
        """
        Creates a new page blob from a file path, or updates the content of an
        existing page blob, with automatic chunking and progress notifications.

        :type container_name: str|unicode
        :param container_name: Name of existing container.

        :type blob_name: str|unicode
        :param blob_name: Name of blob to create or update.

        :type path: str|unicode
        :param path: Path of the file to upload as the blob content.
        """
        try:
            if self.create_container_in_storage(container_name, "container"):
                self.blob_service.put_block_blob_from_path(container_name, blob_name, path)
                return self.blob_service.make_blob_url(container_name, blob_name)
            else:
                return None
        except Exception as e:
            self.log.error(e)
            return None

    def delete_file_from_azure(self, container_name, blob_name):
        try:
            if self.create_container_in_storage(container_name, "container"):
                self.blob_service.delete_blob(container_name, blob_name)
        except Exception as e:
            self.log.error(e)
            return None
开发者ID:ifhuang,项目名称:open-hackathon,代码行数:104,代码来源:blob_service_adapter.py

示例6: generate_website_and_upload_azure

# 需要导入模块: from azure.storage import BlobService [as 别名]
# 或者: from azure.storage.BlobService import put_block_blob_from_text [as 别名]
def generate_website_and_upload_azure(azure_csv_container, azure_web_container):

    blob_service = BlobService(account_name=os.getenv('ACC_NAME'), account_key=os.getenv('ACCESS_KEY'))
    blob_list = blob_service.list_blobs(azure_csv_container)
    blob_name_list =  blob_list.blobs


    
    keys = []
    #Only keep files whose dates can be parsed
    for k in blob_name_list:
        try:
            parser.parse(k.name[:8])
            keys.append(k)
        except:
            pass

    keys = [k for k in keys if (".zip" in k.name or ".csv" in k.name)]



    
    my_array = []
    for k in keys:
        my_dict = {}
        url = r"http://fhrscsvs.blob.core.windows.net/{}/{}".format(azure_csv_container,k.name)
        name = k.name

        date = parser.parse(name[:8])
        dateformat = date.strftime("%a %d %b %Y")
        my_dict["Date of data download"] = dateformat

        my_dict["Size"] = sizeof_fmt(k.properties.content_length)

        name = get_link_text(name,dateformat,my_dict)
        
        my_dict["File"] = "<a href='{0}'>{1}</a>".format(url,name)
        
        my_array.append(my_dict)

    my_array = sorted(my_array, key=lambda k: k['File'], reverse=True) 

    table_array_fullsnapshot = [a for a in my_array if "__all_current" in a["File"]]
    table_array_differences = [a for a in my_array if "__diff" in a["File"]]

    template_dir = os.getenv('TEMPLATE_DIR')
    loader = jinja2.FileSystemLoader(template_dir)
    environment = jinja2.Environment(loader=loader)

    j_template = environment.get_template("template.html")

    order = ["File", "Size"]
        
    timestamp = datetime.datetime.now().strftime("%a %d %b %Y at %H:%M")
    
    import math
    sinarray = [(math.cos(math.radians(i*5-180))+1)*14 for i in range(0,73)]
    html = j_template.render(table_array_fullsnapshot=table_array_fullsnapshot, 
        order=order, 
        timestamp = timestamp, 
        sinarray=sinarray,
        table_array_differences=table_array_differences)


    blob_service.put_block_blob_from_text(
        azure_web_container,
        "index.html",
        html,
        x_ms_blob_content_type='text/html',
        text_encoding="utf-8",
    )
开发者ID:RobinL,项目名称:daily,代码行数:73,代码来源:my_website.py

示例7: print

# 需要导入模块: from azure.storage import BlobService [as 别名]
# 或者: from azure.storage.BlobService import put_block_blob_from_text [as 别名]
while True:
    batch = blob_service.list_blobs('YourContainer', marker=marker, prefix='input_')
    blobs.extend(batch)
    if not batch.next_marker:
        break
    marker = batch.next_marker
for blob in blobs:
    print(blob.name)

#read the blob file as a text file
#I just read in the first from the pervious list

data = blob_service.get_blob_to_text('rockt', blobs[0].name).split("\n")
print("Number of lines in CSV " + str(len(data)))

#do your stuff
#I want to filter out some lines of my CSV and only keep those having ABC or DEF in them

matchers = ['abc', 'def']
matching = [s for s in data if any(xs in s for xs in matchers)]
print("Number of lines in CSV " + str(len(matching)))

#write your text directly back to blob storage

blob_service.put_block_blob_from_text(
    'YourContainer',
    'YourOutputFile.csv',
    ''.join(matching),
    x_ms_blob_content_type='text'
)
开发者ID:swtimmer,项目名称:digp_blog,代码行数:32,代码来源:readandwrite.py

示例8: puttextobjectinazure

# 需要导入模块: from azure.storage import BlobService [as 别名]
# 或者: from azure.storage.BlobService import put_block_blob_from_text [as 别名]
def puttextobjectinazure (strkey, url, data):
    blob_service = BlobService(account_name='wanderight', account_key='gdmZeJOCx3HYlFPZZukUhHAfeGAu4cfHWGQZc3+HIpkBHjlznUDjhXMl5HWh5MgbjpJF09ZxRaET1JVF9S2MWQ==')
    blob_service.put_block_blob_from_text(
        config['container'], strkey, data,
        x_ms_meta_name_values={'url':url}
    )
开发者ID:trentniemeyer,项目名称:BlogParse,代码行数:8,代码来源:Util.py


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