-
Notifications
You must be signed in to change notification settings - Fork 1
/
weeklyStatus.py
executable file
·149 lines (131 loc) · 4.77 KB
/
weeklyStatus.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#! /usr/bin/env python
# coding=UTF-8
import appscript
import datetime
import re
import subprocess
import sys
try:
import sublime_plugin
except:
class sublime_plugin(object):
class TextCommand(object):
pass
class StdoutView(object):
def insert(self, edit, region, data):
sys.stdout.write(data)
# Coordination!
coordination = [
"Talk to Shorlander about search prototype ideas."
]
class WeeklyStatusCommand(sublime_plugin.TextCommand):
def __init__(self, showWeek):
self.indent = 0
self.insert = []
self.showWeek = showWeek
def print_name(self, key, suffix=""):
self.insert.append(self.indent * " " + "* ")
self.insert.append(key.encode("utf-8"))
self.insert.append(suffix + "\n")
def gather_todos(self, things, list, future=False):
todos = things.lists.ID(list)().to_dos()
rv = {}
days = 1
today = datetime.date.today()
if today.weekday() == 0:
days = 3
if self.showWeek:
days = 27
yesterday = datetime.datetime.combine(
today - datetime.timedelta(days=days),
datetime.time(0))
for todo in todos:
if todo.name() == "Update my status!":
if not future and self.showWeek:
break
continue
if not future and todo.completion_date() < yesterday:
break
if self.mozTag in todo.tags():
area = ""
if todo.project():
area = todo.project.name()
elif todo.area():
area = todo.area.name()
if area == "":
area = "Work"
rv.setdefault(area, []).append(todo)
return rv
def print_area(self, area, values):
if area != "Work":
self.print_name(area, ":")
self.indent += 2
values.reverse()
else:
self.print_name("Other:")
self.indent += 2
values.sort(key=lambda v: v.name())
# coallesce items that contain "bug", and start with the same prefix.
names = []
vnames = {}
for value in values:
name = value.name()
index = name.find("bug")
if index != -1:
prefix = name[:index]
bug = name[index:]
if bug.endswith("."):
bug = bug[:-1]
vnames.setdefault(prefix, []).extend([", ", bug])
else:
names.append(name)
# and put them at the end.
for name in sorted(vnames.keys()):
bugs = vnames[name][1:]
if len(bugs) > 1:
bugs[-2] = " and "
names.append(name + "".join(bugs) + ".")
for name in names:
self.print_name(name)
self.indent -= 2
self.insert.append('\n')
def run(self, edit):
things = appscript.app("Things")
tags = things.tags()
self.mozTag = None
for tag in tags:
if tag.name() == "Mozilla":
self.mozTag = tag
break
self.insert.append("-----------------\n\n")
areas = self.gather_todos(things, u"FocusLogbook")
for area in sorted(areas.keys()):
self.print_area(area, areas[area])
self.insert.append("-----------------\n\n")
areas = self.gather_todos(things, u"FocusToday", True)
for area in sorted(areas.keys()):
self.print_area(area, areas[area])
self.insert.append("-----------------\n\n")
self.insert.extend(["* %s\n" % person for person in coordination])
self.insert.append("-----------------\n")
self.insert = u"".join([x.decode("utf-8") for x in self.insert])
# self.insert = self.insert.replace(u"…", u"...").replace(u"”", u'"')
# .replace(u"“", u'"')
self.view.insert(edit, 0, "".join(self.insert))
class HgPdiffCommand(sublime_plugin.TextCommand):
def run(self, edit):
process = subprocess.Popen('cd ' + self.view.window().folders()[0] +
';/usr/local/bin/hg pdiff', shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = process.communicate()
if process.returncode == 0:
self.view.insert(edit, 0, out)
self.view.set_syntax_file(u'Packages/Diff/Diff.tmLanguage')
else:
self.view.insert(edit, 0, err)
self.view.set_syntax_file(u'Packages/Text/Plain text.tmLanguage')
if __name__ == "__main__":
cmd = WeeklyStatusCommand(sys.argv[-1] != "-d")
cmd.view = StdoutView()
cmd.run(None)