43 # Possibly we're passed a date version instead. Try find the node for this. |
43 # Possibly we're passed a date version instead. Try find the node for this. |
44 try: |
44 try: |
45 datetime.strptime (args['key'], '%y%m%d-%H%M') |
45 datetime.strptime (args['key'], '%y%m%d-%H%M') |
46 HgPoll.make_commits_txt() |
46 HgPoll.make_commits_txt() |
47 commits_txt = open ('commits.txt', 'r') |
47 commits_txt = open ('commits.txt', 'r') |
48 |
48 |
49 for line in commits_txt: |
49 for line in commits_txt: |
50 data = line.replace ('\n', '').split (' ') |
50 data = line.replace ('\n', '').split (' ') |
51 if data[1] == args['key']: |
51 if data[1] == args['key']: |
52 node = data[0] |
52 node = data[0] |
53 break |
53 break |
54 else: |
54 else: |
55 bot.privmsg (replyto, 'couldn\'t find changset for date %s' % args['key']) |
55 bot.privmsg (replyto, 'couldn\'t find changset for date %s' % args['key']) |
56 return |
56 return |
57 #done |
|
58 except ValueError: |
57 except ValueError: |
59 pass |
58 pass |
60 #tried |
59 |
61 |
|
62 # The sandboxes contain all revisions in zandronum and zandronum-stable. |
60 # The sandboxes contain all revisions in zandronum and zandronum-stable. |
63 # Thus we only need to try find the revision in the sandbox repos. |
61 # Thus we only need to try find the revision in the sandbox repos. |
64 try: |
62 try: |
65 repo.hg_command ("log", "-r", node, "--template", " ") |
63 repo.hg_command ("log", "-r", node, "--template", " ") |
66 except hgapi.HgException: |
64 except hgapi.HgException: |
67 bot.privmsg (replyto, 'couldn\'t find changeset %s' % (node)) |
65 bot.privmsg (replyto, 'couldn\'t find changeset %s' % (node)) |
68 return |
66 return |
69 #tried |
67 |
70 |
|
71 try: |
68 try: |
72 data = repo.hg_command ("log", "-r", node, "--template", |
69 data = repo.hg_command ("log", "-r", node, "--template", |
73 "{node|short}@@@@@@@{desc}@@@@@@@{author}@@@@@@@{diffstat}@@@@@@@{date|hgdate}") |
70 "{node|short}@@@@@@@{desc}@@@@@@@{author}@@@@@@@{diffstat}@@@@@@@{date|hgdate}") |
74 data = data.split ('@@@@@@@') |
71 data = data.split ('@@@@@@@') |
75 |
72 |
76 node = data[0] |
73 node = data[0] |
77 message = data[1] |
74 message = data[1] |
78 author = data[2] |
75 author = data[2] |
79 diffstat = data[3] |
76 diffstat = data[3] |
80 date = datetime.utcfromtimestamp (int (data[4].split (' ')[0])) |
77 date = datetime.utcfromtimestamp (int (data[4].split (' ')[0])) |
81 delta = datetime.now() - date |
78 delta = datetime.now() - date |
82 datestring = '' |
79 datestring = '' |
83 |
80 |
84 # Remove the email address from the author if possible |
81 # Remove the email address from the author if possible |
85 match = re.compile (r'^(.+) <([^>]+)>$.*').match (author) |
82 match = re.compile (r'^(.+) <([^>]+)>$.*').match (author) |
86 if match: |
83 if match: |
87 author = match.group (1) |
84 author = match.group (1) |
88 email = match.group (2) |
85 email = match.group (2) |
89 |
86 |
90 username = Config.find_developer_by_email (email) |
87 username = Config.find_developer_by_email (email) |
91 |
88 |
92 if username != '': |
89 if username != '': |
93 author = username |
90 author = username |
94 |
91 |
95 if delta.days < 4: |
92 if delta.days < 4: |
96 if delta.days == 0: |
93 if delta.days == 0: |
97 if delta.seconds < 60: |
94 if delta.seconds < 60: |
98 datestring = 'just now' |
95 datestring = 'just now' |
99 elif delta.seconds < 3600: |
96 elif delta.seconds < 3600: |
104 datestring = '%d hour%s ago' % (hours, plural (hours)) |
101 datestring = '%d hour%s ago' % (hours, plural (hours)) |
105 else: |
102 else: |
106 datestring = '%d day%s ago' % (delta.days, plural (delta.days)) |
103 datestring = '%d day%s ago' % (delta.days, plural (delta.days)) |
107 else: |
104 else: |
108 datestring = 'on %s' % (str (date)) |
105 datestring = 'on %s' % (str (date)) |
109 #fi |
106 |
110 |
|
111 bot.privmsg (replyto, 'changeset %s (%s): committed by %s %s (%s)' % \ |
107 bot.privmsg (replyto, 'changeset %s (%s): committed by %s %s (%s)' % \ |
112 (node, date.strftime ('%y%m%d-%H%M'), author, datestring, diffstat)) |
108 (node, date.strftime ('%y%m%d-%H%M'), author, datestring, diffstat)) |
113 |
109 |
114 for line in message.split ('\n'): |
110 for line in message.split ('\n'): |
115 bot.privmsg (replyto, ' ' + line) |
111 bot.privmsg (replyto, ' ' + line) |
116 except hgapi.HgException as e: |
112 except hgapi.HgException as e: |
117 result = HgPoll.decipher_hgapi_error (e) |
113 result = HgPoll.decipher_hgapi_error (e) |
118 |
114 |
119 if result[0]: |
115 if result[0]: |
120 bot.privmsg (replyto, 'error: %s' % result[1]) |
116 bot.privmsg (replyto, 'error: %s' % result[1]) |
121 else: |
117 else: |
122 bot.privmsg (replyto, 'error: %s' % `e`) |
118 bot.privmsg (replyto, 'error: %s' % `e`) |
123 #tried |
|
124 |
119 |
125 def cmd_hg (bot, args, **rest): |
120 def cmd_hg (bot, args, **rest): |
126 try: |
121 try: |
127 repo = hgapi.Repo (args['repo']) |
122 repo = hgapi.Repo (args['repo']) |
128 result = repo.hg_command (*args['command']) |
123 result = repo.hg_command (*args['command']) |
129 self.privmsg (replyto, result) |
124 self.privmsg (replyto, result) |
130 except hgapi.hgapi.HgException as e: |
125 except hgapi.hgapi.HgException as e: |
131 result = HgPoll.decipher_hgapi_error (e) |
126 result = HgPoll.decipher_hgapi_error (e) |
132 |
127 |
133 if result[0]: |
128 if result[0]: |
134 self.privmsg (replyto, 'error: %s' % result[1]) |
129 self.privmsg (replyto, 'error: %s' % result[1]) |
135 else: |
130 else: |
136 self.privmsg (replyto, 'error: %s' % `e`) |
131 self.privmsg (replyto, 'error: %s' % `e`) |
137 #fi |
|
138 #tried |
|