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


Python Bucket.stat方法代码示例

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


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

示例1: put_obj2storage

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import stat [as 别名]
def put_obj2storage(file_name = '', data = '', expires='365', type=None, encoding= None, domain_name = setting.STORAGE_DOMAIN_NAME):
    import sae.const  
    access_key = sae.const.ACCESS_KEY  
    secret_key = sae.const.SECRET_KEY  
    appname = sae.const.APP_NAME  
    domain_name = "attachment" 
    bucket = Bucket(domain_name)
    bucket.put()
    bucket.post(metadata={'expires': '2d'})
    attrs = bucket.stat()
    bucket.put_object(file_name, data)
    file_url = bucket.generate_url(file_name)
    #begin to created
    im = Image.open("/s/attachment/" + file_name)
    #im = Image.open(bucket.get_object_contents(file_name))
    im.thumbnail((320,200))
    #im.save("/s/attachment/" + file_name+"_thumbnail.jpg")
    imgext = re.search("(\.\w*)$", file_name)
    if imgext:
        thumbnail_name = file_name + "_thumbnail"+ imgext.group(1)
    else:                
        thumbnail_name = file_name + "_thumbnail.jpg"
    pureext = imgext.group(1)[1:]
    if pureext == "jpg":
        pureext = "jpeg"
    #bucket.put_object(thumbnail_name, im.tostring('jpeg', 'RGB'))
    bucket.put_object(thumbnail_name, im.tostring("jpeg", 'RGB'))
    thumbnail_url = bucket.generate_url(thumbnail_name)
    #s = sae.storage.Client()
    #ob = sae.storage.Object(data = data, cache_control='access plus %s day' % expires, content_type= type, content_encoding= encoding)
    return file_url, thumbnail_url
开发者ID:firsthym,项目名称:rebang,代码行数:33,代码来源:views.py

示例2: SAEStorage

# 需要导入模块: from sae.storage import Bucket [as 别名]
# 或者: from sae.storage.Bucket import stat [as 别名]
class SAEStorage(LocalStorage):
    def __init__(self, bucket):
        from sae.storage import Bucket
        self.bucket = Bucket(bucket)
        bucket_stat = self.bucket.stat()
        #self.last_mark = bucket_stat.objects + \
        #                       bucket_stat.bytes
        self.last_mark = 0

    def list(self):
        articles = self.bucket.list()
        filter_func = lambda x : self.is_article(x.name)
        articles = filter(filter_func, articles)
        articles = self._sorted_files(articles)
        rst = []
        for article in articles:
            article_name = article.name
            content = self.bucket.get_object_contents(article_name)
            content = content.decode('utf-8')
            art_meta = self._get_metadatas(content)
            art_meta['filename'] = article_name
            if type(article.name) == unicode:
                adjust_name = article_name.encode('utf-8')
            else :
                adjust_name = article_name
            art_meta['filename_url_encode'] = \
                         base64.urlsafe_b64encode(adjust_name)
            if not art_meta['date']:
                art_meta['date'] = article.last_modified
            if not art_meta["slug"]:
                art_meta['slug'] = article_name.rpartition(".")[0]
                art_meta['slug'] = art_meta['slug'].replace("_", " ")
            rst.append(art_meta)
        return rst

    def get(self, article, cut = -1):
        content = self.bucket.get_object_contents(article)
        content = content.decode('utf-8')
        content = unicode(content)
        mdparse = MDParse()
        if cut != -1:
            content = content[:cut]
            content += "\n....."
        content = self._clean_metadatas(content)
        return mdparse.parse(content)

    def save(self, name, content):
        self.bucket.put_object(name, content)

    def delete(self, name):
        self.bucket.delete_object(name)

    def update_time(self, article):
        stat = self.bucket.stat_object(article)
        tmp = float(stat.timestamp)
        d = datetime.datetime.fromtimestamp(tmp)
        return d.strftime("%Y-%m-%d %H:%M:%S")

    def has_last(self):
        bucket_stat = self.bucket.stat()
        curr_mark = bucket_stat.objects + bucket_stat.bytes
        res = self.last_mark == curr_mark
        self.last_mark = curr_mark
        return not res

    def _sorted_files(self, articles):
        def key_func(x):
            stat = self.bucket.stat_object(x.name)
            return float(stat.timestamp)
        return sorted(articles, key=key_func, reverse=True)
开发者ID:progresstudy,项目名称:SIMBlog,代码行数:72,代码来源:utils.py


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