mod_hg.py

Sun, 16 Aug 2015 19:27:14 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 16 Aug 2015 19:27:14 +0300
changeset 153
497b7290977d
parent 152
1b734faab67a
child 155
5a9b5065f53f
permissions
-rw-r--r--

More Python 3 rework

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
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
29 from __future__ import print_function
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
30 from datetime import datetime
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
31 import hgpoll
74
9f14fb6995ff - added a missing import..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
32 import re
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
33 import subprocess
76
a2fe9ba3041a - various fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 75
diff changeset
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
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
36 from hgdb import HgCommitsDatabase
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 ModuleData = {
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 'commands':
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 {
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 'name': 'checkhg',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 'description': 'Polls the zandronum repositories for updates',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 'args': None,
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 'level': 'admin',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 },
117
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
47
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 {
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 'name': 'cset',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 '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
51 'args': '<key>',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 'level': 'normal',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 },
117
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
54
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 {
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
56 'name': 'resolves',
123
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 121
diff changeset
57 'description': '''Manually cause a ticket to be resolved by a changeset''',
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
58 'args': '<ticket> <changeset>',
117
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
59 'level': 'admin', # TODO
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 82
diff changeset
60 },
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 ]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 }
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63
76
a2fe9ba3041a - various fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 75
diff changeset
64 def plural (a):
a2fe9ba3041a - various fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 75
diff changeset
65 return '' if a == 1 else 's'
a2fe9ba3041a - various fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 75
diff changeset
66
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 def cmd_checkhg (bot, **rest):
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
68 hgpoll.force_poll()
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
70 def is_dateversion (key):
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
71 try:
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
72 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
73 return True
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
74 except ValueError:
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
75 return False
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
76
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
77 def resolve_node (node):
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
78 repo = None
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
79 db = HgCommitsDatabase()
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
80
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
81 if '/' in node:
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
82 reponame, node = node.split ('/')[:2]
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
83
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
84 try:
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
85 repo = hgpoll.RepositoriesByName[reponame]
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
86 except KeyError:
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
87 command_error ('''unknown repository %s''' % reponame)
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 # 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
90 if is_dateversion (node):
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
91 node = db.find_commit_by_dateversion (node)
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
92
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
93 if node == None:
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
94 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
95 return
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 node = node[0:7]
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
98
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
99 noderepos = db.get_commit_repos (node)
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
100
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
101 if repo == None:
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
102 if not noderepos:
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
103 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
104
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
105 repo = noderepos[0]
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
106
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
107 return (node, repo)
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
108
151
e24793fae424 Yet more fixes
Teemu Piippo <tsapii@utu.fi>
parents: 147
diff changeset
109 def get_version_string (repo, node):
145
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
110 try:
151
e24793fae424 Yet more fixes
Teemu Piippo <tsapii@utu.fi>
parents: 147
diff changeset
111 data = repo.hg ('cat', '--rev', node, 'src/version.h')
145
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
112
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
113 regexps = [ \
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
114 re.compile (r'#define\s+GAMEVER_STRING\s+"([^"]+)"'), \
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
115 re.compile (r'#define\s+DOTVERSIONSTR_NOREV\s+"([^"]+)"'), \
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
116 re.compile (r'#define\s+DOTVERSIONSTR\s+"([^"]+)"')]
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
117 except subprocess.CalledProcessError:
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
118 try:
151
e24793fae424 Yet more fixes
Teemu Piippo <tsapii@utu.fi>
parents: 147
diff changeset
119 data = repo.hg ('cat', '--rev', node, 'src/core/versiondefs.h')
145
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
120 regexps = [re.compile (r'#define\s+VERSION_STRING\s+"([^"]+)"')]
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
121 except subprocess.CalledProcessError:
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
122 return ''
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
123
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
124 for line in data.splitlines():
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
125 for rex in regexps:
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
126 match = rex.match (line)
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
127
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
128 if match:
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
129 return match.group (1)
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
130
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
131 def cmd_cset (bot, args, reply, **rest):
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
132 node, repo = resolve_node (args['key'])
152
1b734faab67a Port to Python 3
Teemu Piippo <crimsondusk64@gmail.com>
parents: 151
diff changeset
133 commit = repo.get_commit_data (rev=node,
1b734faab67a Port to Python 3
Teemu Piippo <crimsondusk64@gmail.com>
parents: 151
diff changeset
134 node='node|short',
1b734faab67a Port to Python 3
Teemu Piippo <crimsondusk64@gmail.com>
parents: 151
diff changeset
135 message='desc',
1b734faab67a Port to Python 3
Teemu Piippo <crimsondusk64@gmail.com>
parents: 151
diff changeset
136 author='author',
1b734faab67a Port to Python 3
Teemu Piippo <crimsondusk64@gmail.com>
parents: 151
diff changeset
137 diffstat='diffstat',
1b734faab67a Port to Python 3
Teemu Piippo <crimsondusk64@gmail.com>
parents: 151
diff changeset
138 time='date|hgdate',
1b734faab67a Port to Python 3
Teemu Piippo <crimsondusk64@gmail.com>
parents: 151
diff changeset
139 bookmarks='bookmarks',
1b734faab67a Port to Python 3
Teemu Piippo <crimsondusk64@gmail.com>
parents: 151
diff changeset
140 latesttagdistance='latesttagdistance',
1b734faab67a Port to Python 3
Teemu Piippo <crimsondusk64@gmail.com>
parents: 151
diff changeset
141 latesttag='latesttag',
1b734faab67a Port to Python 3
Teemu Piippo <crimsondusk64@gmail.com>
parents: 151
diff changeset
142 email='author|email')
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
143
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
144 del node
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
145 commit['date'] = datetime.utcfromtimestamp (int (commit['time'].split (' ')[0]))
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
146 commit['latesttagdistance'] = int (commit['latesttagdistance'])
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
147 commit['bookmarks'] = hgpoll.prettify_bookmarks (commit['bookmarks'])
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
148
145
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
149 # Find out the version string of this changeset
151
e24793fae424 Yet more fixes
Teemu Piippo <tsapii@utu.fi>
parents: 147
diff changeset
150 versionstring = get_version_string (repo, commit['node'])
e24793fae424 Yet more fixes
Teemu Piippo <tsapii@utu.fi>
parents: 147
diff changeset
151 username = Config.find_developer_by_email (commit['email'])
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
152
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
153 if username:
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
154 commit['author'] = username
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
155
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
156 # Try prettify the diffstat
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
157 match = re.match (r'^([0-9]+): \+([0-9]+)/-([0-9]+)$', commit['diffstat'])
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
158
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
159 if match:
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
160 commit['diffstat'] = "%s\003:\0033 +%s\003/\0034-%s\003" % \
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
161 (match.group (1), match.group (2), match.group (3))
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
162
151
e24793fae424 Yet more fixes
Teemu Piippo <tsapii@utu.fi>
parents: 147
diff changeset
163 delta = datetime.utcnow() - commit['date']
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
164 if delta.days < 4:
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
165 if delta.days == 0:
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
166 if delta.seconds < 60:
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
167 datestring = 'just now'
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
168 elif delta.seconds < 3600:
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
169 minutes = delta.seconds / 60
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
170 datestring = '%d minute%s ago' % (minutes, plural (minutes))
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 else:
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
172 hours = delta.seconds / 3600
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
173 datestring = '%d hour%s ago' % (hours, plural (hours))
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 else:
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
175 datestring = '%d day%s ago' % (delta.days, plural (delta.days))
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
176 else:
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
177 datestring = 'on %s' % (str (commit['date']))
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
178
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
179 if commit['latesttagdistance'] != 0:
145
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
180 versionblurb = ""
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
181
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
182 if versionstring:
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
183 versionblurb = versionstring + ' '
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
184
151
e24793fae424 Yet more fixes
Teemu Piippo <tsapii@utu.fi>
parents: 147
diff changeset
185 versionblurb += '%s, %d hops from %s' % (commit['date'].strftime ('%y%m%d-%H%M'),
e24793fae424 Yet more fixes
Teemu Piippo <tsapii@utu.fi>
parents: 147
diff changeset
186 commit['latesttagdistance'], commit['latesttag'])
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
187 else:
145
588aff83bb87 - Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
Teemu Piippo <crimsondusk64@gmail.com>
parents: 144
diff changeset
188 versionblurb = latesttag
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
189
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
190 reply ('changeset\0035 %s%s\003 (%s)\003: committed by\0032 %s\003 %s,\0032 %s' % \
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
191 (commit['node'], commit['bookmarks'], versionblurb, commit['author'], datestring,
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
192 commit['diffstat']))
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
193
151
e24793fae424 Yet more fixes
Teemu Piippo <tsapii@utu.fi>
parents: 147
diff changeset
194 for line in commit['message'].split ('\n'):
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
195 reply (' ' + line)
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
196
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
197 reply ('url: %s/commits/%s' % (repo.url, commit['node']))
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198
117
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
199 def cmd_resolves (bot, args, **rest):
147
4a72fb181a43 Fix .cset
Teemu Piippo <tsapii@utu.fi>
parents: 146
diff changeset
200 hgpoll.announce_ticket_resolved (args['ticket'], args['changeset'])

mercurial