-
Notifications
You must be signed in to change notification settings - Fork 15
/
announce.py
executable file
·110 lines (94 loc) · 2.73 KB
/
announce.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
# File: announce.py
# Version: 0.1
# Description: a script for announcing registry changes
# Last Modified: 2004-10-27
# Author: Peter Saint-Andre ([email protected])
# License: public domain
# HowTo: ./announce.py filename (without extension!)
# IMPORTS:
#
import glob
import os
from select import select
import smtplib
import socket
from string import split,strip,join,find
import sys
import time
from xml.dom.minidom import parse,parseString,Document
def getText(nodelist):
thisText = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
thisText = thisText + node.data
return thisText
# READ IN ARGS:
#
# 1. registry file name
regname = sys.argv[1];
regfile = regname + '.xml'
# PARSE REGISTRY HEADERS:
#
# - title
# - version
# - initials
# - remark
thereg = parse(regfile)
regNode = (thereg.getElementsByTagName("registry")[0])
headerNode = (regNode.getElementsByTagName("meta")[0])
titleNode = (headerNode.getElementsByTagName("title")[0])
title = getText(titleNode.childNodes)
revNode = (headerNode.getElementsByTagName("revision")[0])
versionNode = (revNode.getElementsByTagName("version")[0])
version = getText(versionNode.childNodes)
initialsNode = (revNode.getElementsByTagName("initials")[0])
initials = getText(initialsNode.childNodes)
remarkNode = (revNode.getElementsByTagName("remark")[0])
remark = getText(remarkNode.childNodes)
# what kind of action are we taking?
regflag = ""
if (version == "0.1"):
regflag = "new"
# SEND MAIL:
#
# From: [email protected]
# To: [email protected]
# Subject: UPDATED REGISTRY: $title
# [or "NEW REGISTRY:" if version 0.1]
# Body:
# The $title registry has been updated.
# Version: $version
# Changelog: $remark ($initials)
# URL: https://xmpp.org/registrar/$regname.html
fromaddr = "[email protected]"
# for testing...
# toaddrs = "[email protected]"
# for real...
toaddrs = "[email protected]"
if regflag == "new":
thesubject = 'NEW REGISTRY: '
announceline = 'The ' + title + ' registry has been created.'
else:
thesubject = 'UPDATED REGISTRY: '
announceline = 'The ' + title + ' registry has been updated.'
thesubject = thesubject + title
versionline = 'Version: ' + version
changelogline = 'Changelog: ' + remark + ' (' + initials + ')'
urlline = 'URL: https://xmpp.org/registrar/' + regname + '.html'
msg = "From: XMPP Registrar <%s>\r\n" % fromaddr
msg = msg + "To: %s\r\n" % toaddrs
msg = msg + "Subject: %s\r\n" % thesubject
msg = msg + announceline
msg = msg + "\r\n\n"
msg = msg + versionline
msg = msg + "\r\n\n"
msg = msg + changelogline
msg = msg + "\r\n\n"
msg = msg + urlline
msg = msg + "\r\n"
server = smtplib.SMTP('localhost')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
# END