Sat, 08 Aug 2015 14:21:51 +0300
whitespace
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 | 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 | 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 | 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 | { |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | 'name': 'hg', |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | 'description': 'Executes a hg command', |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
58 | 'args': '<command...>', |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | 'level': 'admin', |
87 | 60 | }, |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
61 | |
87 | 62 | { |
63 | 'name': 'resolves', | |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
64 | 'description': '''Manually cause a ticket to be resolved by a changeset''', |
87 | 65 | 'args': '<ticket> <changeset>', |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
66 | 'level': 'admin', # TODO |
87 | 67 | }, |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | ] |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | } |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | |
76 | 71 | def plural (a): |
72 | return '' if a == 1 else 's' | |
73 | ||
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | def cmd_checkhg (bot, **rest): |
147 | 75 | hgpoll.force_poll() |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
77 | def is_dateversion (key): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
78 | try: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
79 | 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
|
80 | return True |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
81 | except ValueError: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
82 | return False |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
83 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
84 | def resolve_node (node): |
147 | 85 | repo = None |
86 | db = HgCommitsDatabase() | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
87 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
88 | if '/' in node: |
147 | 89 | reponame, node = node.split ('/')[:2] |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
90 | |
147 | 91 | try: |
92 | repo = hgpoll.RepositoriesByName[reponame] | |
93 | except KeyError: | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
94 | command_error ('''unknown repository %s''' % reponame) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | # 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
|
97 | if is_dateversion (node): |
147 | 98 | 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
|
99 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
100 | if node == None: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
101 | 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
|
102 | return |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
103 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
104 | node = node[0:7] |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
105 | |
147 | 106 | noderepos = db.get_commit_repos (node) |
111 | 107 | |
147 | 108 | if repo == None: |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
109 | if not noderepos: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
110 | 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
|
111 | |
147 | 112 | repo = noderepos[0] |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
113 | |
147 | 114 | return (node, repo) |
111 | 115 | |
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
|
116 | def get_version_string (reponame, node): |
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 | try: |
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 | data = subprocess.check_output (['hg', '--cwd', reponame, 'cat', |
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
|
119 | '--rev', node, 'src/version.h']) |
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 | |
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 | 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
|
122 | 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
|
123 | 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
|
124 | 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
|
125 | 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
|
126 | try: |
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 | data = subprocess.check_output (['hg', '--cwd', reponame, 'cat', |
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 | '--rev', node, 'src/core/versiondefs.h']) |
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 | 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
|
130 | 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
|
131 | 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
|
132 | |
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
|
133 | 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
|
134 | 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
|
135 | 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
|
136 | |
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
|
137 | 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
|
138 | 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
|
139 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
140 | def cmd_cset (bot, args, reply, **rest): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
141 | data = "" |
147 | 142 | node, repo = resolve_node (args['key']) |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
143 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | try: |
147 | 145 | data = repo.get_commit_data (rev=node, |
146 | node='node|short', | |
147 | message='desc', | |
148 | author='author', | |
149 | diffstat='diffstat', | |
150 | time='date|hgdate', | |
151 | bookmarks='bookmarks', | |
152 | latesttagdistance='latesttagdistance', | |
153 | latesttag='latesttag', | |
154 | email='author|email') | |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
155 | except Subprocess.CalledProcessError: |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
156 | command_error ('''couldn't find changeset %s in %s''' % (node, reponame)) |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
157 | |
147 | 158 | del node |
159 | commit['date'] = datetime.utcfromtimestamp (int (commit['time'].split (' ')[0])) | |
160 | commit['latesttagdistance'] = int (commit['latesttagdistance']) | |
161 | commit['bookmarks'] = hgpoll.prettify_bookmarks (commit['bookmarks']) | |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
162 | |
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
|
163 | # Find out the version string of this changeset |
147 | 164 | versionstring = get_version_string (reponame, commit['node']) |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
165 | username = Config.find_developer_by_email (email) |
111 | 166 | |
147 | 167 | if username: |
168 | commit['author'] = username | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
169 | |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
170 | # Try prettify the diffstat |
147 | 171 | match = re.match (r'^([0-9]+): \+([0-9]+)/-([0-9]+)$', commit['diffstat']) |
111 | 172 | |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
173 | if match: |
147 | 174 | commit['diffstat'] = "%s\003:\0033 +%s\003/\0034-%s\003" % \ |
175 | (match.group (1), match.group (2), match.group (3)) | |
111 | 176 | |
147 | 177 | delta = datetime.utcnow() - date |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
178 | if delta.days < 4: |
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
179 | if delta.days == 0: |
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
180 | if delta.seconds < 60: |
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
181 | datestring = 'just now' |
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
182 | elif delta.seconds < 3600: |
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
183 | minutes = delta.seconds / 60 |
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
184 | 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
|
185 | else: |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
186 | hours = delta.seconds / 3600 |
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
187 | 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
|
188 | else: |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
189 | datestring = '%d day%s ago' % (delta.days, plural (delta.days)) |
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
190 | else: |
147 | 191 | datestring = 'on %s' % (str (commit['date'])) |
112 | 192 | |
147 | 193 | 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
|
194 | 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
|
195 | |
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
|
196 | 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
|
197 | 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
|
198 | |
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
|
199 | versionblurb += '%s, %d hops from %s' % (date.strftime ('%y%m%d-%H%M'), |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
200 | latesttagdistance, latesttag) |
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
201 | 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
|
202 | versionblurb = latesttag |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
203 | |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
204 | reply ('changeset\0035 %s%s\003 (%s)\003: committed by\0032 %s\003 %s,\0032 %s' % \ |
147 | 205 | (commit['node'], commit['bookmarks'], versionblurb, commit['author'], datestring, |
206 | commit['diffstat'])) | |
111 | 207 | |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
208 | for line in message.split ('\n'): |
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
209 | reply (' ' + line) |
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
210 | |
147 | 211 | 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
|
212 | |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
213 | def cmd_hg (bot, args, reply, **rest): |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | try: |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
215 | result = subprocess.check_output (['hg'] + args['command']) |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
216 | reply (result) |
144
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
217 | except Exception as e: |
b3d1b356e544
- Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents:
132
diff
changeset
|
218 | command_error (str (e)) |
87 | 219 | |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
220 | def cmd_resolves (bot, args, **rest): |
147 | 221 | hgpoll.announce_ticket_resolved (args['ticket'], args['changeset']) |