2014-08-08 15:35:33 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
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
|
2017-05-05 12:33:57 +02:00
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import yaml
|
2017-01-27 12:49:12 +01:00
|
|
|
from xdg.BaseDirectory import save_data_path
|
2017-05-05 12:33:57 +02:00
|
|
|
from collections import namedtuple
|
|
|
|
|
|
|
|
logger = logging.getLogger()
|
|
|
|
|
|
|
|
# map of default config entries
|
|
|
|
config_defaults = {
|
2018-01-25 16:15:33 -06:00
|
|
|
'sender': 'noreply@opensuse.org',
|
|
|
|
'to': 'opensuse-factory@opensuse.org',
|
|
|
|
'relay': 'relay.suse.de',
|
2017-05-05 12:33:57 +02:00
|
|
|
'url' : "http://download.opensuse.org/tumbleweed/iso/",
|
|
|
|
'iso' : "openSUSE-Tumbleweed-DVD-x86_64-Current.iso",
|
|
|
|
'name' : 'factory-announcer',
|
2017-10-20 08:54:37 +02:00
|
|
|
'subject' : 'New Tumbleweed snapshot {version} released!',
|
2017-05-05 12:33:57 +02:00
|
|
|
'changesfile' : "Changes.{version}.txt",
|
|
|
|
'bodytemplate' : """
|
2015-12-14 17:59:21 +01:00
|
|
|
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:
|
2017-05-05 12:33:57 +02:00
|
|
|
https://openqa.opensuse.org/tests/overview?distri=opensuse&groupid=1&version=Tumbleweed&build={version}
|
2016-01-27 13:20:44 +01:00
|
|
|
|
2018-05-31 19:30:06 +09:30
|
|
|
Please do not reply to this email to report issues, rather file a bug
|
2018-05-31 20:00:44 +09:30
|
|
|
on bugzilla.opensuse.org. For more information on filing bugs please
|
2018-05-31 19:30:06 +09:30
|
|
|
see https://en.opensuse.org/openSUSE:Submitting_bug_reports
|
2016-07-19 11:37:55 +02:00
|
|
|
|
2017-05-05 12:33:57 +02:00
|
|
|
{text}
|
|
|
|
""",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
def _load_config(handle = None):
|
|
|
|
d = config_defaults
|
|
|
|
y = yaml.safe_load(handle) if handle is not None else {}
|
|
|
|
return namedtuple('Config', sorted(d.keys()))(*[ y.get(p, d[p]) for p in sorted(d.keys()) ])
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="Announce new snapshots")
|
|
|
|
parser.add_argument("--dry", action="store_true", help="dry run")
|
|
|
|
parser.add_argument("--debug", action="store_true", help="debug output")
|
|
|
|
parser.add_argument("--verbose", action="store_true", help="verbose")
|
|
|
|
parser.add_argument("--from", dest='sender', metavar="EMAIL", help="sender email address")
|
|
|
|
parser.add_argument("--to", metavar="EMAIL", help="recepient email address")
|
|
|
|
parser.add_argument("--relay", metavar="RELAY", help="SMTP relay server address")
|
|
|
|
parser.add_argument("--version", metavar="VERSION", help="announce specific version")
|
|
|
|
parser.add_argument("--config", metavar="FILE", type=argparse.FileType(), help="YAML config file to override defaults")
|
|
|
|
parser.add_argument("--dump-config", action="store_true", help="dump built in YAML config")
|
|
|
|
|
|
|
|
options = parser.parse_args()
|
|
|
|
|
|
|
|
# Set logging configuration
|
|
|
|
logging.basicConfig(level=logging.DEBUG if options.debug
|
|
|
|
else logging.INFO,
|
|
|
|
format='%(asctime)s - %(module)s:%(lineno)d - %(levelname)s - %(message)s')
|
|
|
|
|
|
|
|
if options.dump_config:
|
|
|
|
print yaml.dump(config_defaults, default_flow_style=False)
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
config = _load_config(options.config)
|
|
|
|
|
|
|
|
if not options.sender:
|
|
|
|
options.sender = config.sender
|
|
|
|
if not options.to:
|
|
|
|
options.to = config.to
|
|
|
|
if not options.relay:
|
|
|
|
options.relay = config.relay
|
|
|
|
|
|
|
|
if not options.sender or not options.to or not options.relay:
|
|
|
|
logger.error("need to specify --from and --to and --relay")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
datadir = save_data_path('opensuse.org', config.name)
|
2015-12-14 17:59:21 +01:00
|
|
|
|
2017-05-05 12:33:57 +02:00
|
|
|
current_fn = os.path.join(datadir, "announcer-current-version")
|
2014-08-08 15:35:33 +02:00
|
|
|
|
2016-01-19 14:00:30 +01:00
|
|
|
if not options.version:
|
2017-05-05 12:33:57 +02:00
|
|
|
u = urlparse(urljoin(config.url, config.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
|
|
|
|
2018-10-24 16:29:15 -05:00
|
|
|
m = re.search(r'(?:Snapshot|Build)([\d.]+)-Media', loc)
|
2016-01-19 14:00:30 +01:00
|
|
|
if m is None:
|
2017-05-05 12:33:57 +02:00
|
|
|
raise Exception("failed to parse %s"%loc)
|
2014-08-08 15:35:33 +02:00
|
|
|
|
2016-01-19 14:00:30 +01:00
|
|
|
version = m.group(1)
|
2017-05-05 12:33:57 +02:00
|
|
|
logger.debug("found version %s", version)
|
2016-01-19 14:00:30 +01:00
|
|
|
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:
|
2017-05-05 12:33:57 +02:00
|
|
|
logger.debug("version unchanged, exit")
|
2014-08-11 16:23:19 +02:00
|
|
|
sys.exit(0)
|
2014-08-08 15:35:33 +02:00
|
|
|
|
2017-05-05 12:33:57 +02:00
|
|
|
u = urlparse(urljoin(config.url, config.changesfile.format(version=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:
|
2017-05-05 12:33:57 +02:00
|
|
|
logger.error("no changes or file corrupt? not sending anything")
|
2014-08-14 17:04:35 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2017-05-05 12:33:57 +02:00
|
|
|
msg = MIMEText(config.bodytemplate.format(version=version, text=txt))
|
|
|
|
msg['Subject'] = config.subject.format(version=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:
|
2017-05-05 12:33:57 +02:00
|
|
|
logger.info("announcing version {}".format(version))
|
2014-08-14 17:04:35 +02:00
|
|
|
s = smtplib.SMTP(options.relay)
|
|
|
|
s.sendmail(options.sender, [msg['To']], msg.as_string())
|
|
|
|
s.quit()
|
2014-08-08 15:35:33 +02:00
|
|
|
|
2017-05-05 12:33:57 +02:00
|
|
|
tmpfn = os.path.join(datadir, ".announcer-current-version")
|
2014-08-14 17:55:45 +02:00
|
|
|
os.symlink(version, tmpfn)
|
|
|
|
os.rename(tmpfn, current_fn)
|
2014-08-08 15:35:33 +02:00
|
|
|
|