Mon, 04 May 2015 02:19:21 +0300
Added scientific notation and dice expressions (cheaply as operators)
124
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
1 | ''' |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
2 | Copyright 2014-2015 Teemu Piippo |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
3 | All rights reserved. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
4 | |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
5 | Redistribution and use in source and binary forms, with or without |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
6 | modification, are permitted provided that the following conditions |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
7 | are met: |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
8 | |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
9 | 1. Redistributions of source code must retain the above copyright |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
10 | notice, this list of conditions and the following disclaimer. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
11 | 2. Redistributions in binary form must reproduce the above copyright |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
12 | notice, this list of conditions and the following disclaimer in the |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
13 | documentation and/or other materials provided with the distribution. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
14 | 3. The name of the author may not be used to endorse or promote products |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
15 | derived from this software without specific prior written permission. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
16 | |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
27 | ''' |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
28 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | from hgapi import hgapi, Repo |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
30 | from datetime import datetime |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | import hgpoll as HgPoll |
74
9f14fb6995ff
- added a missing import..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
32 | import re |
76 | 33 | import bt as Bt |
34 | 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
|
35 | from modulecore import command_error |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | ModuleData = { |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | 'commands': |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | [ |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | { |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | 'name': 'checkhg', |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | 'description': 'Polls the zandronum repositories for updates', |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | 'args': None, |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | 'level': 'admin', |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | }, |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
46 | |
72
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 | 'name': 'cset', |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | '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
|
50 | 'args': '<key>', |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | 'level': 'normal', |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | }, |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
53 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | { |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | 'name': 'hg', |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | 'description': 'Executes a hg command', |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | 'args': '<repo> <command...>', |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | 'level': 'admin', |
87 | 59 | }, |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
60 | |
87 | 61 | { |
62 | 'name': 'resolves', | |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
63 | 'description': '''Manually cause a ticket to be resolved by a changeset''', |
87 | 64 | 'args': '<ticket> <changeset>', |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
65 | 'level': 'admin', # TODO |
87 | 66 | }, |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
67 | |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
68 | { |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
69 | 'name': 'rebuildcommitsdb', |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
70 | 'description': '''Rebuilds commits.db''', |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
71 | 'args': None, |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
72 | 'level': 'admin', |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
73 | }, |
132 | 74 | |
75 | { | |
76 | 'name': 'updatezadevtopic', | |
77 | 'description': """Updates #zadev topic""", | |
78 | 'args': None, | |
79 | 'level': 'admin', | |
80 | }, | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | ] |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | } |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | |
76 | 84 | def plural (a): |
85 | return '' if a == 1 else 's' | |
86 | ||
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | def cmd_checkhg (bot, **rest): |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | HgPoll.force_poll() |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
90 | def is_dateversion (key): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
91 | try: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
92 | datetime.strptime (key, '%y%m%d-%H%M') |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
93 | return True |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
94 | except ValueError: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
95 | return False |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
96 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
97 | def resolve_node (node): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
98 | reponame = None |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
99 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
100 | if '/' in node: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
101 | reponame, node = node.split ('/')[0:2] |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
102 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
103 | if reponame not in HgPoll.all_repo_names(): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
104 | command_error ('''unknown repository %s''' % reponame) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | # Possibly we're passed a date version instead. Try find the node for this. |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
107 | if is_dateversion (node): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
108 | node = HgPoll.g_CommitsDb.find_commit_by_dateversion (node) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
109 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
110 | if node == None: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
111 | command_error ('''couldn't find changeset for date %s''' % node) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
112 | return |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
113 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
114 | node = node[0:7] |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
115 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
116 | noderepos = HgPoll.g_CommitsDb.get_commit_repos (node) |
111 | 117 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
118 | if reponame == None: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
119 | if not noderepos: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
120 | command_error ('''couldn't find changeset %s''' % node) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
121 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
122 | reponame = noderepos[0] |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
123 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
124 | return (node, reponame) |
111 | 125 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
126 | def cmd_cset (bot, args, reply, **rest): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
127 | data = "" |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
128 | node, reponame = resolve_node (args['key']) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
129 | repourl = HgPoll.get_repo_info (reponame).get_value ('url') |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
130 | repo = Repo (reponame) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
131 | delim = '@@@@@@@@@@@@' |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
132 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | try: |
112 | 134 | data = repo.hg_command ("log", "-l1", "-r", node, "--template", |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
135 | delim.join (["{node|short}", |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
136 | "{desc}", |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
137 | "{author}", |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
138 | "{diffstat}", |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
139 | "{date|hgdate}", |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
140 | "{bookmarks}", |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
141 | "{latesttagdistance}", |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
142 | "{latesttag}"])).split (delim) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | except hgapi.HgException: |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
144 | command_error ('''couldn't find changeset %s in %s''' % (node, reponame)) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | return |
111 | 146 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | try: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | node = data[0] |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | message = data[1] |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | author = data[2] |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | diffstat = data[3] |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | date = datetime.utcfromtimestamp (int (data[4].split (' ')[0])) |
111 | 153 | 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
|
154 | latesttagdistance = int (data[6]) |
112 | 155 | latesttag = data[7] |
82
c6e853703ca8
- fixed bad age message in .cset
Teemu Piippo <crimsondusk64@gmail.com>
parents:
80
diff
changeset
|
156 | delta = datetime.utcnow() - date |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | datestring = '' |
111 | 158 | |
159 | if bookmarks: | |
160 | bookmarks = HgPoll.prettify_bookmarks (bookmarks) | |
161 | ||
80
0f6bfd359a7f
- .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
162 | # 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
|
163 | repo.hg_command ('revert', '-r', node, 'src/version.h') |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
164 | zanversion = '<unknown version>' |
111 | 165 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
166 | try: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
167 | with open (reponame + '/src/version.h') as version_file: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
168 | regexps = [ \ |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
169 | re.compile (r'#define\s+GAMEVER_STRING\s+"([^"]+)"'), \ |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
170 | re.compile (r'#define\s+DOTVERSIONSTR_NOREV\s+"([^"]+)"'), \ |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
171 | re.compile (r'#define\s+DOTVERSIONSTR\s+"([^"]+)"')] |
111 | 172 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
173 | for line in version_file: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
174 | for rex in regexps: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
175 | match = rex.match (line) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
176 | if match != None: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
177 | zanversion = match.group (1) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
178 | break |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
179 | |
80
0f6bfd359a7f
- .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
180 | if match != None: |
0f6bfd359a7f
- .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
181 | break |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
182 | except IOError: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
183 | pass |
111 | 184 | |
80
0f6bfd359a7f
- .cset now looks up the appropriate skulltag/zandronum version
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
185 | repo.hg_command ('revert', '--all') |
111 | 186 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | # 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
|
188 | match = re.compile (r'^(.+) <([^>]+)>$.*').match (author) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | if match: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | author = match.group (1) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | email = match.group (2) |
111 | 192 | |
76 | 193 | username = Config.find_developer_by_email (email) |
111 | 194 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | if username != '': |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | author = username |
110 | 197 | |
198 | # Try prettify the diffstat | |
199 | rex = re.compile (r'^([0-9]+): \+([0-9]+)/-([0-9]+)$') | |
200 | match = rex.match (diffstat) | |
201 | ||
202 | if match: | |
203 | diffstat = "%s\003:\0033 +%s\003/\0034-%s\003" % (match.group (1), match.group (2), match.group (3)) | |
204 | ||
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | if delta.days < 4: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | if delta.days == 0: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | if delta.seconds < 60: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | datestring = 'just now' |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | elif delta.seconds < 3600: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | minutes = delta.seconds / 60 |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
211 | datestring = '%d minute%s ago' % (minutes, plural (minutes)) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | else: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
213 | hours = delta.seconds / 3600 |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | datestring = '%d hour%s ago' % (hours, plural (hours)) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
215 | else: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
216 | 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
|
217 | else: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
218 | datestring = 'on %s' % (str (date)) |
111 | 219 | |
112 | 220 | versionstring = "" |
221 | if latesttagdistance != 0: | |
222 | versionstring = '%s %s, %d hops from %s' % (zanversion, date.strftime ('%y%m%d-%H%M'), latesttagdistance, latesttag) | |
223 | else: | |
224 | versionstring = latesttag | |
225 | ||
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
226 | reply ('changeset\0035 %s%s\003 (%s)\003: committed by\0032 %s\003 %s,\0032 %s' % \ |
112 | 227 | (node, bookmarks, versionstring, author, datestring, diffstat)) |
111 | 228 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | 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
|
230 | reply (' ' + line) |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
231 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
232 | reply ('url: %s/commits/%s' % (repourl, node)) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | except hgapi.HgException as e: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
234 | result = HgPoll.decipher_hgapi_error (e) |
111 | 235 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
236 | 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
|
237 | command_error (result[1]) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
238 | else: |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
239 | command_error (`e`) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
240 | |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
241 | def cmd_hg (bot, args, reply, **rest): |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | try: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | repo = hgapi.Repo (args['repo']) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
244 | 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
|
245 | reply (result) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
246 | except hgapi.hgapi.HgException as e: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | result = HgPoll.decipher_hgapi_error (e) |
111 | 248 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | 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
|
250 | command_error (result[1]) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
251 | else: |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
252 | command_error (`e`) |
87 | 253 | |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
254 | def cmd_resolves (bot, args, **rest): |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
255 | HgPoll.announce_ticket_resolved (args['ticket'], args['changeset']) |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
256 | |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
257 | def cmd_rebuildcommitsdb (bot, args, **rest): |
132 | 258 | HgPoll.g_CommitsDb.create_new() |
259 | ||
260 | def cmd_updatezadevtopic (bot, **rest): | |
261 | HgPoll.update_zadev_topic() |