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


Python Workflow.cached_data方法代码示例

本文整理汇总了Python中workflow.Workflow.cached_data方法的典型用法代码示例。如果您正苦于以下问题:Python Workflow.cached_data方法的具体用法?Python Workflow.cached_data怎么用?Python Workflow.cached_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在workflow.Workflow的用法示例。


在下文中一共展示了Workflow.cached_data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_magic_args

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
def test_magic_args(alfred4):
    """Magic args"""
    # cache original sys.argv
    oargs = sys.argv[:]

    # delsettings
    sys.argv = [oargs[0]] + [b'workflow:delsettings']
    try:
        wf = Workflow(default_settings={'arg1': 'value1'})
        assert wf.settings['arg1'] == 'value1'
        assert os.path.exists(wf.settings_path)
        with pytest.raises(SystemExit):
            wf.args
        assert not os.path.exists(wf.settings_path)
    finally:
        sys.argv = oargs[:]

    # delcache
    sys.argv = [oargs[0]] + [b'workflow:delcache']

    def somedata():
        return {'arg1': 'value1'}

    try:
        wf = Workflow()
        cachepath = wf.cachefile('somedir')
        os.makedirs(cachepath)
        wf.cached_data('test', somedata)
        assert os.path.exists(wf.cachefile('test.cpickle'))
        with pytest.raises(SystemExit):
            wf.args
        assert not os.path.exists(wf.cachefile('test.cpickle'))
    finally:
        sys.argv = oargs[:]
开发者ID:deanishe,项目名称:alfred-workflow,代码行数:36,代码来源:test_workflow.py

示例2: test_install_update

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
    def test_install_update(self):
        """Update: installs update"""

        # Make sure there's no cached update data
        wf = Workflow()
        wf.reset()

        # Verify that there's no update available
        self.assertIsNone(wf.cached_data('__workflow_update_status'))

        self.assertFalse(update.install_update(TEST_REPO_SLUG,
                                               RELEASE_LATEST))

        # Get new update data
        self.assertTrue(update.check_update(TEST_REPO_SLUG, RELEASE_CURRENT))

        # Verify new workflow is downloaded and installed
        c = WorkflowMock()
        with c:
            self.assertTrue(update.install_update(TEST_REPO_SLUG,
                                                  RELEASE_CURRENT))
        self.assertEquals(c.cmd[0], 'open')
        self.assertTrue(c.cmd[1].endswith('.alfredworkflow'))

        self.assertFalse(wf.cached_data(
                         '__workflow_update_status')['available'])
开发者ID:msabramo,项目名称:alfred-workflow,代码行数:28,代码来源:test_update.py

示例3: test_install_update

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
def test_install_update(httpserver, info):
    """Update is installed"""
    # Clear any cached data
    wf = Workflow()
    wf.reset()

    # Assert cache was cleared
    assert wf.cached_data('__workflow_update_status') is None

    with fakeresponse(httpserver, DATA_JSON, HTTP_HEADERS_JSON):
        # No update for latest release
        assert update.install_update(TEST_REPO_SLUG, RELEASE_LATEST) is False

        # Check for updates
        assert update.check_update(TEST_REPO_SLUG, RELEASE_CURRENT) is True

        # Verify new workflow is downloaded and installed
        c = WorkflowMock()
        with c:
            assert update.install_update(TEST_REPO_SLUG,
                                         RELEASE_CURRENT) is True

        assert c.cmd[0] == 'open'
        assert c.cmd[1].endswith('.alfredworkflow')
        assert wf.cached_data(
            '__workflow_update_status')['available'] is False
开发者ID:jikun13,项目名称:alfred-workflow,代码行数:28,代码来源:test_update.py

示例4: main

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
def main():
    wf = Workflow()
    error = None
    try:
        # initialize client
        access_token = wf.get_password('pocket_access_token')
        pocket_instance = Pocket(config.CONSUMER_KEY, access_token)

        state = None
        since = wf.cached_data('pocket_since', max_age=0) or 0
        links = {}
        # fetch cached links if since is not 0
        if since > 0:
            links = wf.cached_data('pocket_list', max_age=0) or {}
            
            # Only use delta syncing if dict is not empty
            if links:
                state = 'all'

        next_since = 0
        offset = 0
        while True:
            get = pocket_instance.get(
                sort='newest',
                detailType='complete',
                since=since,
                state=state,
                count=LINK_LIMIT,
                offset=offset
            )[0]

            data = get['list']
            next_since = get['since']

            if get['status'] != 1 or len(data) == 0:
                break

            links = sync_data(links, data)
            offset += LINK_LIMIT

        wf.cache_data('pocket_since', next_since)
        wf.cache_data('pocket_list', links)

    except (AuthException, URLError, PocketException, PasswordNotFound), e:
        error = type(e).__name__
        wf.cache_data('pocket_error', error)

        # delete token if authentication failed
        if error == 'AuthException':
            wf.delete_password('pocket_access_token')
开发者ID:carriercomm,项目名称:alfred-pocket,代码行数:52,代码来源:pocket_refresh.py

示例5: main

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
def main():
    wf = Workflow()
    error = None
    try:
        # initialize client
        access_token = wf.get_password('pocket_access_token')
        pocket_instance = Pocket(config.CONSUMER_KEY, access_token)

        since = wf.cached_data('pocket_since', max_age=0) or 0
        links = wf.cached_data('pocket_list', max_age=0) or {}

        next_since = 0
        offset = 0
        while True:
            get = pocket_instance.get(
                detailType='complete',
                since=since,
                state='all',
                count=LINK_LIMIT,
                offset=offset
            )[0]

            data = get['list']
            next_since = get['since']

            if get['status'] != 1 or len(data) == 0:
                break

            links.update(data)
            offset += LINK_LIMIT

        # Delete obsolete entries
        for item_id in links.keys():
            if links[item_id]['status'] == '2':
                del links[item_id]

        wf.cache_data('pocket_since', next_since)
        wf.cache_data('pocket_list', links)
        tags = list(set([t for l in links.values() if 'tags' in l
                        for t in l['tags'].keys()]))
        wf.cache_data('pocket_tags', tags)

    except (AuthException, URLError, PocketException, PasswordNotFound), e:
        error = type(e).__name__
        wf.cache_data('pocket_error', error)

        # delete token if authentication failed
        if error == 'AuthException':
            wf.delete_password('pocket_access_token')
开发者ID:danielma,项目名称:dotfiles,代码行数:51,代码来源:pocket_refresh.py

示例6: test_check_update

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
def test_check_update(httpserver, infopl, alfred4):
    """Check update"""
    key = '__workflow_latest_version'
    tests = [
        # data, alfred version, pre, expected value
        (RELEASES_JSON, None, False, True),
        (RELEASES_JSON, '3', False, True),
        (RELEASES_4PLUS_JSON, None, False, True),
        (RELEASES_4PLUS_JSON, '3', False, False),
        (RELEASES_4PLUS_JSON, '3', True, False),
    ]

    for data, alfred, pre, wanted in tests:
        wf = Workflow()
        wf.reset()

        with fakeresponse(httpserver, data, HTTP_HEADERS_JSON):
            v = update.check_update(TEST_REPO, RELEASE_CURRENT,
                                    pre, alfred)
            assert v == wanted, "unexpected update status"

            status = wf.cached_data(key)
            assert status is not None
            assert status['available'] == wanted
            assert wf.update_available == wanted

            if wanted:  # other data may not be set if available is False
                v = update.check_update(TEST_REPO, status['version'],
                                        pre, alfred)
                assert v is False
开发者ID:deanishe,项目名称:alfred-workflow,代码行数:32,代码来源:test_update.py

示例7: test_workflow_update_methods

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
    def test_workflow_update_methods(self):
        """Workflow update methods"""

        def fake(wf):
            return

        Workflow().reset()
        # Initialise with outdated version
        wf = Workflow(update_settings={
            'github_slug': 'deanishe/alfred-workflow-dummy',
            'version': 'v2.0',
            'frequency': 1,
        })

        wf.run(fake)

        # Check won't have completed yet
        self.assertFalse(wf.update_available)

        # wait for background update check
        self.assertTrue(is_running('__workflow_update_check'))
        while is_running('__workflow_update_check'):
            time.sleep(0.05)
        time.sleep(1)

        # There *is* a newer version in the repo
        self.assertTrue(wf.update_available)

        # Mock out subprocess and check the correct command is run
        c = WorkflowMock()
        with c:
            self.assertTrue(wf.start_update())
        # wf.logger.debug('start_update : {}'.format(c.cmd))
        self.assertEquals(c.cmd[0], '/usr/bin/python')
        self.assertEquals(c.cmd[2], '__workflow_update_install')

        # Grab the updated release data, then reset the cache
        update_info = wf.cached_data('__workflow_update_status')

        wf.reset()

        # Initialise with latest available release
        wf = Workflow(update_settings={
            'github_slug': 'deanishe/alfred-workflow-dummy',
            'version': update_info['version'],
        })

        wf.run(fake)

        # Wait for background update check
        self.assertTrue(is_running('__workflow_update_check'))
        while is_running('__workflow_update_check'):
            time.sleep(0.05)

        # Remote version is same as the one we passed to Workflow
        self.assertFalse(wf.update_available)
        self.assertFalse(wf.start_update())
开发者ID:friedenberg,项目名称:alfred-workflow-python,代码行数:59,代码来源:test_update.py

示例8: test_no_auto_update

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
def test_no_auto_update(info):
    """No update check"""
    wf = Workflow()
    wf.reset()
    # Assert cache was cleared
    assert wf.cached_data('__workflow_update_status') is None

    c = WorkflowMock(['script', 'workflow:noautoupdate'])
    with c:
        wf = Workflow()
        wf.args
        assert wf.settings.get('__workflow_autoupdate') is False
        assert wf.cached_data('__workflow_update_status') is None

    c = WorkflowMock()
    with c:
        wf = Workflow(update_settings={
            'github_slug': TEST_REPO_SLUG,
            'version': RELEASE_CURRENT
        })

        assert wf.cached_data('__workflow_update_status') is None
开发者ID:jikun13,项目名称:alfred-workflow,代码行数:24,代码来源:test_update.py

示例9: test_install_update

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
def test_install_update(httpserver, infopl, alfred4):
    """Update is installed."""
    key = '__workflow_latest_version'
    # Clear any cached data
    wf = Workflow()
    wf.reset()

    # Assert cache was cleared
    assert wf.cached_data(key) is None

    with fakeresponse(httpserver, RELEASES_JSON, HTTP_HEADERS_JSON):
        # No update because no update status has been cached
        assert update.install_update() is False

        # Check for updates
        v = update.check_update(TEST_REPO, RELEASE_CURRENT)
        assert v is True

        # Verify new workflow is downloaded and installed
        with WorkflowMock() as c:
            assert update.install_update() is True
            assert c.cmd[0] == 'open'
            assert re.search(r'\.alfred(\d+)?workflow$', c.cmd[1])

        assert wf.cached_data(key)['available'] is False

        # Test mangled update data
        status = wf.cached_data(key)
        assert status['available'] is False
        assert status['download'] is None
        assert status['version'] is None
        # Flip available bit, but leave rest invalid
        status['available'] = True
        wf.cache_data(key, status)

        with WorkflowMock():
            assert update.install_update() is False
开发者ID:deanishe,项目名称:alfred-workflow,代码行数:39,代码来源:test_update.py

示例10: test_check_update

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
def test_check_update(httpserver, info):
    """Check update"""
    wf = Workflow()
    wf.reset()

    with fakeresponse(httpserver, DATA_JSON, HTTP_HEADERS_JSON):
        assert update.check_update(TEST_REPO_SLUG,
                                   RELEASE_CURRENT) is True

        update_info = wf.cached_data('__workflow_update_status')
        assert update_info is not None
        assert wf.update_available is True

        assert update.check_update(TEST_REPO_SLUG,
                                   update_info['version']) is False
开发者ID:jikun13,项目名称:alfred-workflow,代码行数:17,代码来源:test_update.py

示例11: UpdateTests

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
class UpdateTests(unittest.TestCase):

    def setUp(self):
        self.wf = Workflow()

    def test_download_workflow(self):
        """Update: Download workflow update"""
        self.assertRaises(ValueError, u._download_workflow, 'http://github.com/file.zip')
        local_file = u._download_workflow('https://github.com/fniephaus/alfred-pocket/releases/download/v2.1/Pocket-for-Alfred.alfredworkflow')
        self.assertTrue(local_file.endswith('.alfredworkflow'))
        self.assertTrue(os.path.isfile(local_file))

    def test_get_api_url(self):
        """Update: Get API URL"""
        url = u._get_api_url('fniephaus/alfred-workflow')
        expected = 'https://api.github.com/repos/fniephaus/alfred-workflow/releases'
        self.assertEquals(url, expected)
        self.assertRaises(ValueError, u._get_api_url, 'fniephausalfred-workflow')

    def test_extract_info(self):
        """Update: Extract release info"""
        releases = [{
            'tag_name': 'v1.2',
            'assets': [{
                'browser_download_url': 'https://github.com/'
            }]
        }]
        (version, url) = u._extract_info(releases)
        self.assertEquals(version, 'v1.2')
        self.assertEquals(url, 'https://github.com/')
        self.assertRaises(IndexError, u._extract_info, [])
        del releases[0]['assets']
        self.assertRaises(KeyError, u._extract_info, releases)
        del releases[0]['tag_name']
        self.assertRaises(KeyError, u._extract_info, releases)

    def test_check_update(self):
        """Update: Check update"""
        self.assertTrue(u._check_update('fniephaus/alfred-pocket', 'v0.0'))
        update_info = self.wf.cached_data('__workflow_update_available')
        self.assertFalse(u._check_update('fniephaus/alfred-pocket', update_info['version']))
开发者ID:carriercomm,项目名称:alfred-workflow,代码行数:43,代码来源:test_update.py

示例12: main

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
def main():
    wf = Workflow()

    args = parse_args(wf.args)

    title = 'Add this link'
    if args.add_archive:
        title = 'Add and archive this link'

    wf.add_item(title, arg=args.query, valid=True)

    tags = wf.cached_data('pocket_tags', max_age=0)
    if tags:
        for tag in tags:
            if args.query:
                autocomplete = '%s, #%s' % (args.query, tag)
            else:
                autocomplete = '#%s' % tag
            wf.add_item(' > Add #%s' % tag,
                        autocomplete=autocomplete,
                        valid=False)
    wf.send_feedback()
开发者ID:danielma,项目名称:dotfiles,代码行数:24,代码来源:pocket_tags.py

示例13: UpdateTests

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
class UpdateTests(unittest.TestCase):

    def setUp(self):
        create_info_plist()
        self.wf = Workflow()

    def tearDown(self):
        delete_info_plist()

    def test_download_workflow(self):
        """Update: Download workflow update"""

        self.assertRaises(ValueError, update.download_workflow, URL_BAD)

        local_file = update.download_workflow(URL_DL)

        self.assertTrue(local_file.endswith('.alfredworkflow'))
        self.assertTrue(os.path.isfile(local_file))

    def test_valid_api_url(self):
        """Update: API URL for valid slug"""

        url = update.build_api_url(TEST_REPO_SLUG)
        self.assertEquals(url, RELEASES_URL)

    def test_invalid_api_url(self):
        """Update: API URL for invalid slug"""

        self.assertRaises(ValueError, update.build_api_url,
                          'fniephausalfred-workflow')

    def test_empty_repo(self):
        """Update: no releases"""

        self.assertRaises(ValueError, update.check_update,
                          EMPTY_REPO_SLUG, '1.0')

        self.assertEquals(len(update.get_valid_releases(EMPTY_REPO_SLUG)), 0)

    def test_valid_releases(self):
        """Update: valid releases"""

        releases = update.get_valid_releases(TEST_REPO_SLUG)

        # Right number of valid releases
        self.assertEquals(len(releases), 3)

        # Invalid releases are not in list
        versions = [d['version'] for d in releases]
        for v in RELEASES_INVALID:
            self.assertFalse(v in versions)

        # Correct latest release
        self.assertEquals(update.Version(releases[0]['version']),
                          update.Version(RELEASE_LATEST))

    def test_version_formats(self):
        """Update: version formats"""

        # Up-to-date versions
        self.assertFalse(update.check_update(TEST_REPO_SLUG, '6.0'))
        self.assertFalse(update.check_update(TEST_REPO_SLUG, 'v6.0'))

        # Old versions
        self.assertTrue(update.check_update(TEST_REPO_SLUG, 'v5.0'))
        self.assertTrue(update.check_update(TEST_REPO_SLUG, '5.0'))

        # Unknown versions
        self.assertFalse(update.check_update(TEST_REPO_SLUG, 'v8.0'))
        self.assertFalse(update.check_update(TEST_REPO_SLUG, '8.0'))

    def test_check_update(self):
        """Update: Check update"""

        self.assertTrue(update.check_update(TEST_REPO_SLUG, RELEASE_CURRENT))

        update_info = self.wf.cached_data('__workflow_update_status')
        self.assertFalse(update.check_update(TEST_REPO_SLUG,
                                             update_info['version']))

    def test_install_update(self):
        """Update: installs update"""

        # Make sure there's no cached update data
        wf = Workflow()
        wf.reset()

        # Verify that there's no update available
        self.assertTrue(wf.cached_data('__workflow_update_status') is None)

        self.assertFalse(update.install_update(TEST_REPO_SLUG,
                                               RELEASE_LATEST))

        # Get new update data
        self.assertTrue(update.check_update(TEST_REPO_SLUG, RELEASE_CURRENT))

        # Verify new workflow is downloaded and installed
        c = WorkflowMock()
        with c:
            self.assertTrue(update.install_update(TEST_REPO_SLUG,
#.........这里部分代码省略.........
开发者ID:friedenberg,项目名称:alfred-workflow-python,代码行数:103,代码来源:test_update.py

示例14: is_dark

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
def is_dark():
    return min([int(x) for x in WF.alfred_env['theme_background'][5:-6].split(',')]) < 128


if __name__ == '__main__':
    from cask_actions import ACTIONS

    if WF.update_available:
        WF.add_item(
            "An update is available!",
            autocomplete='workflow:update',
            valid=False,
            icon=get_icon("cloud-download")
        )

    if WF.cached_data('cask_not_installed', cask_not_installed, max_age=0):
        WF.add_item(
            'Cask does not seem to be installed!',
            'Hit enter to see what you need to do...',
            arg='open http://caskroom.io/ && exit',
            valid=True,
            icon='cask.png'
        )
        WF.add_item(
            'I trust this workflow',
            'Hit enter to install cask...',
            arg='brew install caskroom/cask/brew-cask',
            valid=True,
            icon='cask.png'
        )
        # delete cached file
开发者ID:apoleshchuk,项目名称:alfred-homebrew,代码行数:33,代码来源:cask.py

示例15: is_dark

# 需要导入模块: from workflow import Workflow [as 别名]
# 或者: from workflow.Workflow import cached_data [as 别名]
def is_dark():
    return min([int(x) for x in WF.alfred_env['theme_background'][5:-6].split(',')]) < 128


if __name__ == '__main__':
    from cask_actions import ACTIONS

    if WF.update_available:
        WF.add_item(
            "An update is available!",
            autocomplete='workflow:update',
            valid=False,
            icon=get_icon("cloud-download")
        )

    if WF.cached_data('cask_not_installed', cask_not_installed, max_age=0):
        WF.add_item('Cask does not seem to be installed!',
                    'Hit enter to see what you need to do...', arg='open http://caskroom.io/ && exit', valid=True)
        WF.add_item('I trust this workflow',
                    'Hit enter to install cask...', arg='brew install caskroom/cask/brew-cask', valid=True)
        # delete cached file
        WF.cache_data('cask_not_installed', None)
    else:
        # extract query
        query = WF.args[0] if len(WF.args) else None

        if query and query.startswith('install'):
            for formula in get_all_casks(query):
                WF.add_item(
                    formula, "Install cask",
                    arg='brew cask install %s' % formula,
开发者ID:rianrainey,项目名称:alfred-homebrew,代码行数:33,代码来源:cask.py


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