当前位置: 首页>>代码示例>>Python>>正文


Python Env.get方法代码示例

本文整理汇总了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)])
开发者ID:michaelsexton,项目名称:WhatPotato,代码行数:27,代码来源:main.py

示例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)
开发者ID:michaelsexton,项目名称:WhatPotato,代码行数:35,代码来源:main.py

示例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 ''
开发者ID:michaelsexton,项目名称:WhatPotato,代码行数:31,代码来源:base.py

示例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/'
开发者ID:michaelsexton,项目名称:WhatPotato,代码行数:10,代码来源:main.py

示例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')
开发者ID:michaelsexton,项目名称:WhatPotato,代码行数:15,代码来源:__init__.py

示例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())
开发者ID:michaelsexton,项目名称:WhatPotato,代码行数:27,代码来源:growl.py


注:本文中的whatpotato.environment.Env.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。