예제 #1
0
파일: oss.py 프로젝트: hatlonely/ops
def put_object(bucket: oss2.Bucket, obj, filename, override=False):
    if not override:
        if bucket.object_exists(obj):
            return {"status": 304}
    if obj:
        obj = os.path.basename(filename)
    res = bucket.put_object_from_file(obj, filename)
    return {"status": res.status}
예제 #2
0
import os
import json
from oss2 import Auth, Bucket, ObjectIterator

with open('package.json') as f:
    package = json.loads(f.read())

Project = package['name']
Deploy = package['deploy']['prod']

auth = Auth(Deploy['accessKeyId'], Deploy['accessKeySecret'])
bucket = Bucket(auth, Deploy['endpoint'], Deploy['bucket'])

for obj in ObjectIterator(bucket):
    bucket.delete_object(obj.key)
    print('Delete <' + obj.key + '> Success')

print('Clear OSS OK!')

for root, _, files in os.walk('dist/' + Project):
    for file in files:
        local = os.path.join(root, file).replace('\\', '/')
        key = local.replace('dist/' + Project + '/', '')
        bucket.put_object_from_file(key, local)
        print('Send <' + key + '> Success')

print('Sync OSS OK!')