當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。