Exemple #1
0
class BucketTool():
    def __init__(self, auth):
        self.__auth = auth
        self.__bucketManager = BucketManager(self.__auth)

    def getBucketList(self):
        bucketList = self.__bucketManager.buckets()
        return bucketList[0]

    def list(self, bucket):
        return self.__bucketManager.list(bucket, limit=20)
Exemple #2
0
class Qiqiu(object):
    def __init__(self, ak, sk):
        self.ak = ak
        self.sk = sk
        self.q = Auth(ak, sk)
        self.bucket = BucketManager(self.q)

    def create_bucket(self, bucket_name, region='z2'):
        # "填写存储区域代号  z0:华东, z1:华北, z2:华南, na0:北美"
        ret, info = self.bucket.mkbucketv2(bucket_name, region)
        print(info)
        print(ret)
        return info.status_code == 200

    def bucket_key_exist(self, bucket_name, key):
        ret, info = self.bucket.stat(bucket_name, key)
        if 'error' in ret:
            return False
        else:
            return ret['hash']

    def upload(self, bucket_name, key, file_path):
        """
        :param key: 上传到七牛后保存的文件名
        :file_path: 要上传文件的本地路径
        :return: 
        """
        # 生成上传 Token,可以指定过期时间等
        token = self.q.upload_token(bucket_name, key, 3600)
        ret, info = put_file(token, key, file_path)
        #print(ret)
        #print(info)
        return ret['hash'] == etag(file_path)

    def get_token(self, bucket_name):
        return self.q.upload_token(bucket_name),

    def fetch(self, bucket_name, key, url):
        """
        把网络照片保存起来
        :param bucket_name: 
        :param key: 
        :param url: 
        :return: 
        """
        ret, info = self.bucket.fetch(url, bucket_name, key)
        print(info)
        return ret['key'] == key

    def list_files(self,
                   bucket_name,
                   limit=500,
                   prefix=None,
                   delimiter=None,
                   marker=None):
        ret, eof, info = self.bucket.list(bucket_name, prefix, marker, limit,
                                          delimiter)
        return ret

    def list_buckets(self):
        ret, info = self.bucket.buckets()
        print(info)
        return ret
Exemple #3
0
from qiniu import Auth, BucketManager


AK = Your_AK
SK = Your_SK
q = Auth(AK, SK)
c = BucketManager(q)
info = c.buckets()
print(info)
Exemple #4
0
# coding=utf-8

import datetime
import sys
from qiniu import http
from qiniu import Auth, BucketManager

# kodo-log 账号的 ak、sk
access_key = ""
secret_key = ""
auth = Auth(access_key, secret_key)
bucketManager = BucketManager(auth)

# 获取到账号下的空间列表
buckets, err = bucketManager.buckets()
if err.status_code is not 200:
    print err
    sys.exit(-1)

# 通过 Zepplin 的单选框来选择日志源空间
bucket_options = []
for bucket in sorted(buckets):
    bucket_options.append((bucket, bucket))
bucket_selected = z.select('bucket_selected', bucket_options)
bucket_custom = z.input("bucket_custom", "")
bucket = bucket_selected
if bucket_custom != "":
    bucket = bucket_custom

# get domain 使用空间域名的列举接口拿到一个域名
domains, err = http._post_with_auth(