def __init__(self, args): Log.append('app_init', 'Info', 'version: %s' % Const.version) set_default(default_zone=Zone(home_dir=pyinstaller.get_runtime_dir())) self.qt = QApplication(args) self.qt.setApplicationName(Const.app_name) self.qt.setWindowIcon( QIcon('%s/app/res/icon.png' % pyinstaller.get_runtime_dir())) self.hook_exception() self.config = Config() self.config.load() self.lang = None # type: English self.load_language(Config.language) self.events = { 'process_events': self.qt.processEvents, 'export_log': self.export_log, 'check_update': self.check_update, 'load_language': self.load_language, 'get_language': lambda: self.lang, 'set_language': self.set_language, 'get_config': lambda: self.config, }
def __init__(self, bucket, access_key, secret_key, cdn_host, host=None, timeout=5): self.bucket = bucket self.access_key = access_key self.secret_key = secret_key self.host = host self.cdn_host = cdn_host self.timeout = timeout self.auth = Auth(self.access_key, self.secret_key) set_default(connection_timeout=self.timeout, connection_retries=0)
import gaia.config as cfg from qiniu import Auth from qiniu import BucketManager from qiniu import put_file from qiniu.utils import etag from qiniu.config import set_default config = ( cfg.load_config("app.yaml") or cfg.load_config("qiniu.yaml") or cfg.load_config("qiniu.json") or cfg.load_config("qiniu.cfg") ) set_default(default_up_host=config["qiniu"]["up_host"]) q = Auth(config["qiniu"]["access_key"], config["qiniu"]["secret_key"]) b = BucketManager(q) def file_exist(bucket, key, localfile): ret, info = b.stat(bucket, key) return ret and "hash" in ret and ret["hash"] == etag(localfile) def file_put(bucket, key, localfile): token = q.upload_token(bucket, key) ret, info = put_file(token, key, localfile)