2014-08-08 15:35:33 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Copyright (c) 2014 SUSE Linux Products GmbH
|
2016-01-19 14:00:30 +01:00
|
|
|
# Copyright (c) 2015, 2016 SUSE Linux GmbH
|
2014-08-08 15:35:33 +02:00
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
|
|
|
|
import httplib
|
|
|
|
import re
|
2016-01-21 10:45:29 +01:00
|
|
|
from urlparse import urlparse, urljoin
|
2014-08-08 15:35:33 +02:00
|
|
|
import smtplib
|
|
|
|
from email.mime.text import MIMEText
|
|
|
|
import os
|
|
|
|
import sys
|
2016-05-12 17:28:08 +02:00
|
|
|
import email.utils
|
2014-08-14 17:04:35 +02:00
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
parser = OptionParser()
|
|
|
|
parser.add_option("--dry", action="store_true", help="dry run")
|
|
|
|
parser.add_option("--debug", action="store_true", help="debug output")
|
|
|
|
parser.add_option("--verbose", action="store_true", help="verbose")
|
|
|
|
parser.add_option("--from", dest='sender', metavar="EMAIL", help="sender email address")
|
|
|
|
parser.add_option("--to", metavar="EMAIL", help="recepient email address")
|
|
|
|
parser.add_option("--relay", metavar="RELAY", help="SMTP relay server address")
|
2016-01-19 14:00:30 +01:00
|
|
|
parser.add_option("--version", metavar="VERSION", help="announce specific version")
|
2014-08-14 17:04:35 +02:00
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
if not options.sender or not options.to or not options.relay:
|
|
|
|
print >>sys.stderr, "need to specify --from and --to and --relay"
|
|
|
|
sys.exit(1)
|
2014-08-08 15:35:33 +02:00
|
|
|
|
2014-11-26 13:26:54 +01:00
|
|
|
url = "http://download.opensuse.org/tumbleweed/iso/"
|
|
|
|
iso = "openSUSE-Tumbleweed-DVD-x86_64-Current.iso"
|
2014-08-15 09:16:04 +02:00
|
|
|
changes = "Changes.%s.txt"
|
2015-12-14 17:59:21 +01:00
|
|
|
intro = """
|
|
|
|
Please note that this mail was generated by a script.
|
|
|
|
The described changes are computed based on the x86_64 DVD.
|
|
|
|
The full online repo contains too many changes to be listed here.
|
|
|
|
|
2016-01-27 13:20:44 +01:00
|
|
|
Please check the known defects of this snapshot before upgrading:
|
|
|
|
https://openqa.opensuse.org/tests/overview?distri=opensuse&groupid=1&version=Tumbleweed&build={}
|
|
|
|
|
2015-12-14 17:59:21 +01:00
|
|
|
"""
|
|
|
|
|
2014-08-08 15:35:33 +02:00
|
|
|
current_fn = os.path.join(os.path.dirname(__file__), "announcer-current-version")
|
|
|
|
|
2016-01-19 14:00:30 +01:00
|
|
|
if not options.version:
|
2016-01-21 10:45:29 +01:00
|
|
|
u = urlparse(urljoin(url, iso))
|
2016-01-19 14:00:30 +01:00
|
|
|
conn = httplib.HTTPConnection(u.hostname, 80)
|
|
|
|
conn.request('HEAD', u.path)
|
|
|
|
res = conn.getresponse()
|
|
|
|
if res.status != 302:
|
2016-05-12 17:30:40 +02:00
|
|
|
raise Exception("http fail: %s %s" % (res.status, res.reason))
|
2014-08-08 15:35:33 +02:00
|
|
|
|
2016-01-19 14:00:30 +01:00
|
|
|
loc = res.getheader('location')
|
|
|
|
if loc is None:
|
|
|
|
raise Exception("empty location!")
|
2014-08-08 15:35:33 +02:00
|
|
|
|
2016-01-19 14:00:30 +01:00
|
|
|
m = re.search('Snapshot(\d+)-Media', loc)
|
|
|
|
if m is None:
|
|
|
|
raise Exception("invalid location")
|
2014-08-08 15:35:33 +02:00
|
|
|
|
2016-01-19 14:00:30 +01:00
|
|
|
version = m.group(1)
|
|
|
|
if options.verbose:
|
|
|
|
print "found version", version
|
|
|
|
else:
|
|
|
|
version = options.version
|
2014-08-08 15:35:33 +02:00
|
|
|
|
2014-08-11 16:23:19 +02:00
|
|
|
if os.path.lexists(current_fn):
|
|
|
|
prev = os.readlink(current_fn)
|
|
|
|
if prev == version:
|
2014-08-14 17:04:35 +02:00
|
|
|
if options.verbose:
|
|
|
|
print "version unchanged, exit"
|
2014-08-11 16:23:19 +02:00
|
|
|
sys.exit(0)
|
2014-08-08 15:35:33 +02:00
|
|
|
|
2016-05-12 17:30:40 +02:00
|
|
|
u = urlparse(urljoin(url, changes % version))
|
2014-08-08 15:35:33 +02:00
|
|
|
conn = httplib.HTTPConnection(u.hostname, 80)
|
|
|
|
conn.request('HEAD', u.path)
|
|
|
|
res = conn.getresponse()
|
|
|
|
if res.status == 302:
|
|
|
|
|
|
|
|
loc = res.getheader('location')
|
|
|
|
if loc is None:
|
2016-05-12 17:30:40 +02:00
|
|
|
raise Exception("empty location!")
|
2014-08-08 15:35:33 +02:00
|
|
|
u = urlparse(loc)
|
|
|
|
|
|
|
|
conn = httplib.HTTPConnection(u.hostname, 80)
|
|
|
|
conn.request('GET', u.path)
|
|
|
|
res = conn.getresponse()
|
|
|
|
if res.status != 200:
|
2016-05-12 17:30:40 +02:00
|
|
|
raise Exception("http fail: %s %s" % (res.status, res.reason))
|
2014-08-08 15:35:33 +02:00
|
|
|
|
2014-08-14 17:04:35 +02:00
|
|
|
txt = res.read()
|
2016-05-12 17:30:40 +02:00
|
|
|
if "====" not in txt:
|
2014-08-14 17:04:35 +02:00
|
|
|
if options.verbose:
|
|
|
|
print >>sys.stderr, "no changes or file corrupt? not sending anything"
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-01-27 13:20:44 +01:00
|
|
|
msg = MIMEText(intro.format(version) + txt)
|
2016-05-12 17:30:40 +02:00
|
|
|
msg['Subject'] = 'New Tumbleweed snapshot %s released!' % version
|
2014-08-14 17:04:35 +02:00
|
|
|
msg['From'] = options.sender
|
|
|
|
msg['To'] = options.to
|
2015-03-16 09:48:50 +01:00
|
|
|
msg['Mail-Followup-To'] = options.to
|
2016-05-12 17:30:40 +02:00
|
|
|
msg['Date'] = email.utils.formatdate(localtime=1)
|
2016-05-12 17:28:08 +02:00
|
|
|
msg['Message-ID'] = email.utils.make_msgid()
|
2014-08-08 15:35:33 +02:00
|
|
|
|
2014-08-14 17:04:35 +02:00
|
|
|
if options.dry:
|
|
|
|
print "sending ..."
|
|
|
|
print msg.as_string()
|
|
|
|
else:
|
|
|
|
s = smtplib.SMTP(options.relay)
|
|
|
|
s.sendmail(options.sender, [msg['To']], msg.as_string())
|
|
|
|
s.quit()
|
2014-08-08 15:35:33 +02:00
|
|
|
|
2014-08-14 17:55:45 +02:00
|
|
|
tmpfn = os.path.join(os.path.dirname(__file__), ".announcer-current-version")
|
|
|
|
os.symlink(version, tmpfn)
|
|
|
|
os.rename(tmpfn, current_fn)
|
2014-08-08 15:35:33 +02:00
|
|
|
|
|
|
|
# vim: sw=4 et
|