Sun, 17 May 2015 20:40:09 +0300
Update:
- added a config option to disable the REST server
- added a message to be printed when IRC connections are first attempted
- look up the long commit node to be inserted into commits.db to avoid precision loss
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 | |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
29 | import hgapi |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
30 | import time |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
31 | import re |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
32 | import bt as Bt |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
33 | import irc as Irc |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
34 | import os, sqlite3, subprocess |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
35 | from datetime import datetime |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | from configfile import Config |
120
9880bb697149
- added doomseeker support, fixed up mod_bridge, now shortens new commit links with bit.ly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
37 | import utility |
132 | 38 | import subprocess |
133 | 39 | import random |
40 | import math | |
41 | ||
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
42 | g_CommitsDb = None |
132 | 43 | ZDoomRevNumber = 0 |
44 | ||
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
45 | def all_repo_names(): |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
46 | return Config.get_node ('hg').get_value ('repos', {}).keys() |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
48 | class CommitsDb (object): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
49 | def __init__(self): |
132 | 50 | dbname = Config.get_node('hg').get_value('commits_db', 'commits.db') |
51 | needNew = not os.path.isfile (dbname) | |
52 | self.db = sqlite3.connect (dbname) | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
53 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
54 | if needNew: |
122
f899af683bbe
- fixed a derp in commitsdb
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
55 | self.create_new() |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
56 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
57 | def create_new (self): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
58 | self.db.executescript (''' |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
59 | DROP TABLE IF EXISTS COMMITS; |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
60 | DROP TABLE IF EXISTS REPOS; |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
61 | DROP TABLE IF EXISTS REPOCOMMITS; |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
62 | CREATE TABLE IF NOT EXISTS COMMITS |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
63 | ( |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
64 | Node text NOT NULL, |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
65 | Dateversion text NOT NULL, |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
66 | PRIMARY KEY (Node) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
67 | ); |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
68 | CREATE TABLE IF NOT EXISTS REPOS |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
69 | ( |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
70 | Name text NOT NULL, |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
71 | PRIMARY KEY (Name) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
72 | ); |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
73 | CREATE TABLE IF NOT EXISTS REPOCOMMITS |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
74 | ( |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
75 | Reponame text, |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
76 | Node text, |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
77 | FOREIGN KEY (Reponame) REFERENCES REPOS(Name), |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
78 | FOREIGN KEY (Node) REFERENCES COMMITS(Node) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
79 | ); |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
80 | ''') |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
81 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
82 | print 'Building commits.db...' |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
83 | for repo in all_repo_names(): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
84 | print 'Adding commits from %s...' % repo |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
85 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
86 | data = subprocess.check_output (['hg', '--cwd', repo, 'log', '--template', |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
87 | '{node} {date|hgdate}\n']).splitlines() |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
88 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
89 | for line in data: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
90 | changeset, timestamp, tz = line.split(' ') |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
91 | self.add_commit (repo, changeset, int (timestamp)) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
92 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
93 | self.commit() |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
94 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
95 | def add_commit (self, repo, changeset, timestamp): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
96 | dateversion = datetime.utcfromtimestamp (timestamp).strftime ('%y%m%d-%H%M') |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
97 | self.db.execute (''' |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
98 | INSERT OR IGNORE INTO REPOS |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
99 | VALUES (?) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
100 | ''', (repo,)) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
101 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
102 | self.db.execute (''' |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
103 | INSERT OR IGNORE INTO COMMITS |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
104 | VALUES (?, ?) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
105 | ''', (changeset, dateversion)) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
106 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
107 | self.db.execute (''' |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
108 | INSERT INTO REPOCOMMITS |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
109 | VALUES (?, ?) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
110 | ''', (repo, changeset)) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
111 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
112 | def get_commit_repos (self, node): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
113 | cursor = self.db.execute (''' |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
114 | SELECT Reponame |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
115 | FROM REPOCOMMITS |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
116 | WHERE Node LIKE ? |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
117 | ''', (node + '%',)) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
118 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
119 | results = cursor.fetchall() |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
120 | return list (set (zip (*results)[0])) if results else [] |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
121 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
122 | def find_commit_by_dateversion (self, dateversion): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
123 | cursor = self.db.execute (''' |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
124 | SELECT Node |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
125 | FROM COMMITS |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
126 | WHERE Dateversion = ? |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
127 | ''', (dateversion,)) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
128 | result = cursor.fetchone() |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
129 | return result[0] if result else None |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
130 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
131 | def commit(self): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
132 | self.db.commit() |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
133 | |
110 | 134 | def color_for_repo (repo_name): |
120
9880bb697149
- added doomseeker support, fixed up mod_bridge, now shortens new commit links with bit.ly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
135 | repo_name = repo_name.lower() |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
136 | repoconfig = Config.get_node ('hg').get_node ('repos') |
120
9880bb697149
- added doomseeker support, fixed up mod_bridge, now shortens new commit links with bit.ly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
137 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
138 | if repoconfig.has_node (repo_name): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
139 | return repoconfig.get_node(repo_name).get_value ('colorcode', 0) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
140 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
141 | return 0 |
110 | 142 | |
111 | 143 | def prettify_bookmarks (bookmarks): |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
144 | if bookmarks: |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
145 | return "\0036 [\002%s\002]" % bookmarks |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
146 | else: |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
147 | return '' |
111 | 148 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
149 | def get_repo_info (reponame): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
150 | reponame = reponame.lower() |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
151 | repoconfig = Config.get_node ('hg').get_node ('repos') |
87 | 152 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
153 | if repoconfig.has_node (reponame): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
154 | return repoconfig.get_node (reponame) |
87 | 155 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
156 | return None |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | ' Check if a repository exists ' |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
159 | def check_repo_exists (repo_name): |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | print 'Checking that %s exists...' % repo_name |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | zanrepo = hgapi.Repo (repo_name) |
87 | 162 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
163 | if not os.path.exists (repo_name): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
164 | os.makedirs (repo_name) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
165 | |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
166 | if not os.path.isfile (os.path.join (repo_name, '.hg', 'hgrc')): |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
167 | # If the repo does not exist, clone it. |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
168 | repo_url = get_repo_info (repo_name).get_value ('url') |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | try: |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
170 | print ('Cloning %s...' % repo_name) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | zanrepo.hg_clone (repo_url, repo_name) |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
172 | |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
173 | # We need to un-alias a few things, they can be aliased on the host machine (e.g. mine) |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
174 | comms=['log', 'incoming', 'pull', 'commit', 'push', 'outgoing', 'strip', 'transplant'] |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
175 | try: |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
176 | with open (os.path.join (repo_name, '.hg', 'hgrc'), 'a') as fp: |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
177 | fp.write ('\n[alias]\n' + ''.join(['%s=%s\n' % (x, x) for x in comms])) |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
178 | except Exception as e: |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
179 | print ('Warning: unable to alter hgrc of %s: %s' % repo_name, e) |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
180 | print ('Cloning done.') |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
181 | except Exception as e: |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
182 | print ('Unable to clone %s from %s: %s' % (repo_name, repo_url, e)) |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
183 | quit (1) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
184 | |
88 | 185 | |
186 | class HgProcessError (Exception): | |
187 | def __init__ (self, value): | |
188 | self.message = value | |
189 | def __str__ (self): | |
190 | return self.message | |
191 | ||
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
192 | def announce_ticket_resolved (ticket_id, cset): |
91 | 193 | ticket_id = int (ticket_id) |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
194 | reponames = g_CommitsDb.get_commit_repos (cset) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
195 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
196 | if not reponames: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
197 | raise HgProcessError ('Changeset %s does not appear to exist!' % cset) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
198 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
199 | for reponame in reponames: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
200 | repoinfo = get_repo_info (reponame) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
201 | if not repoinfo: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
202 | raise HgProcessError ('Unknown repo %s' % reponame) |
91 | 203 | |
132 | 204 | if not repoinfo.get_value ('extrarepo', default=False): |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
205 | break |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
206 | else: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
207 | raise HgProcessError ('Changeset %s is only committed to non-published repositories %s' % |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
208 | (cset, reponames)) |
89 | 209 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
210 | repo = hgapi.Repo (reponame) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
211 | repo_url = repoinfo.get_value ('url', default=None) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
212 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
213 | if not repo_url: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
214 | raise HgProcessError ('Repo %s has no url!' % reponame) |
87 | 215 | |
216 | # Acquire additional data | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
217 | moredata = get_commit_data (repo, cset, |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
218 | r"{author|nonempty}\n{date(date, '%A %d %B %Y %H:%M:%S')}").split('\n') |
87 | 219 | |
220 | if len (moredata) != 2: | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
221 | raise HgProcessError ('malformed hg data while processing %s' % cset) |
87 | 222 | |
223 | commit_author = moredata[0] | |
224 | commit_date = moredata[1] | |
225 | commit_email = "" | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
226 | commit_message = repo.hg_command ('log', '-r', cset, '--template', '{desc}') |
87 | 227 | |
228 | try: | |
229 | ticket_data = Bt.get_issue (ticket_id) | |
230 | except Exception as e: | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
231 | raise HgProcessError ("error while processing %s: %s" % (cset, e)) |
87 | 232 | |
233 | # Remove the email address from the author if possible | |
234 | rex = re.compile (r'^(.+) <([^>]+)>$.*') | |
235 | match = rex.match (commit_author) | |
236 | if match: | |
237 | commit_author = match.group (1) | |
238 | commit_email = match.group (2) | |
239 | ||
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
240 | commit_diffstat = repo.hg_command ('diff', '--change', cset, '--stat') |
87 | 241 | |
242 | if len(commit_diffstat) > 0: | |
243 | # commit_diffstat = 'Changes in files:\n[code]\n' + commit_diffstat + '\n[/code]' | |
244 | commit_diffstat = 'Changes in files:\n' + bbcodify(commit_diffstat) | |
245 | else: | |
246 | commit_diffstat = 'No changes in files.' | |
247 | ||
248 | # Compare the email addresses against known developer usernames | |
249 | commit_trackeruser = Config.find_developer_by_email (commit_email) | |
250 | ||
251 | if commit_trackeruser != '': | |
252 | commit_author += ' [%s]' % commit_trackeruser | |
253 | ||
115 | 254 | commit_message = commit_message.replace ("\n", " ") |
255 | ||
87 | 256 | message = 'Issue addressed by commit %s: [b][url=%s/commits/%s]%s[/url][/b]' \ |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
257 | % (cset, repo_url, cset, commit_message) |
87 | 258 | message += "\nCommitted by %s on %s\n\n%s" \ |
259 | % (commit_author, commit_date, commit_diffstat) | |
260 | ||
261 | need_update = False | |
262 | ||
263 | # If not already set, set handler | |
264 | if not 'handler' in ticket_data: | |
265 | ticket_data['handler'] = {'name': commit_trackeruser} | |
266 | need_update = True | |
267 | ||
268 | # Find out the status level of the ticket | |
269 | needs_testing_level = 70 | |
270 | ||
271 | if ticket_data['status']['id'] < needs_testing_level: | |
272 | ticket_data.status['id'] = needs_testing_level | |
273 | need_update = True | |
274 | ||
275 | # Set target version if not set | |
276 | if not 'target_version' in ticket_data: | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
277 | ticket_data['target_version'] = repoinfo.get_value ('version') |
87 | 278 | need_update = True |
279 | ||
280 | # Announce on IRC | |
281 | for irc_client in Irc.all_clients: | |
282 | for channel in irc_client.channels: | |
283 | if channel.get_value ('btannounce', default=True): | |
284 | irc_client.privmsg (channel.get_value ('name'), | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
285 | "\003%d%s\003: commit\0035 %s\003 addresses issue\002\0032 %d\002" % (color_for_repo (reponame), reponame, cset, ticket_id)) |
87 | 286 | irc_client.privmsg (channel.get_value ('name'), |
287 | "Read all about it here: " + Bt.get_ticket_url (ticket_id)) | |
288 | ||
289 | if need_update: | |
290 | # We need to remove the note data, otherwise the ticket notes | |
291 | # will get unnecessary updates. WTF, MantisBT? | |
292 | ticket_data.notes = [] | |
293 | Bt.update_issue (ticket_id, ticket_data) | |
294 | ||
295 | Bt.post_note (ticket_id, message) | |
296 | ||
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
297 | def init(): |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
298 | global repocheck_timeout |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
299 | global g_CommitsDb |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
300 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
301 | for repo in all_repo_names(): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
302 | check_repo_exists (repo) |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
303 | |
140 | 304 | g_CommitsDb = CommitsDb() |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
305 | repocheck_timeout = time.time() + 15 |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
306 | |
132 | 307 | global ZDoomRevNumber |
308 | try: | |
309 | ZDoomRevNumber = get_zdrev_number ('zandronum-merge-experiments', 'tip') | |
310 | except Exception as e: | |
311 | print 'error while figuring out zdoom rev number: %s' % e | |
312 | ||
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
313 | def get_commit_data (repo, rev, template): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
314 | return repo.hg_command ('log', '-l', '1', '-r', rev, '--template', template) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
315 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
316 | def decipher_hgapi_error (e): |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
317 | # Blah, hgapi, why must your error messages be so mangled? |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
318 | try: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
319 | rawmsg = e.message.replace('\n', '').replace('" +','').replace('\t','') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
320 | errmsg = re.compile (r'.*: tErr: (.*)Out:.*').match (rawmsg).group (1) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
321 | return [True, errmsg] |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
322 | except: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
323 | return [False, ''] |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
324 | |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
325 | def bbcodify (commit_diffstat): |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
326 | result = '' |
87 | 327 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
328 | for line in commit_diffstat.split('\n'): |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
329 | rex = re.compile (r'^(.*)\|(.*) (\+*)(-*)(.*)$') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
330 | match = rex.match (line) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
331 | if match: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
332 | line = '%s|%s [color=#5F7]%s[/color][color=#F53]%s[/color]%s\n' \ |
111 | 333 | % (match.group (1), match.group (2), match.group (3), |
334 | match.group (4), match.group (5)) | |
87 | 335 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
336 | # Tracker doesn't seem to like empty color tags |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
337 | line = line.replace ('[color=#5F7][/color]', '').replace ('[color=#F53][/color]', '') |
87 | 338 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
339 | result += line |
87 | 340 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
341 | return result |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
342 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
343 | def poll(): |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
344 | global repocheck_timeout |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
345 | if time.time() < repocheck_timeout: |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
346 | return |
87 | 347 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
348 | for reponame in all_repo_names(): |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
349 | poll_one_repo (reponame) |
87 | 350 | |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
351 | hgns = Config.get_node ('hg') |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
352 | repocheck_timeout = time.time() + hgns.get_value ('checkinterval', default=15) * 60 |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
353 | |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
354 | def poll_one_repo (repo_name): |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
355 | global repocheck_timeout |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
356 | hgns = Config.get_node ('hg') |
87 | 357 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
358 | if not hgns.get_value ('track', default=True): |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
359 | return |
87 | 360 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
361 | repo = hgapi.Repo (repo_name) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
362 | commit_data = [] |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
363 | delimeter = '^^^^^^^^^^' |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
364 | delimeter2 = '@@@@@@@@@@' |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
365 | print 'Checking %s for updates' % repo_name |
87 | 366 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
367 | try: |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
368 | data = repo.hg_command ('incoming', '--quiet', '--template', |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
369 | delimeter.join (['{node|short}', '{desc}']) + delimeter2).split (delimeter2) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
370 | except hgapi.hgapi.HgException as e: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
371 | deciphered = decipher_hgapi_error (e) |
87 | 372 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
373 | if deciphered[0] and len(deciphered[1]) > 0: |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
374 | Irc.broadcast ("error while using hg incoming on %s: %s" % (repo_name, deciphered[1])) |
87 | 375 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
376 | return |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
377 | except Exception as e: |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
378 | Irc.broadcast ("%s" % `e`) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
379 | return |
87 | 380 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
381 | if not data: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
382 | print ('No updates to %s' % repo_name) |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
383 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
384 | for line in data: |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
385 | if line: |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
386 | commit_data.append (line.split (delimeter)) |
87 | 387 | |
97 | 388 | process_new_commits (repo_name, commit_data) |
389 | ||
390 | def process_new_commits (repo_name, commit_data): | |
108
8cf31b4d5fcb
- we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
391 | if len (commit_data) == 0: |
8cf31b4d5fcb
- we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
392 | return |
8cf31b4d5fcb
- we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
393 | |
120
9880bb697149
- added doomseeker support, fixed up mod_bridge, now shortens new commit links with bit.ly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
394 | repo_name = repo_name.lower() |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
395 | repo_url = get_repo_info (repo_name).get_value ('url') |
132 | 396 | isExtraRepo = get_repo_info (repo_name).get_value ('extrarepo', False) |
98
4edbdf390bd1
- fix previous commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
97
diff
changeset
|
397 | zanrepo = hgapi.Repo (repo_name) |
110 | 398 | print '%d new commits on %s' % (len (commit_data), repo_name) |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
399 | pull_args = [] |
132 | 400 | messages = [[], [], []] |
401 | messageSizeClass = 2 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
402 | |
108
8cf31b4d5fcb
- we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
403 | for commit in commit_data: |
8cf31b4d5fcb
- we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
404 | pull_args.append ('-r'); |
8cf31b4d5fcb
- we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
405 | pull_args.append (commit[0]); |
8cf31b4d5fcb
- we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
406 | |
8cf31b4d5fcb
- we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
407 | print 'Pulling new commits...' |
8cf31b4d5fcb
- we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
408 | try: |
8cf31b4d5fcb
- we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
409 | zanrepo.hg_command ('pull', *pull_args) |
8cf31b4d5fcb
- we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
410 | except Exception as e: |
8cf31b4d5fcb
- we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
411 | Irc.broadcast ('Warning: unable to pull: %s' % `e`) |
8cf31b4d5fcb
- we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents:
101
diff
changeset
|
412 | return |
87 | 413 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
414 | for commit in commit_data: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
415 | commit_node = commit[0] |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
416 | commit_message = commit[1] |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
417 | print 'Processing new commit %s...' % commit_node |
87 | 418 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
419 | try: |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
420 | existingrepos = g_CommitsDb.get_commit_repos (commit_node) |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
421 | alreadyAdded = len (existingrepos) > 0 |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
422 | |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
423 | delim = '@@@@@@@@@@' |
140 | 424 | data = get_commit_data (zanrepo, commit_node, delim.join (['{node}', '{author}', '{bookmarks}', \ |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
425 | '{date|hgdate}'])).split (delim) |
140 | 426 | commit_full_node = data[0] |
427 | commit_author = data[1] | |
428 | commit_bookmarks = prettify_bookmarks (data[2]) | |
429 | commit_time = int (data[3].split (' ')[0]) | |
100
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
430 | commit_url = '%s/commits/%s' % (repo_url, commit_node) |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
431 | commit_email = '' |
87 | 432 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
433 | # If the commit was already in the commits database, it is not a new one and we should |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
434 | # not react to it. Still add it to the db though so that the new repo name is added. |
140 | 435 | g_CommitsDb.add_commit (repo=repo_name, changeset=commit_full_node, timestamp=commit_time) |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
436 | if alreadyAdded: |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
437 | print ('''I already know of %s - they're in %s - not announcing.''' % |
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
122
diff
changeset
|
438 | (commit_node, existingrepos)) |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
439 | continue |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
440 | |
100
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
441 | # Remove the email address from the author if possible |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
442 | rex = re.compile (r'^(.+) <([^>]+)>$.*') |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
443 | match = rex.match (commit_author) |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
444 | if match: |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
445 | commit_author = match.group (1) |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
446 | commit_email = match.group (2) |
87 | 447 | |
100
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
448 | commit_trackeruser = Config.find_developer_by_email (commit_email) |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
449 | committer = commit_trackeruser if commit_trackeruser != '' else commit_author |
87 | 450 | |
133 | 451 | commitDescriptor = """commit""" if int (math.ceil (random.random() * 100)) != 1 else """KERMIT""" |
452 | ||
453 | commitMessage = """\003%d%s\003: new %s\0035 %s%s\003 by\0032 %s\003: %s""" % \ | |
454 | (color_for_repo (repo_name), repo_name, commitDescriptor, commit_node, commit_bookmarks, | |
132 | 455 | committer, utility.shorten_link (commit_url)) |
112 | 456 | |
132 | 457 | messages[0].append (commitMessage) |
458 | messages[1].append (commitMessage) | |
459 | messages[2].append (commitMessage) | |
460 | messages[1].append (' ' + commit_message.splitlines()[0]) | |
87 | 461 | |
132 | 462 | for line in commit_message.splitlines()[0:4]: |
463 | messages[2].append (' ' + line) | |
87 | 464 | |
132 | 465 | if not isExtraRepo: |
100
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
466 | rex = re.compile (r'^.*(fixes|resolves|addresses|should fix) ([0-9]+).*$') |
132 | 467 | |
468 | for line in commit_message.splitlines(): | |
469 | match = rex.match (line) | |
87 | 470 | |
132 | 471 | if match: |
472 | announce_ticket_resolved (match.group (2), commit_node) | |
473 | break | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
474 | except Exception as e: |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
475 | Irc.broadcast ('Error while processing %s: %s' % (commit_node, e)) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
476 | continue |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
477 | |
132 | 478 | fullMessageLength = len (''.join (messages[2])) |
479 | ||
480 | if fullMessageLength > 3000: | |
481 | messageSizeClass = 0 | |
482 | elif fullMessageLength > 768: | |
483 | messageSizeClass = 1 | |
484 | ||
485 | print ("""Message length in total: %d, using size class %d (%d)""" %\ | |
486 | (fullMessageLength, messageSizeClass, len (''.join (messages[messageSizeClass])))) | |
487 | ||
488 | # Post it all on IRC now | |
489 | for message in messages[messageSizeClass]: | |
490 | for irc_client in Irc.all_clients: | |
491 | for channel in irc_client.channels: | |
492 | if not channel.get_value ('btannounce', False): | |
493 | continue | |
494 | ||
495 | if isExtraRepo and not channel.get_value ('allpublishing', False): | |
496 | continue | |
497 | ||
498 | irc_client.privmsg (channel.get_value ('name'), message) | |
499 | ||
500 | # Hack for ZDoom upgrades | |
501 | if repo_name == 'zandronum-merge-experiments': | |
502 | check_zdoom_upgrade (repo_name, commit_node) | |
503 | ||
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
504 | g_CommitsDb.commit() |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
120
diff
changeset
|
505 | |
132 | 506 | def make_progress_bar (p, barLength, colored=True): |
507 | BoldChar, ColorChar = (Irc.BoldChar, Irc.ColorChar) | |
508 | return BoldChar + '[' + BoldChar \ | |
509 | + ColorChar + '2,2' + ('=' * int (round (p * barLength))) \ | |
510 | + ColorChar + '1,1' + ('-' * int (barLength - round (p * barLength))) \ | |
511 | + ColorChar + BoldChar + ']' + BoldChar | |
512 | ||
513 | ZDoomMin = 2560 | |
514 | ZDoomMax = 3794 | |
515 | ||
516 | def check_zdoom_upgrade (repo_name, commit_node): | |
517 | zanrepo = hgapi.Repo (repo_name) | |
518 | try: | |
519 | global ZDoomRevNumber | |
520 | newnumber = get_zdrev_number (repo_name, commit_node) | |
521 | ||
522 | if newnumber > ZDoomRevNumber: | |
523 | ZDoomRevNumber = newnumber | |
524 | fraction = float (newnumber - ZDoomMin) / (ZDoomMax - ZDoomMin) | |
525 | # progressBar = make_progress_bar (fraction, 30, colored=True); | |
526 | ||
527 | message = """ZDoom upgrade: r%d: %d revisions left (%d%% complete)""" %\ | |
528 | (newnumber, ZDoomMax - newnumber, round (fraction * 100)) | |
529 | ||
530 | for irc_client in Irc.all_clients: | |
531 | for channel in irc_client.channels: | |
532 | if not channel.get_value ('allpublishing', False): | |
533 | continue | |
534 | irc_client.privmsg (channel.get_value ('name'), message) | |
535 | ||
536 | update_zadev_topic() | |
537 | except Exception as e: | |
538 | Irc.broadcast ('Error while dealing with ZDoom upgrade number: %s' % e) | |
539 | ||
540 | def update_zadev_topic(): | |
140 | 541 | return |
132 | 542 | fraction = float (ZDoomRevNumber - ZDoomMin) / (ZDoomMax - ZDoomMin) |
543 | topicText = """ZDoom 2.6.1 progress: at r%d, %d revisions left (%d%% complete)""" %\ | |
544 | (ZDoomRevNumber, ZDoomMax - ZDoomRevNumber, round (fraction * 100)) | |
545 | ||
546 | try: | |
547 | Irc.ClientsByName['zandronum'].write ("""TOPIC #zadev :%s""" % topicText) | |
548 | Irc.ClientsByName['zandronum'].write ("""TOPIC #commits :%s""" % topicText) | |
549 | except Exception as e: | |
550 | Irc.broadcast ("""Error setting #zadev topic: %s""" % e) | |
551 | ||
552 | def get_zdrev_number (repo_name, commit_node): | |
553 | zanrepo = hgapi.Repo (repo_name) | |
554 | subprocess.call (['hg', '--cwd', repo_name, 'revert', '-r', commit_node, 'src/version.h']) | |
555 | rx = re.compile (r'#define\s+ZD_SVN_REVISION_NUMBER\s+([0-9]+)') | |
556 | result = None | |
557 | ||
558 | with open (repo_name + '/src/version.h') as version_file: | |
559 | for line in version_file: | |
560 | match = rx.match (line) | |
561 | if match != None: | |
562 | result = int (match.group (1)) | |
563 | break | |
564 | ||
565 | subprocess.call (['hg', '--cwd', repo_name, 'revert', '-r.', 'src/version.h']) | |
566 | ||
567 | if result != None: | |
568 | return result | |
569 | ||
570 | raise ValueError ("""Could not find ZD_SVN_REVISION_NUMBER in version.h""") | |
571 | ||
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
572 | def force_poll(): |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
573 | global repocheck_timeout |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
574 | repocheck_timeout = 0 |
85
302e2bec51d8
- fixed bad find_developer_by_email call
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
575 | poll() |