-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcommon.py
60 lines (49 loc) · 1.44 KB
/
common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# -*- coding: utf-8 -*-
__author__ = 'eveliotc'
__license__ = 'See LICENSE'
import alfred
from alfred import Item
import sys
from subprocess import Popen, PIPE
def json_to_obj(x):
if isinstance(x, dict):
return type('X', (), {k: json_to_obj(v) for k, v in x.iteritems()})
else:
return x
def join_query(dic):
return ' '.join(dic)
def le_result(r, exit = True):
alfred.write(r)
if exit:
sys.exit()
def xml_result(r, exit = True):
if len(r) < 1:
empty_result(exit)
else:
le_result(alfred.xml(r), exit)
def empty_result(exit = True):
empty = Item(
attributes={'uid': alfred.uid('empty'), 'arg': ''},
title='Gradle Please',
subtitle=u':( Nothing found.',
icon=u'icon.png')
xml_result([empty], exit)
def apple_script(scpt, args=[]):
p = Popen(['osascript', '-'] + args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate(scpt)
return stdout
def tell_alfred(what):
apple_script('tell application "Alfred 2" to search "%s"' % what)
# TODO refactor gp.py to use this instead of dynamic obj
class Pom(object):
a = ''
g = ''
p = ''
latestVersion = ''
source = ''
@property
def id(self):
return self.g + ':' + self.a
def __repr__(self):
#notjson #justdebugginthings
return '{id:%s a:%s g:%s p:%s v:%s}' % (self.id, self.a, self.g, self.p, self.latestVersion)