44.1.8
by Daniel Holbach
* setup.py, 5-a-day, add-5-a-day, update-signature, |
1 |
import textwrap |
2 |
import time |
|
56
by Daniel Holbach
* 5-a-day, data/bash_completion/5-a-day, fiveaday/bzr.py, fiveaday/files.py, |
3 |
import sys |
44.1.8
by Daniel Holbach
* setup.py, 5-a-day, add-5-a-day, update-signature, |
4 |
import os |
5 |
||
65
by Daniel Holbach
* 5-a-day, 5-a-day-applet, data/5-a-day-applet.glade, fiveaday/bzr.py, |
6 |
from gettext import gettext as _ |
7 |
||
44.1.8
by Daniel Holbach
* setup.py, 5-a-day, add-5-a-day, update-signature, |
8 |
import files |
9 |
||
105
by Daniel Holbach
* fiveaday/core.py, 5-a-day, fiveaday/core.py, fiveaday/files.py, |
10 |
from core import Core |
11 |
c = Core() |
|
12 |
||
44.1.8
by Daniel Holbach
* setup.py, 5-a-day, add-5-a-day, update-signature, |
13 |
def get_affected_srcpkgs(bug): |
14 |
lpbugs = False |
|
15 |
try: |
|
16 |
import launchpadbugs.connector as Connector |
|
17 |
Bug = Connector.ConnectBug(method="Text") |
|
18 |
lpbugs = True |
|
19 |
except: |
|
65
by Daniel Holbach
* 5-a-day, 5-a-day-applet, data/5-a-day-applet.glade, fiveaday/bzr.py, |
20 |
print _("""Warning: Please install python-launchpad-bugs |
21 |
It will add more information about the bug to your signature.""") |
|
44.1.8
by Daniel Holbach
* setup.py, 5-a-day, add-5-a-day, update-signature, |
22 |
|
23 |
try: |
|
24 |
affects = set(map(lambda a: a.affects.longname.lower(), |
|
25 |
Bug(int(bug)).infotable)) |
|
26 |
affects = filter(lambda a: a.count("ubuntu"), affects) |
|
27 |
affects = map(lambda a: a.replace(" (ubuntu)", ""), affects) |
|
44.1.14
by Daniel Holbach
* fiveaday/signature.py: work around Bug 210571. |
28 |
except: |
44.1.8
by Daniel Holbach
* setup.py, 5-a-day, add-5-a-day, update-signature, |
29 |
affects = None |
30 |
||
31 |
return affects |
|
57
by Daniel Holbach
* fiveaday/signature.py: make signature work with new time format. |
32 |
|
33 |
||
34 |
def get_int(s): |
|
35 |
i = None |
|
36 |
try: |
|
37 |
i = int(s) |
|
38 |
except: |
|
39 |
pass
|
|
40 |
return i |
|
41 |
||
42 |
||
43 |
def generate_signature(log, date): |
|
44 |
d = time.localtime(date) |
|
45 |
date_str = "%s-%s-%s" % (d[0], d[1], d[2]) |
|
46 |
is_right_date = lambda a: str(a).startswith(date_str) or \ |
|
47 |
(get_int(a.split()[0]) and \ |
|
48 |
get_int(a.split()[0]) > date-24*60*60) |
|
49 |
log = set(filter(is_right_date, log)) |
|
44.1.8
by Daniel Holbach
* setup.py, 5-a-day, add-5-a-day, update-signature, |
50 |
if len(log)>5: |
51 |
log = list(log)[-5:] |
|
52 |
text = "My 5 today: " |
|
53 |
html = """ |
|
54 |
<font color='lightslategray'>-- <br />My 5 today: """
|
|
55 |
for line in log: |
|
56 |
bugnr = line.split()[1] |
|
57 |
srcpkgs = "" |
|
58 |
affects = get_affected_srcpkgs(bugnr) |
|
59 |
if affects: |
|
60 |
srcpkgs = str(", ".join(affects)) |
|
61 |
text += "#%s (%s), " % (bugnr, srcpkgs) |
|
62 |
html += "#<a href='https://launchpad.net/bugs/%s'>%s</a> (%s), " % (bugnr, bugnr, srcpkgs) |
|
63 |
else: |
|
64 |
text += "#%s, " % (bugnr) |
|
65 |
html += "#<a href='https://launchpad.net/bugs/%s'>%s</a>, " % (bugnr, bugnr) |
|
66 |
text = "\n".join(textwrap.wrap(text[:-2], 70)) |
|
67 |
html = html[:-2] |
|
68 |
text += """ |
|
69 |
Do 5 a day - every day! https://wiki.ubuntu.com/5-A-Day\n""" |
|
70 |
html += """<br />Do 5 a day - every day! <a href='https://wiki.ubuntu.com/5-A-Day'>https://wiki.ubuntu.com/5-A-Day</a><br /></font>""" |
|
71 |
||
72 |
return (text, html) |
|
73 |
||
74 |
||
103.1.4
by Benjamin Drung
fix double usage of html variable in signature.update |
75 |
def update(show_html, yesterday): |
44.1.8
by Daniel Holbach
* setup.py, 5-a-day, add-5-a-day, update-signature, |
76 |
log = files.LogFile() |
56
by Daniel Holbach
* 5-a-day, data/bash_completion/5-a-day, fiveaday/bzr.py, fiveaday/files.py, |
77 |
if not log: |
78 |
print >> sys.stderr, \ |
|
65
by Daniel Holbach
* 5-a-day, 5-a-day-applet, data/5-a-day-applet.glade, fiveaday/bzr.py, |
79 |
_("You need to use 5-a-day --add first to add a few bug reports to your list.") |
56
by Daniel Holbach
* 5-a-day, data/bash_completion/5-a-day, fiveaday/bzr.py, fiveaday/files.py, |
80 |
sys.exit(1) |
44.1.8
by Daniel Holbach
* setup.py, 5-a-day, add-5-a-day, update-signature, |
81 |
files.preserve_old_signature() |
82 |
||
103.1.1
by Benjamin Drung
parse options with getopt (LP: #218074) |
83 |
if yesterday: |
57
by Daniel Holbach
* fiveaday/signature.py: make signature work with new time format. |
84 |
date = time.time()-24*3600 |
44.1.8
by Daniel Holbach
* setup.py, 5-a-day, add-5-a-day, update-signature, |
85 |
else: |
57
by Daniel Holbach
* fiveaday/signature.py: make signature work with new time format. |
86 |
date = time.time() |
87 |
||
88 |
(text, html) = generate_signature(log.entries, date) |
|
105
by Daniel Holbach
* fiveaday/core.py, 5-a-day, fiveaday/core.py, fiveaday/files.py, |
89 |
f = open(c.signature_file, "a") |
90 |
if os.path.exists(c.old_signature_file): |
|
91 |
f.write(open(c.old_signature_file).read()) |
|
44.1.8
by Daniel Holbach
* setup.py, 5-a-day, add-5-a-day, update-signature, |
92 |
f.write("\n") |
93 |
f.write(text) |
|
94 |
f.close() |
|
95 |
||
103.1.4
by Benjamin Drung
fix double usage of html variable in signature.update |
96 |
if show_html: |
44.1.8
by Daniel Holbach
* setup.py, 5-a-day, add-5-a-day, update-signature, |
97 |
print html |
98 |
||
99 |
return 0 |
|
100 |