forked from albertlauncher/python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom_projects.py
67 lines (51 loc) · 1.75 KB
/
atom_projects.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
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
"""List and open your Atom projects.
Synopsis: <trigger> [filter]"""
import os
import re
import time
from pathlib import Path
from shutil import which
import cson
from albertv0 import *
__iid__ = "PythonInterface/v0.1"
__prettyname__ = "Atom Projects"
__version__ = "1.0"
__trigger__ = "atom "
__author__ = "Manuel Schneider"
__dependencies__ = ["python-cson"]
projects_file = str(Path.home()) + "/.atom/projects.cson"
if which("atom") is None:
raise Exception("'atom' is not in $PATH.")
iconPath = iconLookup('atom')
mtime = 0
projects = []
def updateProjects():
global mtime
try:
new_mtime = os.path.getmtime(projects_file)
except Exception as e:
warning("Could not get mtime of file: " + projects_file + str(e))
if mtime != new_mtime:
mtime = new_mtime
with open(projects_file) as projects_cson:
global projects
projects = cson.loads(projects_cson.read())
def handleQuery(query):
if not query.isTriggered:
return
updateProjects()
stripped = query.string.strip()
items = []
for project in projects:
if re.search(stripped, project['title'], re.IGNORECASE):
items.append(Item(id=__prettyname__ + project['title'],
icon=iconPath,
text=project['title'],
subtext="Group: %s" % (project['group'] if 'group' in project else "None"),
completion=query.rawString,
actions=[
ProcAction(text="Open project in Atom",
commandline=["atom"] + project['paths'])
]))
return items