def year(): sinastorage.setDefaultAppInfo( '***********************', '*************************************') s = SCSBucket('sundae') password = request.form['password'] url0 = s.make_url_authed('picture/bj1.gif') url1 = s.make_url_authed('picture/boom.jpg') url2 = s.make_url_authed('picture/tree.jpg') url3 = s.make_url_authed('picture/snow.jpg') url4 = s.make_url_authed('picture/we.jpg') url5 = s.make_url_authed('picture/me.png') url7 = s.make_url_authed('picture/001.png') if password == u'王璐琰': c = SCSBucket('brokenmist') url10 = c.make_url_authed('picture/bj1.gif') url11 = c.make_url_authed('picture/w1.jpg') url12 = c.make_url_authed('picture/w2.jpg') url13 = c.make_url_authed('picture/w4.jpg') return render_template('wly.html', url10=url10, url11=url11, url12=url12, url13=url13, url14=url7) else: names = (****************************************************************************************) num = len(names) for i in range(0, num): if password == names[i][0]: na = names[i][1] words = name.example(na) nameurl = s.make_url_authed('picture/'+na+'.png') return render_template('newyear.html', url1=url1, url2=url2, url3=url3, url4=url4, url5=url5, nameurl=nameurl, words=words) return render_template('seeyou.html', url0=url0)
def fun(_time_out, _access_key, _secret_key): sinastorage.setDefaultAppInfo(_access_key, _secret_key) already_exist = False all_b = SCSBucket(timeout=_time_out) buckets_generator = all_b.list_buckets() for bucket in buckets_generator: if bucket[0] == BUCKET_NAME: already_exist = True if not already_exist: new_bucket = SCSBucket(BUCKET_NAME, timeout=_time_out) new_bucket.put_bucket() new_bucket.put('haoc/', '')
def upload(self): ''' 普通上传 ''' try: self.mutex.lock() self.state = RunnableState.RUNNING s = SCSBucket(self.bucketName) with FileWithCallback(self.filePath, 'rb', self.uploadCallBack) as fileWithCallback: scsResponse = s.putFileByHeaders( '%s%s' % (self.prefix, os.path.basename(self.filePath)), fileWithCallback) self.response = scsResponse except SCSError, e: print e self.response = SCSResponse(e.urllib2Request, e.urllib2Response) if isinstance(e, ManualCancel): #手动取消 self.state = RunnableState.DID_CANCELED self.response._responseBody = u'手动取消' self.emitter.emit( QtCore.SIGNAL( "fileUploadDidCanceled(PyQt_PyObject,PyQt_PyObject)"), self, e.msg) else: self.state = RunnableState.DID_FAILED self.response._responseBody = e.data self.emitter.emit( QtCore.SIGNAL( "fileUploadDidFailed(PyQt_PyObject,PyQt_PyObject)"), self, e.msg) return
def copy_file(): s = SCSBucket('asdasdasdasd') """ 注意: source 必须从bucket开始,如:'/cloud0/aaa.txt' """ s.copy('/asdasdasdasd/aaaa.txt', 'aaaa22111.txt')
def update_file_acl(): s = SCSBucket('test11') acl = {} acl[ACL.ACL_GROUP_ANONYMOUSE] = [ACL.ACL_READ] acl[ACL.ACL_GROUP_CANONICAL] = [ACL.ACL_READ_ACP,ACL.ACL_WRITE_ACP] s.update_acl('sss.txt', acl)
def __init__(self, host, accesskey, secretkey, bucket_name, remote_dir): self.host = host self.bucket_name = bucket_name self.remote_dir = remote_dir sinastorage.setDefaultAppInfo(accesskey, secretkey) self.handler = SCSBucket(self.bucket_name)
def rename(self, com, time_out): old_cloud_name = "haoc/nodes/%s" % com.old_name new_cloud_name = "haoc/nodes/%s" % com.new_name bucket = SCSBucket(BUCKET_NAME, timeout=time_out) try: if new_cloud_name[-1] == '/': bucket.copy(source="/%s/%s" % (BUCKET_NAME, old_cloud_name), key=new_cloud_name) del bucket[old_cloud_name] else: shall_do = True if self.from_agenda: try: bucket["%s.nod" % new_cloud_name] except sinastorage.bucket.KeyNotFound: pass else: info = bucket.info("%s.nod" % new_cloud_name) ct = float(info.get('metadata').get('lmt')) if com.op_time < ct: shall_do = False if shall_do: bucket.copy(source="/%s/%s.nod" % (BUCKET_NAME, old_cloud_name), key="%s.nod" % new_cloud_name) del bucket["%s.nod" % old_cloud_name] bucket.copy(source="/%s/%s.hlp" % (BUCKET_NAME, old_cloud_name), key="%s.hlp" % new_cloud_name) del bucket["%s.hlp" % old_cloud_name] except sinastorage.bucket.KeyNotFound: pass
def html_form(): sinastorage.setDefaultAppInfo( '***********************', '*************************************') s = SCSBucket('eggtart') url = s.make_url_authed('picture/bj1.gif') whuurl = s.make_url_authed('picture/whu.jpg') return render_template('html_form.html', url=url, url1=whuurl)
def fun(): cloud_path = "haoc/nodes/%s" % self.path bucket = SCSBucket(BUCKET_NAME) # info = bucket.info(cloud_path) total_size = 0 response = bucket[cloud_path] CHUNK = 16 * 1024 download_size = 0 with open(local_path, 'wb') as fp: while True: chunk = response.read(CHUNK) if download_size == 0: total_size = long(response.info().dict.get( 'content-length', 0)) download_size += CHUNK self.progress_bar.set_progress(download_size, total_size) if not chunk: break fp.write(chunk) if os.path.exists("%s.hlp" % local_path[:-4]): response = bucket["%s.hlp" % cloud_path[:-4]] with open("%s.hlp" % local_path[:-4], 'wb') as fp: while True: chunk = response.read(CHUNK) if not chunk: break fp.write(chunk)
def blog(): sinastorage.setDefaultAppInfo( '***********************', '*************************************') s = SCSBucket('sundae') url1 = s.make_url_authed('picture/beijing.jpg') url2 = s.make_url_authed('picture/ziti.png') return render_template('blog.html', url0=url1, url1=url2)
def fun(_time_out): if self.lis is not None: self.lis = [] bucket = SCSBucket(BUCKET_NAME, timeout=_time_out) items_generator = bucket.listdir(prefix='haoc/nodes/', limit=10000) access_key = HaocUtils.Config.get_ak() for item in items_generator: common_name = item[0][11:] local_name = "%s/data/%s/nodes/%s" % ( HaocUtils.get_root_path(), access_key, common_name) if self.lis is not None: if common_name[-1] == '/' or common_name[-4:] == '.nod': self.lis.append(common_name) if common_name[-1] == '/': if not os.path.exists(local_name): os.makedirs(local_name) elif common_name[-4:]: if os.path.exists(local_name): lt = int(os.path.getmtime("%s.nod" % local_name[:-4])) ct = int( bucket.info( "%s.nod" % item[0][:-4]).get('metadata').get('lmt')) # Compare local file modified time with cloud file modified time if lt < ct: open(local_name, "w").close() if is_manual_sync: print "Updated: %s" % common_name else: if not os.path.exists(os.path.dirname(local_name)): os.makedirs(os.path.dirname(local_name)) open(local_name, "w").close() if is_manual_sync: print "Created: %s" % common_name
def who(): sinastorage.setDefaultAppInfo( '***********************', '*************************************') s = SCSBucket('sundae') url1 = s.make_url_authed('picture/who.png') url0 = s.make_url_authed('picture/bj1.gif') url2 = s.make_url_authed('picture/i.png') return render_template('who.html', url0=url0, url1=url1, url2=url2)
def push(dirname): ''' 把dirname文件夹下所有文件都以相同的结构同步到sae云存储中 比如,在dirname下有如下文件: dirname/a/test.txt dirname/test.txt 推送到sae的云存储中的文件结构就是: /a/test.txt /test.txt 注意空文件夹不推送 ''' akey = os.environ['SAE_STORAGE_ACCESS_KEY'] skey = os.environ['SAE_STORAGE_SECRET_KEY'] bucketname = os.environ['SAE_BUCKET_NAME'] sinastorage.setDefaultAppInfo(akey, skey) bucket = SCSBucket(bucketname, secure=False) fpaths = [] for root, dirs, files in os.walk(dirname): ps = splitpath(root) visible = True for p in ps: if p.startswith('.'): visible = False if not visible: continue del ps[0] for f in files: local_fpath = os.path.join(root, f) ps.append(f) fpath = pathjoin(*ps) print('check :' + fpath) fpaths.append(fpath) # if not fpath.startswith(PATH_SPLITER): # fpath =PATH_SPLITER+fpath if file_exist(bucket, fpath): meta = bucket.meta(fpath) sae_sha1 = ['Content-SHA1'] fdata = open(local_fpath, 'rb').read() if len(fdata) == 0 and meta['Size'] == 0: pass else: sha1 = hashlib.sha1() sha1.update(fdata) if sae_sha1 != sha1.hexdigest(): bucket.putFile(fpath, local_fpath) else: bucket.putFile(fpath, local_fpath) sae_files = bucket.listdir(prefix='') for f in sae_files: #f=(name, isPrefix, sha1, expiration_time, modify, owner, md5, content_type, size) localf = os.path.join(dirname, f[0]) print('expecting local: ', localf) if f[0] not in fpaths and not os.path.isfile(localf): print('del ' + f[0]) del bucket[f[0]] else: print('has ' + f[0])
def phone(): sinastorage.setDefaultAppInfo( '***********************', '*************************************') s = SCSBucket('eggtart') bkdurl = s.make_url_authed('picture/P50714-095115.jpg') whuurl = s.make_url_authed('picture/whu.jpg') pcurl = s.make_url_authed('picture/computer.png') blogurl = s.make_url_authed('picture/blog.png') return render_template('phone.html', url1=bkdurl, url2=whuurl, url3=pcurl, url4=blogurl)
def get_file(): s = SCSBucket('asdasdasdasd') response = s['a/asdf/新建 文本文档.txt'] CHUNK = 16 * 1024 with open('111', 'wb') as fp: while True: chunk = response.read(CHUNK) if not chunk: break fp.write(chunk)
def fun(_time_out): f = None try: ice_b = SCSBucket(BUCKET_NAME, timeout=_time_out) response = ice_b['user/name'] f = StringIO(response.read()) return f.read() finally: if f is not None: f.close()
def hello(): sinastorage.setDefaultAppInfo( '***********************', '*************************************') s = SCSBucket('eggtart') pcurl = s.make_url_authed('picture/computer.png') phoneurl = s.make_url_authed('picture/phone.png') blogurl = s.make_url_authed('picture/blog.png') whuurl = s.make_url_authed('picture/whu.jpg') cycleurl = s.make_url_authed('picture/cycle.JPG') return render_template('home.html', url1=pcurl, url2=phoneurl, url3=blogurl, url4=whuurl, url5=cycleurl)
def happy(): sinastorage.setDefaultAppInfo( '***********************', '*************************************') s = SCSBucket('sundae') e = SCSBucket('eggtart') url1 = s.make_url_authed('picture/bj2.gif') url2 = s.make_url_authed('picture/bianpao.gif') url3 = s.make_url_authed('picture/dui0.gif') url4 = s.make_url_authed('picture/door.gif') url5 = s.make_url_authed('picture/deng.gif') url6 = s.make_url_authed('picture/ji.gif') url7 = s.make_url_authed('picture/ren.gif') url8 = s.make_url_authed('picture/tu.gif') url9 = s.make_url_authed('picture/yuan.gif') url10 = s.make_url_authed('picture/cai.gif') url11 = s.make_url_authed('picture/fa.gif') url12 = s.make_url_authed('picture/zong.gif') url13 = s.make_url_authed('picture/lazha.png') whuurl = e.make_url_authed('picture/whu.jpg') return render_template('happy.html', url1=url1, url2=url2, url3=url3, url4=url4, url5=url5, url6=url6, url7=url7, url8=url8, url9=url9, url10=url10, url11=url11, url12=url12, url13=url13, whuurl=whuurl)
def blog_signin(): username = request.form['username'] password = request.form['password']+username+'Sundae' md5 = hashlib.md5() md5.update(password.encode('utf-8')) pwd = md5.hexdigest() sinastorage.setDefaultAppInfo( '***********************', '*************************************') s = SCSBucket('sundae') try: response = s[r'password/'+username+'.txt'] except BaseException, e: return '''
def run(self): s = SCSBucket(self.bucketName) try: self.mutex.lock() self.state = RunnableState.RUNNING self.response = s.send(s.request(method="DELETE", key=None)) except SCSError, e: self.state = RunnableState.DID_FAILED self.response = SCSResponse(e.urllib2Request, e.urllib2Response) self.response._responseBody = e.data self.emitter.emit( QtCore.SIGNAL( "DeleteBucketRunnableDidFailed(PyQt_PyObject,PyQt_PyObject)" ), self, e.msg) return
def signin_form(): global opener, cookie, handler sinastorage.setDefaultAppInfo( '***********************', '*************************************') s = SCSBucket('eggtart') user_Agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586' headers = {"User-Agent": user_Agent} url0 = 'http://210.42.121.132/servlet/GenImg' cookie = cookielib.CookieJar() handler = urllib2.HTTPCookieProcessor(cookie) opener = urllib2.build_opener(handler) req0 = urllib2.Request(url0, headers=headers) response = opener.open(req0) s.put('picture/123.jpg', response.read()) url = s.make_url_authed('picture/123.jpg') return render_template('signin_test.html', pic=url)
def qing(): sinastorage.setDefaultAppInfo( '***********************', '*************************************') s = SCSBucket('eggtart') url = s.make_url_authed('picture/bj1.gif') url0 = s.make_url_authed('picture/c4.jpg') url1 = s.make_url_authed('picture/c5.jpg') url2 = s.make_url_authed('picture/c6.jpg') url3 = s.make_url_authed('picture/c8.jpg') url4 = s.make_url_authed('picture/c0.jpg') url5 = s.make_url_authed('picture/c1.jpg') url6 = s.make_url_authed('picture/c7.jpg') url7 = s.make_url_authed('picture/c2.jpg') url8 = s.make_url_authed('picture/c3.jpg') url9 = s.make_url_authed('picture/whu.jpg') return render_template('cycle.html', url=url, url0=url0, url1=url1, url2=url2, url3=url3, url4=url4, url5=url5, url6=url6, url7=url7, url8=url8, whuurl=url9,)
def run(self): try: self.mutex.lock() self.state = RunnableState.RUNNING s = SCSBucket(self.bucketName) self.response = s.put_bucket() self.response.close() except SCSError, e: self.state = RunnableState.DID_FAILED self.emitter.emit( QtCore.SIGNAL( "CreateBucketDidFailed(PyQt_PyObject,PyQt_PyObject)"), self, e.msg) self.response = SCSResponse(e.urllib2Request, e.urllib2Response) self.response._responseBody = e.data return
def chuan(): sinastorage.setDefaultAppInfo( '***********************', '*************************************') s = SCSBucket('eggtart') url = s.make_url_authed('picture/bj1.gif') url0 = s.make_url_authed('picture/q3.JPG') url1 = s.make_url_authed('picture/q4.JPG') url2 = s.make_url_authed('picture/q7.jpg') url3 = s.make_url_authed('picture/q2.jpg') url4 = s.make_url_authed('picture/q1.jpg') url5 = s.make_url_authed('picture/q8.jpg') url6 = s.make_url_authed('picture/q5.JPG') url7 = s.make_url_authed('picture/q0.jpg') url8 = s.make_url_authed('picture/q6.jpg') url9 = s.make_url_authed('picture/whu.jpg') return render_template('cycle.html', url=url, url0=url0, url1=url1, url2=url2, url3=url3, url4=url4, url5=url5, url6=url6, url7=url7, url8=url8, whuurl=url9,)
def run(self): try: self.mutex.lock() self.state = RunnableState.RUNNING s = SCSBucket(self.bucketName) scsResponse = s.update_acl(self.key, self.acl) self.response = scsResponse except SCSError, e: self.response = SCSResponse(e.urllib2Request, e.urllib2Response) self.response._responseBody = e.data self.state = RunnableState.DID_FAILED self.emitter.emit( QtCore.SIGNAL( "UpdateFileACLDidFailed(PyQt_PyObject,PyQt_PyObject)"), self, e.msg) return
def run(self): try: self.mutex.lock() self.state = RunnableState.RUNNING s = SCSBucket(self.bucketName) # if self.key.rfind('/') == len(self.key)-1 : # m = (("prefix", smart_str(self.key)), # ("delimiter", '/'), # ("max-keys", 5), # ("formatter","json")) # args = dict((str(k), str(v)) for (k, v) in m if v is not None) # response = s.send(s.request(key='', args=args)) # files_generator = SCSListing.parse(response) # # if files_generator.contents_quantity > 0 or files_generator.common_prefixes_quantity > 0 : # for item in files_generator: # if cmp(item[0],self.key) != 0: # self.emitter.emit(QtCore.SIGNAL("DeleteObjectForbidden(PyQt_PyObject,PyQt_PyObject)"), self, u'不能删除非空目录(前缀) ') # return # s = SCSBucket(self.bucketName) if self.key.endswith('/') is not True: #文件 self.response = s.send(s.request(method="DELETE", key=self.key)) else: #目录 m = (("prefix", smart_str(self.key)), ("formatter", "json")) args = dict((str(k), str(v)) for (k, v) in m if v is not None) response = s.send(s.request(key='', args=args)) files_generator = SCSListing.parse(response) ''' 根据bucketName获取bucket下得所有文件 ''' #name, isPrefix, sha1, expiration_time, modify, owner, md5, content_type, size for item in files_generator: fileNameStr = item[0] if not item[1]: self.response = s.send( s.request(method="DELETE", key=fileNameStr)) except SCSError, e: self.state = RunnableState.DID_FAILED self.response = SCSResponse(e.urllib2Request, e.urllib2Response) self.response._responseBody = e.data self.emitter.emit( QtCore.SIGNAL( "DeleteObjectDidFailed(PyQt_PyObject,PyQt_PyObject)"), self, e.msg) return
def run(self): try: self.mutex.lock() self.state = RunnableState.RUNNING s = SCSBucket(self.bucketName) self.response = s.send( s.request(method="GET", key=None, subresource='meta')) metaResult = json.loads(self.response.read()) self.response.close() except SCSError, e: self.state = RunnableState.DID_FAILED self.response = SCSResponse(e.urllib2Request, e.urllib2Response) self.response._responseBody = e.data self.emitter.emit( QtCore.SIGNAL( "BucketInfoDidFailed(PyQt_PyObject,PyQt_PyObject)"), self, e.msg) return
def run(self): try: self.mutex.lock() self.state = RunnableState.RUNNING s = SCSBucket() self.response = s.send(s.request(key='')) bucketJsonObj = json.loads(self.response.read()) self.response.close() self.buckets = bucketJsonObj['Buckets'] except SCSError, e: self.state = RunnableState.DID_FAILED self.response = SCSResponse(e.urllib2Request, e.urllib2Response) self.response._responseBody = e.data self.emitter.emit( QtCore.SIGNAL( "ListBucketRunnableDidFailed(PyQt_PyObject,PyQt_PyObject)" ), self, e.msg) return
def run(self): try: self.mutex.lock() self.state = RunnableState.RUNNING s = SCSBucket(self.bucketName) scsResponse = s.send(s.request(method="HEAD", key=self.key)) info = info_dict(dict(scsResponse.urllib2Response.info())) scsResponse.close() self.response = scsResponse except SCSError, e: self.response = SCSResponse(e.urllib2Request, e.urllib2Response) self.response._responseBody = e.data self.state = RunnableState.DID_FAILED self.emitter.emit( QtCore.SIGNAL( "fileInfoDidFailed(PyQt_PyObject,PyQt_PyObject)"), self, e.msg) return
def register(): sinastorage.setDefaultAppInfo( '***********************', '*************************************') s = SCSBucket('sundae') username = request.form['username'] try: response = s[r'password/'+username+'.txt'] except BaseException, e: password = request.form['password'] password1 = request.form['password1'] if password == password1: password = password+username+'Sundae' md5 = hashlib.md5() md5.update(password.encode('utf-8')) pwd = md5.hexdigest() s.put(r'password/'+username+'.txt', pwd) return '<h3>注册成功,感谢您的支持!</h3>' else: return '''