예제 #1
0
def notify(title, text=''):
    """Show a notification."""
    if not boolvar('SHOW_NOTIFICATIONS'):
        return

    v = Variables(title=title, text=text)
    print(v)
예제 #2
0
def test_variables_multiple_args(infopl):
    """Variables: multiple args."""
    arg = ['one', 'two']
    js = '{"alfredworkflow": {"arg": ["one", "two"]}}'
    v = Variables(arg=arg)
    assert v.obj == {'alfredworkflow': {'arg': arg}}
    assert str(v) == js
    assert unicode(v) == js
예제 #3
0
def main(wf):
    snippet_body = os.getenv("snippetBody")

    # var_names = os.getenv("varNames").split()

    variables = {}

    # for var_name in var_names:
    #     variables.update({var_name : os.getenv(var_name)})

    v = Variables(**variables)

    v.config = {
        "clipboardtext" : snippet_body
    }

    print(v)
예제 #4
0
def test_variables_multiple_args(infopl):
    """Variables: multiple args."""
    arg = ["one", "two"]
    js = '{"alfredworkflow": {"arg": ["one", "two"]}}'
    v = Variables(arg=arg)
    assert v.obj == {"alfredworkflow": {"arg": arg}}
    assert str(v) == js
    assert str(v) == js
예제 #5
0
def test_variables_unicode():
    """Unicode handled correctly."""
    v = Variables(arg="fübar", englisch="englisch")
    v["französisch"] = "französisch"
    v.config["über"] = "über"
    d = {
        "alfredworkflow": {
            "arg": "fübar",
            "variables": {"englisch": "englisch", "französisch": "französisch"},
            "config": {"über": "über"},
        }
    }
    print((repr(v.obj)))
    print((repr(d)))
    assert v.obj == d

    # Round-trip to JSON and back
    d2 = json.loads(str(v))
    assert d2 == d
예제 #6
0
def main(wf):
    try:
        data = wf.args[0].split(" ")
        if len(data) != 2:
            return 1

        [key, value] = data
        wf.logger.debug('Saving %r', key)

        if key in ['user', 'org']:
            wf.store_data(key, value)
            print(Variables('Set your %s to "%s"' % (key, value)))
        elif key == 'token':
            wf.save_password('ghpr-api-key', value)
            print(Variables('Saved your API token in Keychain'))
        else:
            return 1
    except Exception as err:
        wf.logger.debug('err=%r', err)
        return 1
예제 #7
0
def test_variables_unicode():
    """Unicode handled correctly."""
    v = Variables(arg=u'fübar', englisch='englisch')
    v[u'französisch'] = u'französisch'
    v.config[u'über'] = u'über'
    d = {
        'alfredworkflow':
            {
                'arg': u'fübar',
                'variables': {
                    'englisch': u'englisch',
                    u'französisch': u'französisch',
                },
                'config': {u'über': u'über'}
            }
    }
    print(repr(v.obj))
    print(repr(d))
    assert v.obj == d

    # Round-trip to JSON and back
    d2 = json.loads(unicode(v))
    assert d2 == d
예제 #8
0
def test_variables_unicode():
    """Unicode handled correctly."""
    v = Variables(arg=u'fübar', englisch='englisch')
    v[u'französisch'] = u'französisch'
    v.config[u'über'] = u'über'
    d = {
        'alfredworkflow':
            {
                'arg': u'fübar',
                'variables': {
                    'englisch': u'englisch',
                    u'französisch': u'französisch',
                },
                'config': {u'über': u'über'}
            }
    }
    print(repr(v.obj))
    print(repr(d))
    assert v.obj == d

    # Round-trip to JSON and back
    d2 = json.loads(unicode(v))
    assert d2 == d
예제 #9
0
def do_toggle_alfred_sorts(wf):
    """Toggle "Alfred sorts results" setting."""
    ctx = Context(wf)
    v = ctx.getbool('ALFRED_SORTS_RESULTS')
    if v:
        new = '0'
        status = 'off'
    else:
        new = '1'
        status = 'on'

    log.debug('turning "ALFRED_SORTS_RESULTS" %s ...', status)
    set_config('ALFRED_SORTS_RESULTS', new)

    print(Variables(title='Alfred sorts results', text='Turned ' + status))
예제 #10
0
def do_toggle_show_query(wf):
    """Toggle "show query in results" setting."""
    ctx = Context(wf)
    v = ctx.getbool('SHOW_QUERY_IN_RESULTS')
    if v:
        new = '0'
        status = 'off'
    else:
        new = '1'
        status = 'on'

    log.debug('turning "SHOW_QUERY_IN_RESULTS" %s ...', status)
    set_config('SHOW_QUERY_IN_RESULTS', new)

    print(Variables(title='Show query in results', text='Turned ' + status))
예제 #11
0
def test_variables_empty():
    """Empty Variables returns empty string."""
    v = Variables()
    assert unicode(v) == u''
    assert str(v) == ''
예제 #12
0
def test_variables_plain_arg():
    """Arg-only returns string, not JSON."""
    v = Variables(arg=u'test')
    assert unicode(v) == u'test'
    assert str(v) == 'test'
예제 #13
0
def test_variables_empty():
    """Empty Variables returns empty string."""
    v = Variables()
    assert str(v) == ""
    assert str(v) == ""
예제 #14
0
def test_variables_plain_arg():
    """Arg-only returns string, not JSON."""
    v = Variables(arg="test")
    assert str(v) == "test"
    assert str(v) == "test"
예제 #15
0
def test_variables():
    """Set variables correctly."""
    v = Variables(a=1, b=2)
    assert v.obj == {'alfredworkflow': {'variables': {'a': 1, 'b': 2}}}
예제 #16
0
def test_variables_config():
    """Set config correctly."""
    v = Variables()
    v.config['var'] = 'val'
    assert v.obj == {'alfredworkflow': {'config': {'var': 'val'}}}
예제 #17
0
def test_variables():
    """Set variables correctly."""
    v = Variables(a=1, b=2)
    assert v.obj == {"alfredworkflow": {"variables": {"a": 1, "b": 2}}}
예제 #18
0
def test_variables_config():
    """Set config correctly."""
    v = Variables()
    v.config['var'] = 'val'
    assert v.obj == {'alfredworkflow': {'config': {'var': 'val'}}}
예제 #19
0
def test_variables_config():
    """Set config correctly."""
    v = Variables()
    v.config["var"] = "val"
    assert v.obj == {"alfredworkflow": {"config": {"var": "val"}}}
예제 #20
0
def return_for_flow(result):
    v = Variables(result)
    print(v)
예제 #21
0
#!/usr/bin/python
# encoding: utf-8

import sys, os, json

from subprocess import Popen, PIPE, CalledProcessError
from workflow import Workflow3, Variables
from workflow.util import run_command

log = None
v = Variables()

# With 1Password session key and a vault item UUID, request info for that item
def main(wf):
	# Get cached 1Password session key
	session_key = wf.stored_data('session_key')
	if session_key is None:
		v.arg = 'Vault authentication has expired or is not valid'
		return
	
	args = wf.args
	op = args[0]
	jq = args[1]
	uuid = args[2]
	action = args[3]
	
	# Issue bash command to request item info from 1Password
	item_raw = None
	return_code = 0
	try:
		command_output = Popen([op, 'get', 'item', uuid, '--session', session_key], stdout=PIPE)