Exemplo n.º 1
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv, 'v:c:q:', ['vendor', 'command', 'query'])
    except getopt.error:
        sys.exit(2)

    vendor = None
    command = None
    query = None

    for opt, arg in opts:
        if opt in ('-v', '--vendor'):
            vendor = arg.strip()
        elif opt in ('-c', '--command'):
            command = arg.strip()
        elif opt in ('-q', '--query'):
            query = arg.strip()

    if vendor and command:
        workflow = alfred.Workflow()
        provider = core.providers.create(vendor, workflow.settings)

        icon = provider.icon

        if command == 'get.profiles':
            profile = provider.profile

            results = map(lambda x: workflow.feedback.Item(
                attributes={'uid': workflow.uid(), 'arg': x['name'], 'valid': u'yes'},
                icon=icon,
                title=x['title'] if x['name'] != profile else u'* %s' % x['title'],
                subtitle=x['full_path']
            ), provider.get_profiles(query))

            if not results:
                results = workflow.feedback.Item(
                    attributes={'uid': workflow.uid(), 'valid': u'no'},
                    icon=icon,
                    title=u'No profiles found',
                    subtitle=u'No profiles were found'
                )

            workflow.feedback.add(results)

            xml = workflow.feedback.to_xml()

            alfred.write(xml)
        elif command == 'set.profile':
            provider.settings.set({'profile': query})
            provider.settings.save()

            alfred.write(u'Now %s uses the "%s" profile' % (provider.name, query))
Exemplo n.º 2
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv, 'v:c:q:', ['vendor', 'command', 'query'])
    except getopt.error:
        sys.exit(2)

    vendor = None
    command = None
    query = None

    for opt, arg in opts:
        if opt in ('-v', '--vendor'):
            vendor = arg.strip()
        elif opt in ('-c', '--command'):
            command = arg.strip()
        elif opt in ('-q', '--query'):
            query = arg.strip()

    if vendor and command:
        workflow = alfred.Workflow()
        provider = core.providers.create(vendor, workflow.settings)

        icon = provider.icon

        if command == 'get.bookmarks':
            result = map(lambda x: workflow.feedback.Item(
                attributes={'uid': workflow.uid(), 'arg': x['url'], 'valid': u'yes'},
                icon=icon,
                title=x['title'],
                subtitle=x['url']
            ), provider.get_bookmarks(query))

            if not result:
                result = workflow.feedback.Item(
                    attributes={'uid': workflow.uid(), 'valid': u'no'},
                    icon=icon,
                    title=u'No bookmarks found',
                    subtitle=u'No bookmarks matching your query were found'
                )

            workflow.feedback.add(result)

            xml = workflow.feedback.to_xml()

            alfred.write(xml)
Exemplo n.º 3
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv, 'v:c:q:',
                                   ['vendor', 'command', 'query'])
    except getopt.error:
        sys.exit(2)

    vendor = None
    command = None
    query = None

    for opt, arg in opts:
        if opt in ('-v', '--vendor'):
            vendor = arg.strip()
        elif opt in ('-c', '--command'):
            command = arg.strip()
        elif opt in ('-q', '--query'):
            query = arg.strip()

    if vendor and command:
        workflow = alfred.Workflow()
        provider = core.providers.create(vendor, workflow.settings)

        icon = provider.icon

        if command == 'get.profiles':
            profile = provider.profile

            result = map(
                lambda x: workflow.feedback.Item(attributes={
                    'uid': workflow.uid(),
                    'arg': x['name'],
                    'valid': u'yes'
                },
                                                 icon=icon,
                                                 title=x['name']
                                                 if x['name'] != profile else
                                                 u'* %s' % x['name'],
                                                 subtitle=x['full_path']),
                provider.get_profiles(query))

            if not result:
                result = workflow.feedback.Item(
                    attributes={
                        'uid': workflow.uid(),
                        'valid': u'no'
                    },
                    icon=icon,
                    title=u'No profiles found',
                    subtitle=u'No profiles were found')

            workflow.feedback.add(result)

            xml = workflow.feedback.to_xml()

            alfred.write(xml)
        elif command == 'set.profile':
            provider.settings.set({'profile': query})
            provider.settings.save()

            alfred.write(u'Now %s uses the "%s" profile' %
                         (provider.name, query))