本文整理匯總了Python中whatpotato.environment.Env.get方法的典型用法代碼示例。如果您正苦於以下問題:Python Env.get方法的具體用法?Python Env.get怎麽用?Python Env.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類whatpotato.environment.Env
的用法示例。
在下文中一共展示了Env.get方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getUserScript
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import get [as 別名]
def getUserScript(self, script_route, **kwargs):
klass = self
class UserscriptHandler(RequestHandler):
def get(self, random, route):
bookmarklet_host = Env.setting('bookmarklet_host')
loc = bookmarklet_host if bookmarklet_host else "{0}://{1}".format(self.request.protocol, self.request.headers.get('X-Forwarded-Host') or self.request.headers.get('host'))
params = {
'includes': fireEvent('userscript.get_includes', merge = True),
'excludes': fireEvent('userscript.get_excludes', merge = True),
'version': klass.getVersion(),
'api': '%suserscript/' % Env.get('api_base'),
'host': loc,
}
script = klass.renderTemplate(__file__, 'template.js_tmpl', **params)
klass.createFile(os.path.join(Env.get('cache_dir'), 'whatpotato.user.js'), script)
self.redirect(Env.get('api_base') + 'file.cache/whatpotato.user.js')
Env.get('app').add_handlers(".*$", [('%s%s' % (Env.get('api_base'), script_route), UserscriptHandler)])
示例2: __init__
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import get [as 別名]
def __init__(self):
if Env.get('desktop'):
self.updater = DesktopUpdater()
elif os.path.isdir(os.path.join(Env.get('app_dir'), '.git')):
git_default = 'git'
git_command = self.conf('git_command', default = git_default)
git_command = git_command if git_command != git_default and (os.path.isfile(git_command) or re.match('^[a-zA-Z0-9_/\.\-]+$', git_command)) else git_default
self.updater = GitUpdater(git_command)
else:
self.updater = SourceUpdater()
addEvent('app.load', self.logVersion, priority = 10000)
addEvent('app.load', self.setCrons)
addEvent('updater.info', self.info)
addApiView('updater.info', self.info, docs = {
'desc': 'Get updater information',
'return': {
'type': 'object',
'example': """{
'last_check': "last checked for update",
'update_version': "available update version or empty",
'version': current_cp_version
}"""}
})
addApiView('updater.update', self.doUpdateView)
addApiView('updater.check', self.checkView, docs = {
'desc': 'Check for available update',
'return': {'type': 'see updater.info'}
})
addEvent('setting.save.updater.enabled.after', self.setCrons)
示例3: getCache
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import get [as 別名]
def getCache(self, cache_key, url = None, **kwargs):
use_cache = not len(kwargs.get('data', {})) > 0 and not kwargs.get('files')
if use_cache:
cache_key_md5 = md5(cache_key)
cache = Env.get('cache').get(cache_key_md5)
if cache:
if not Env.get('dev'): log.debug('Getting cache %s', cache_key)
return cache
if url:
try:
cache_timeout = 300
if 'cache_timeout' in kwargs:
cache_timeout = kwargs.get('cache_timeout')
del kwargs['cache_timeout']
data = self.urlopen(url, **kwargs)
if data and cache_timeout > 0 and use_cache:
self.setCache(cache_key, data, timeout = cache_timeout)
return data
except:
if not kwargs.get('show_error', True):
raise
log.debug('Failed getting cache: %s', (traceback.format_exc(0)))
return ''
示例4: getCredentials
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import get [as 別名]
def getCredentials(self, **kwargs):
try:
oauth_token = kwargs.get('oauth')
except:
return 'redirect', Env.get('web_base') + 'settings/downloaders/'
log.debug('oauth_token is: %s', oauth_token)
self.conf('oauth_token', value = oauth_token);
return 'redirect', Env.get('web_base') + 'settings/downloaders/'
示例5: page_not_found
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import get [as 別名]
def page_not_found(rh):
index_url = Env.get('web_base')
url = rh.request.uri[len(index_url):]
if url[:3] != 'api':
r = index_url + '#' + url.lstrip('/')
rh.redirect(r)
else:
if not Env.get('dev'):
time.sleep(0.1)
rh.set_status(404)
rh.write('Wrong API key used')
示例6: register
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import get [as 別名]
def register(self):
if self.registered:
return
try:
hostname = self.conf("hostname")
password = self.conf("password")
port = self.conf("port")
self.growl = notifier.GrowlNotifier(
applicationName=Env.get("appname"),
notifications=["Updates"],
defaultNotifications=["Updates"],
applicationIcon=self.getNotificationImage("medium"),
hostname=hostname if hostname else "localhost",
password=password if password else None,
port=port if port else 23053,
)
self.growl.register()
self.registered = True
except Exception as e:
if "timed out" in str(e):
self.registered = True
else:
log.error("Failed register of growl: %s", traceback.format_exc())