def __init__(self, **kwargs): self.content = { 'title' : kwargs.get('title', ''), 'subtitle' : kwargs.get('subtitle', ''), 'icon' : kwargs.get('icon') if kwargs.get('icon') else 'icon.png' } it = kwargs.get('icontype', '').lower() self.icon_type = it if it in ['fileicon', 'filetype'] else None valid = kwargs.get('valid', None) if isinstance(valid, (str, unicode)) and valid.lower() == 'no': valid = 'no' elif isinstance(valid, bool) and not valid: valid = 'no' else: valid = None self.attrb = { 'uid' : kwargs.get('uid', '{0}.{1}'.format(core.bundleID(), random.getrandbits(40))), 'arg' : kwargs.get('arg', None), 'valid' : valid, 'autocomplete' : kwargs.get('autocomplete', None), 'type' : kwargs.get('type', None) } for key in self.content.keys(): if self.content[key] is None: del self.content[key] for key in self.attrb.keys(): if self.attrb[key] is None: del self.attrb[key]
def getLocalPath(source_link): storage_dir = os.path.join(core._storage_base_dir, core.bundleID()) if not os.path.exists(storage_dir): os.makedirs(storage_dir) _, ext = os.path.splitext(source_link) filename = '{}{}'.format(util.hashDigest(source_link), ext) return os.path.join(storage_dir, filename)
def __init__(self, config_file = 'config.json'): self.configs = {} self.configFile = '' path = os.path.join(CONFIG_FOLDER, core.bundleID()) if not os.path.exists(path): os.makedirs(path) self.configFile = os.path.join(path, config_file) if os.path.exists(path): try: with codecs.open(self.configFile, 'r', 'utf-8') as f: self.configs = json.load(f) except Exception, e: pass
def __init__(self, config_file = 'config.json'): self.configs = {} self.configFile = '' path = os.path.join(CONFIG_FOLDER, core.bundleID()) if not os.path.exists(path): os.makedirs(path) self.configFile = os.path.join(path, config_file) if os.path.exists(path): try: with open(self.configFile, 'r') as f: self.configs = json.load(f) except Exception, e: pass
def __init__(self, **kwargs): self.content = { 'title': kwargs.get('title', ''), 'subtitle': kwargs.get('subtitle', ''), 'icon': kwargs.get('icon') if kwargs.get('icon') else 'icon.png' } it = kwargs.get('icontype', '').lower() self.icon_type = it if it in ['fileicon', 'filetype'] else None valid = kwargs.get('valid', None) if isinstance(valid, (str, unicode)) and valid.lower() == 'no': valid = 'no' elif isinstance(valid, bool) and not valid: valid = 'no' else: valid = None self.attrb = { 'uid': kwargs.get( 'uid', '{0}.{1}'.format(core.bundleID(), random.getrandbits(40))), 'arg': kwargs.get('arg', None), 'valid': valid, 'autocomplete': kwargs.get('autocomplete', None), 'type': kwargs.get('type', None) } for key in self.content.keys(): if self.content[key] is None: del self.content[key] for key in self.attrb.keys(): if self.attrb[key] is None: del self.attrb[key]
def __init__(self): self.cache_dir = os.path.join(CACHE_FOLDER, core.bundleID()) if not os.path.exists(self.cache_dir): os.makedirs(self.cache_dir)
# -*- coding: utf-8 -*- import hashlib, random import core hashDigest = lambda s: hashlib.md5(s).hexdigest() uid = lambda: '{0}.{1}'.format(core.bundleID(), random.getrandbits(25))
# -*- coding: utf-8 -*- import os, urllib, subprocess import core, util _storage_dir = os.path.join('/tmp', core.bundleID()) def getLocalPath(source_link): if not os.path.exists(_storage_dir): os.makedirs(_storage_dir) _, ext = os.path.splitext(source_link) filename = '{}{}'.format(util.hashDigest(source_link), ext) return os.path.join(_storage_dir, filename) def getLocalIfExists(source_link, download=False): filepath = getLocalPath(source_link) if os.path.exists(filepath): return filepath if download: singleDownload(source_link) return getLocalIfExists(source_link, False) def isLocalExists(source_link): filepath = getLocalPath(source_link) return os.path.exists(filepath) def batchDownload(links, wait=True): if isinstance(links, (str, unicode)): links = links.split(',') if not links or not isinstance(links, list):
def clean(): cache_dir = os.path.join(core._cache_base_dir, core.bundleID()) if os.path.exists(cache_dir): shutil.rmtree(cache_dir)
def _getFilepath(name): cache_dir = os.path.join(core._cache_base_dir, core.bundleID()) if not os.path.exists(cache_dir): os.makedirs(cache_dir) # convert to md5, more safe for file name return os.path.join(cache_dir, '{}.json'.format(util.hashDigest(name)))
# -*- coding: utf-8 -*- import os, urllib, subprocess import core, util _storage_dir = os.path.join('/tmp', core.bundleID()) def getLocalPath(source_link): if not os.path.exists(_storage_dir): os.makedirs(_storage_dir) _, ext = os.path.splitext(source_link) filename = '{}{}'.format(util.hashDigest(source_link), ext) return os.path.join(_storage_dir, filename) def getLocalIfExists(source_link, download=False): filepath = getLocalPath(source_link) if os.path.exists(filepath): return filepath if download: singleDownload(source_link) return getLocalIfExists(source_link, False) def isLocalExists(source_link): filepath = getLocalPath(source_link) return os.path.exists(filepath)
def _getFilepath(): config_dir = os.path.join(core._config_base_dir, core.bundleID()) if not os.path.exists(config_dir): os.makedirs(config_dir) return os.path.join(config_dir, 'config.json')
# -*- coding: utf-8 -*- import os, json, codecs import core _config_dir = os.path.join(core._CONFIG_FOLDER, core.bundleID()) def _getFilepath(): if not os.path.exists(_config_dir): os.makedirs(_config_dir) return os.path.join(_config_dir, 'config.json') def _save(configs): filepath = _getFilepath() with codecs.open(filepath, 'w', 'utf-8') as f: json.dump(configs, f, indent=4) def getAll(): filepath = _getFilepath() try: with codecs.open(filepath, 'r', 'utf-8') as f: return json.load(f) except: pass return {} def get(key, default=None):
# -*- coding: utf-8 -*- import os, json, codecs import core _config_dir = os.path.join(core._CONFIG_FOLDER, core.bundleID()) def _getFilepath(): if not os.path.exists(_config_dir): os.makedirs(_config_dir) return os.path.join(_config_dir, 'config.json') def _save(configs): filepath = _getFilepath() with codecs.open(filepath, 'w', 'utf-8') as f: json.dump(configs, f, indent=4) def getAll(): filepath = _getFilepath() try: with codecs.open(filepath, 'r', 'utf-8') as f: return json.load(f) except: pass return {} def get(key, default=None): configs = getAll() return configs.get(key, default) def set(**kwargs):
# -*- coding: utf-8 -*- import os, json, time, shutil, codecs import hashlib import core, util # { 'expire_time' : 0, name: '', data' : {} } _DEFAULT_EXPIRE = 60 * 60 * 24 _cache_dir = os.path.join(core._CACHE_FOLDER, core.bundleID()) def _getFilepath(name): if not os.path.exists(_cache_dir): os.makedirs(_cache_dir) # convert to md5, more safe for file name return os.path.join(_cache_dir, '{}.json'.format(util.hashDigest(name))) def _getContent(name): try: filepath = _getFilepath(name) with codecs.open(filepath, 'r', 'utf-8') as f: return json.load(f) except: pass def set(name, data, expire=_DEFAULT_EXPIRE): filepath = _getFilepath(name)
# -*- coding: utf-8 -*- import os, json, time, shutil, codecs import hashlib import core, util # { 'expire_time' : 0, name: '', data' : {} } _DEFAULT_EXPIRE = 60 * 60 * 24 _cache_dir = os.path.join(core._CACHE_FOLDER, core.bundleID()) def _getFilepath(name): if not os.path.exists(_cache_dir): os.makedirs(_cache_dir) # convert to md5, more safe for file name return os.path.join(_cache_dir, '{}.json'.format(util.hashDigest(name))) def _getContent(name): try: filepath = _getFilepath(name) with codecs.open(filepath, 'r', 'utf-8') as f: return json.load(f) except: pass def set(name, data, expire=_DEFAULT_EXPIRE): filepath = _getFilepath(name) try: cache = { 'expire_time' : time.time() + expire,