mod_hg.py

Mon, 19 Jan 2015 16:42:36 -0500

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 19 Jan 2015 16:42:36 -0500
changeset 120
9880bb697149
parent 117
6c0609395889
child 121
ac07779f788d
permissions
-rw-r--r--

- added doomseeker support, fixed up mod_bridge, now shortens new commit links with bit.ly

72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 from hgapi import hgapi, Repo
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
2 from datetime import datetime
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 import hgpoll as HgPoll
74
9f14fb6995ff - added a missing import..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
4 import re
76
a2fe9ba3041a - various fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 75
diff changeset
5 import bt as Bt
a2fe9ba3041a - various fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 75
diff changeset
6 from configfile import Config
113
08e9b1c1b324 - added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
7 from modulecore import command_error
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 ModuleData = {
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 'commands':
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 [
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 {
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 'name': 'checkhg',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 'description': 'Polls the zandronum repositories for updates',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 'args': None,
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 'level': 'admin',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 },
117
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
18
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 {
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 'name': 'cset',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 'description': 'Yields changeset information (use a hash or date as key)',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 'args': '<key>',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 'level': 'normal',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 },
117
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
25
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 {
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 'name': 'hg',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 'description': 'Executes a hg command',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 'args': '<repo> <command...>',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 'level': 'admin',
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
31 },
117
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
32
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
33 {
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
34 'name': 'resolves',
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
35 'description': 'Manually cause a ticket to be resolved by a changeset',
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
36 'args': '<ticket> <changeset>',
117
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
37 'level': 'admin', # TODO
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
38 },
117
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
39
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
40 {
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
41 'name': 'compress',
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
42 'description': 'Compresses a head on the sandbox repositories.',
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
43 'args': '<changeset>',
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
44 'level': 'admin', # TODO
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
45 }
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 ]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 }
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48
76
a2fe9ba3041a - various fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 75
diff changeset
49 def plural (a):
a2fe9ba3041a - various fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 75
diff changeset
50 return '' if a == 1 else 's'
a2fe9ba3041a - various fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 75
diff changeset
51
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 def cmd_checkhg (bot, **rest):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 HgPoll.force_poll()
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54
113
08e9b1c1b324 - added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
55 def cmd_cset (bot, args, reply, **rest):
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 repo = Repo ('zandronum-everything')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 data = ""
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 node = args['key']
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 # Possibly we're passed a date version instead. Try find the node for this.
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 try:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 datetime.strptime (args['key'], '%y%m%d-%H%M')
76
a2fe9ba3041a - various fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 75
diff changeset
63 HgPoll.make_commits_txt()
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 commits_txt = open ('commits.txt', 'r')
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
65
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 for line in commits_txt:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 data = line.replace ('\n', '').split (' ')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 if data[1] == args['key']:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 node = data[0]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 break
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 else:
113
08e9b1c1b324 - added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
72 command_error ('couldn\'t find changeset for date %s' % args['key'])
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 return
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 except ValueError:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 pass
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
76
113
08e9b1c1b324 - added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
77 # zandronum-everything contains all zandronum changesets, so look for changesets in that.
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 try:
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
79 data = repo.hg_command ("log", "-l1", "-r", node, "--template",
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
80 "{node|short}@@@@@@@" +
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
81 "{desc}@@@@@@@" +
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
82 "{author}@@@@@@@" +
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
83 "{diffstat}@@@@@@@" +
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
84 "{date|hgdate}@@@@@@@" +
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
85 "{bookmarks}@@@@@@@" +
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
86 "{latesttagdistance}@@@@@@@" +
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
87 "{latesttag}")
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 except hgapi.HgException:
113
08e9b1c1b324 - added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
89 command_error ('couldn\'t find changeset %s' % (node))
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 return
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
91
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 try:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 data = data.split ('@@@@@@@')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 node = data[0]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 message = data[1]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 author = data[2]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 diffstat = data[3]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 date = datetime.utcfromtimestamp (int (data[4].split (' ')[0]))
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
99 bookmarks = data[5]
113
08e9b1c1b324 - added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
100 latesttagdistance = int (data[6])
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
101 latesttag = data[7]
82
c6e853703ca8 - fixed bad age message in .cset
Teemu Piippo <crimsondusk64@gmail.com>
parents: 80
diff changeset
102 delta = datetime.utcnow() - date
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 datestring = ''
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
104
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
105 if bookmarks:
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
106 bookmarks = HgPoll.prettify_bookmarks (bookmarks)
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
107
80
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
108 # Find out the Zandronum version of this changeset
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
109 repo.hg_command ('revert', '-r', node, 'src/version.h')
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
110 zanversion = '<unknown zandronum version>'
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
111
80
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
112 with open ('zandronum-everything/src/version.h') as version_file:
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
113 regexps = [ \
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
114 re.compile (r'#define\s+GAMEVER_STRING\s+"([^"]+)"'), \
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
115 re.compile (r'#define\s+DOTVERSIONSTR_NOREV\s+"([^"]+)"'), \
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
116 re.compile (r'#define\s+DOTVERSIONSTR\s+"([^"]+)"')]
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
117
80
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
118 for line in version_file:
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
119 for rex in regexps:
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
120 match = rex.match (line)
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
121 if match != None:
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
122 zanversion = match.group (1)
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
123 break
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
124
80
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
125 if match != None:
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
126 break
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
127
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
128
80
0f6bfd359a7f - .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
129 repo.hg_command ('revert', '--all')
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
130
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 # Remove the email address from the author if possible
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 match = re.compile (r'^(.+) <([^>]+)>$.*').match (author)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 if match:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 author = match.group (1)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 email = match.group (2)
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
136
76
a2fe9ba3041a - various fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 75
diff changeset
137 username = Config.find_developer_by_email (email)
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
138
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 if username != '':
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 author = username
110
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
141
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
142 # Try prettify the diffstat
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
143 rex = re.compile (r'^([0-9]+): \+([0-9]+)/-([0-9]+)$')
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
144 match = rex.match (diffstat)
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
145
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
146 if match:
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
147 diffstat = "%s\003:\0033 +%s\003/\0034-%s\003" % (match.group (1), match.group (2), match.group (3))
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
148
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 if delta.days < 4:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 if delta.days == 0:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 if delta.seconds < 60:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 datestring = 'just now'
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 elif delta.seconds < 3600:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 minutes = delta.seconds / 60
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 datestring = '%d minute%s ago' % (minutes, plural (minutes))
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 else:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 hours = delta.seconds / 3600
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 datestring = '%d hour%s ago' % (hours, plural (hours))
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 else:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 datestring = '%d day%s ago' % (delta.days, plural (delta.days))
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 else:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 datestring = 'on %s' % (str (date))
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
163
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
164 versionstring = ""
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
165 if latesttagdistance != 0:
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
166 versionstring = '%s %s, %d hops from %s' % (zanversion, date.strftime ('%y%m%d-%H%M'), latesttagdistance, latesttag)
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
167 else:
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
168 versionstring = latesttag
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
169
113
08e9b1c1b324 - added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
170 reply ('changeset\0035 %s%s\003 (%s)\003: committed by\0032 %s\003 %s,\0032 %s' % \
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
171 (node, bookmarks, versionstring, author, datestring, diffstat))
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
172
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173 for line in message.split ('\n'):
113
08e9b1c1b324 - added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
174 reply (' ' + line)
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 except hgapi.HgException as e:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 result = HgPoll.decipher_hgapi_error (e)
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
177
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 if result[0]:
113
08e9b1c1b324 - added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
179 command_error (result[1])
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 else:
113
08e9b1c1b324 - added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
181 command_error (`e`)
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182
117
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
183 def cmd_hg (bot, args, reply, **rest):
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 try:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 repo = hgapi.Repo (args['repo'])
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 result = repo.hg_command (*args['command'])
117
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
187 reply (result)
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 except hgapi.hgapi.HgException as e:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 result = HgPoll.decipher_hgapi_error (e)
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
190
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 if result[0]:
113
08e9b1c1b324 - added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
192 command_error (result[1])
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 else:
113
08e9b1c1b324 - added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
194 command_error (`e`)
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
195
117
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
196 def cmd_resolves (bot, args, **rest):
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
197 try:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
198 HgPoll.announce_ticket_resolved (args['ticket'], args['changeset'])
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
199 except Exception as e:
113
08e9b1c1b324 - added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
200 command_error (str (e))

mercurial