Fri, 01 May 2015 19:08:12 +0300
lots of new stuff
calc.py | file | annotate | diff | comparison | revisions | |
cobalt.py | file | annotate | diff | comparison | revisions | |
configfile.py | file | annotate | diff | comparison | revisions | |
hgpoll.py | file | annotate | diff | comparison | revisions | |
irc.py | file | annotate | diff | comparison | revisions | |
mod_hg.py | file | annotate | diff | comparison | revisions |
--- a/calc.py Fri Apr 24 06:40:08 2015 +0300 +++ b/calc.py Fri May 01 19:08:12 2015 +0300 @@ -142,6 +142,7 @@ 'e': cmath.e, 'phi': 1.6180339887498948482, 'epsilon': epsilon, + 'potato': cmath.sqrt(8) / 3, } random.seed (time.time()) @@ -408,7 +409,7 @@ def is_operand (self, x): # Operands can be either lists (which also mean parens, thus can be single-expressions) # or complex numbers - return type(x) in [complex, list] + return type(x) in [complex, list, FunctionCall] def find_fitting_operator (self, sym, numOperands): # Pass 1: exact numOperands match
--- a/cobalt.py Fri Apr 24 06:40:08 2015 +0300 +++ b/cobalt.py Fri May 01 19:08:12 2015 +0300 @@ -116,5 +116,4 @@ except Irc.RestartError as e: excepterm (e.message) -if __name__ == '__main__': - main() +main()
--- a/configfile.py Fri Apr 24 06:40:08 2015 +0300 +++ b/configfile.py Fri May 01 19:08:12 2015 +0300 @@ -26,7 +26,10 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ''' -import json +import json, sys +IsInitialized = False +Config = None +ConfigFileName = "" class ConfigNode: def __init__ (self, obj, name, parent): @@ -45,7 +48,7 @@ if not key in self.obj: if default == None: - raise ValueError ('Mandatory key \'%s\' not found' % self.keyname (key)) + raise ValueError ("""Mandatory key '%s' not found""" % self.keyname (key)) self.obj[key] = default self.save() @@ -89,7 +92,7 @@ self.root.save() return - with open ('cobalt.json', 'w') as fp: + with open (ConfigFileName, 'w') as fp: json.dump (self.obj, fp, sort_keys = True, indent = 1) print "Config saved." @@ -102,16 +105,27 @@ return '' def init(): - print 'Loading configuration...' + filename = 'cobalt.json' + + if len (sys.argv) >= 2: + filename = sys.argv[1] + + global IsInitialized + global ConfigFileName + ConfigFileName = filename + + if not IsInitialized: + print """Loading configuration...""" - try: - with open ('cobalt.json', 'r') as fp: - jsondata = json.loads (fp.read()) - except IOError as e: - print 'couldn\'t open cobalt.json: %s' % e - quit() - - global Config - Config = ConfigNode (jsondata, name=None, parent=None) + try: + with open (filename, 'r') as fp: + jsondata = json.loads (fp.read()) + except IOError as e: + print ("""couldn't open %s: %s""" % (filename, e)) + quit() -init() + global Config + Config = ConfigNode (jsondata, name=None, parent=None) + IsInitialized = True + +init() \ No newline at end of file
--- a/hgpoll.py Fri Apr 24 06:40:08 2015 +0300 +++ b/hgpoll.py Fri May 01 19:08:12 2015 +0300 @@ -35,15 +35,19 @@ from datetime import datetime from configfile import Config import utility +import subprocess g_CommitsDb = None +ZDoomRevNumber = 0 + def all_repo_names(): return Config.get_node ('hg').get_value ('repos', {}).keys() class CommitsDb (object): def __init__(self): - needNew = not os.path.isfile ('commits.db') - self.db = sqlite3.connect ('commits.db') + dbname = Config.get_node('hg').get_value('commits_db', 'commits.db') + needNew = not os.path.isfile (dbname) + self.db = sqlite3.connect (dbname) if needNew: self.create_new() @@ -195,7 +199,7 @@ if not repoinfo: raise HgProcessError ('Unknown repo %s' % reponame) - if not repoinfo.get_value ('private', default=False): + if not repoinfo.get_value ('extrarepo', default=False): break else: raise HgProcessError ('Changeset %s is only committed to non-published repositories %s' % @@ -298,6 +302,12 @@ repocheck_timeout = time.time() + 15 g_CommitsDb = CommitsDb() + global ZDoomRevNumber + try: + ZDoomRevNumber = get_zdrev_number ('zandronum-merge-experiments', 'tip') + except Exception as e: + print 'error while figuring out zdoom rev number: %s' % e + def get_commit_data (repo, rev, template): return repo.hg_command ('log', '-l', '1', '-r', rev, '--template', template) @@ -381,11 +391,12 @@ repo_name = repo_name.lower() repo_url = get_repo_info (repo_name).get_value ('url') - ispublishing = not get_repo_info (repo_name).get_value ('private', False) - num_commits = 0 + isExtraRepo = get_repo_info (repo_name).get_value ('extrarepo', False) zanrepo = hgapi.Repo (repo_name) print '%d new commits on %s' % (len (commit_data), repo_name) pull_args = [] + messages = [[], [], []] + messageSizeClass = 2 for commit in commit_data: pull_args.append ('-r'); @@ -434,34 +445,124 @@ commit_trackeruser = Config.find_developer_by_email (commit_email) committer = commit_trackeruser if commit_trackeruser != '' else commit_author - for irc_client in Irc.all_clients: - for channel in irc_client.channels: - if not channel.get_value ('btannounce', False): - continue + commitMessage = "\003%d%s\003: new commit\0035 %s%s\003 by\0032 %s\003: %s" % \ + (color_for_repo (repo_name), repo_name, commit_node, commit_bookmarks, + committer, utility.shorten_link (commit_url)) - if ispublishing or channel.get_value ('btprivate', False): - irc_client.privmsg (channel.get_value ('name'), - "\003%d%s\003: new commit\0035 %s%s\003 by\0032 %s\003: %s" - % (color_for_repo (repo_name), repo_name, commit_node, commit_bookmarks, - committer, utility.shorten_link (commit_url))) + messages[0].append (commitMessage) + messages[1].append (commitMessage) + messages[2].append (commitMessage) + messages[1].append (' ' + commit_message.splitlines()[0]) - for line in commit_message.splitlines(): - irc_client.privmsg (channel.get_value ('name'), ' ' + line) + for line in commit_message.splitlines()[0:4]: + messages[2].append (' ' + line) - if ispublishing: + if not isExtraRepo: rex = re.compile (r'^.*(fixes|resolves|addresses|should fix) ([0-9]+).*$') - match = rex.match (commit_message) + + for line in commit_message.splitlines(): + match = rex.match (line) - if match: - announce_ticket_resolved (match.group (2), commit_node) - - num_commits += 1 + if match: + announce_ticket_resolved (match.group (2), commit_node) + break except Exception as e: Irc.broadcast ('Error while processing %s: %s' % (commit_node, e)) continue + fullMessageLength = len (''.join (messages[2])) + + if fullMessageLength > 3000: + messageSizeClass = 0 + elif fullMessageLength > 768: + messageSizeClass = 1 + + print ("""Message length in total: %d, using size class %d (%d)""" %\ + (fullMessageLength, messageSizeClass, len (''.join (messages[messageSizeClass])))) + + # Post it all on IRC now + for message in messages[messageSizeClass]: + for irc_client in Irc.all_clients: + for channel in irc_client.channels: + if not channel.get_value ('btannounce', False): + continue + + if isExtraRepo and not channel.get_value ('allpublishing', False): + continue + + irc_client.privmsg (channel.get_value ('name'), message) + + # Hack for ZDoom upgrades + if repo_name == 'zandronum-merge-experiments': + check_zdoom_upgrade (repo_name, commit_node) + g_CommitsDb.commit() +def make_progress_bar (p, barLength, colored=True): + BoldChar, ColorChar = (Irc.BoldChar, Irc.ColorChar) + return BoldChar + '[' + BoldChar \ + + ColorChar + '2,2' + ('=' * int (round (p * barLength))) \ + + ColorChar + '1,1' + ('-' * int (barLength - round (p * barLength))) \ + + ColorChar + BoldChar + ']' + BoldChar + +ZDoomMin = 2560 +ZDoomMax = 3794 + +def check_zdoom_upgrade (repo_name, commit_node): + zanrepo = hgapi.Repo (repo_name) + try: + global ZDoomRevNumber + newnumber = get_zdrev_number (repo_name, commit_node) + + if newnumber > ZDoomRevNumber: + ZDoomRevNumber = newnumber + fraction = float (newnumber - ZDoomMin) / (ZDoomMax - ZDoomMin) + # progressBar = make_progress_bar (fraction, 30, colored=True); + + message = """ZDoom upgrade: r%d: %d revisions left (%d%% complete)""" %\ + (newnumber, ZDoomMax - newnumber, round (fraction * 100)) + + for irc_client in Irc.all_clients: + for channel in irc_client.channels: + if not channel.get_value ('allpublishing', False): + continue + irc_client.privmsg (channel.get_value ('name'), message) + + update_zadev_topic() + except Exception as e: + Irc.broadcast ('Error while dealing with ZDoom upgrade number: %s' % e) + +def update_zadev_topic(): + fraction = float (ZDoomRevNumber - ZDoomMin) / (ZDoomMax - ZDoomMin) + topicText = """ZDoom 2.6.1 progress: at r%d, %d revisions left (%d%% complete)""" %\ + (ZDoomRevNumber, ZDoomMax - ZDoomRevNumber, round (fraction * 100)) + + try: + Irc.ClientsByName['zandronum'].write ("""TOPIC #zadev :%s""" % topicText) + Irc.ClientsByName['zandronum'].write ("""TOPIC #commits :%s""" % topicText) + except Exception as e: + Irc.broadcast ("""Error setting #zadev topic: %s""" % e) + +def get_zdrev_number (repo_name, commit_node): + zanrepo = hgapi.Repo (repo_name) + subprocess.call (['hg', '--cwd', repo_name, 'revert', '-r', commit_node, 'src/version.h']) + rx = re.compile (r'#define\s+ZD_SVN_REVISION_NUMBER\s+([0-9]+)') + result = None + + with open (repo_name + '/src/version.h') as version_file: + for line in version_file: + match = rx.match (line) + if match != None: + result = int (match.group (1)) + break + + subprocess.call (['hg', '--cwd', repo_name, 'revert', '-r.', 'src/version.h']) + + if result != None: + return result + + raise ValueError ("""Could not find ZD_SVN_REVISION_NUMBER in version.h""") + def force_poll(): global repocheck_timeout repocheck_timeout = 0
--- a/irc.py Fri Apr 24 06:40:08 2015 +0300 +++ b/irc.py Fri May 01 19:08:12 2015 +0300 @@ -32,6 +32,7 @@ import re import modulecore as ModuleCore import traceback +import time from configfile import Config import bt as Bt import hgpoll as HgPoll @@ -43,6 +44,7 @@ ColorChar = '\003' all_clients = [] +ClientsByName = {} class RestartError (Exception): def __init__ (self, value): @@ -99,6 +101,7 @@ asyncore.dispatcher.__init__ (self) self.create_socket (socket.AF_INET, socket.SOCK_STREAM) self.connect ((self.host, self.port)) + ClientsByName[self.name] = self def register_to_irc (self): ident = Config.get_value ('ident', default='cobalt') @@ -135,6 +138,7 @@ if self.verbose: print "[%s] <- %s" % (self.name, line) self.send ("%s\n" % line) + time.sleep (0.25) self.send_buffer = [] def handle_read (self):
--- a/mod_hg.py Fri Apr 24 06:40:08 2015 +0300 +++ b/mod_hg.py Fri May 01 19:08:12 2015 +0300 @@ -71,6 +71,13 @@ 'args': None, 'level': 'admin', }, + + { + 'name': 'updatezadevtopic', + 'description': """Updates #zadev topic""", + 'args': None, + 'level': 'admin', + }, ] } @@ -248,4 +255,7 @@ HgPoll.announce_ticket_resolved (args['ticket'], args['changeset']) def cmd_rebuildcommitsdb (bot, args, **rest): - HgPoll.g_CommitsDb.create_new() \ No newline at end of file + HgPoll.g_CommitsDb.create_new() + +def cmd_updatezadevtopic (bot, **rest): + HgPoll.update_zadev_topic() \ No newline at end of file