add command line options

This commit is contained in:
Ludwig Nussel 2014-08-14 17:04:35 +02:00
parent 51115ac4a3
commit a1b5edc5a8

View File

@ -27,6 +27,21 @@ import smtplib
from email.mime.text import MIMEText from email.mime.text import MIMEText
import os import os
import sys import sys
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")
(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)
url = "http://download.opensuse.org/factory/iso/" url = "http://download.opensuse.org/factory/iso/"
iso = "openSUSE-Factory-DVD-x86_64-Current.iso" iso = "openSUSE-Factory-DVD-x86_64-Current.iso"
@ -49,10 +64,14 @@ if m is None:
raise Exception("invalid location") raise Exception("invalid location")
version = m.group(1) version = m.group(1)
if options.verbose:
print "found version", version
if os.path.lexists(current_fn): if os.path.lexists(current_fn):
prev = os.readlink(current_fn) prev = os.readlink(current_fn)
if prev == version: if prev == version:
if options.verbose:
print "version unchanged, exit"
sys.exit(0) sys.exit(0)
u = urlparse(url+changes%version) u = urlparse(url+changes%version)
@ -72,14 +91,24 @@ res = conn.getresponse()
if res.status != 200: if res.status != 200:
raise Exception("http fail: %s %s"%(res.status, res.reason)) raise Exception("http fail: %s %s"%(res.status, res.reason))
msg = MIMEText(res.read()) txt = res.read()
msg['Subject'] = 'New Factory snapshot %s released!'%version if not "====" in txt:
msg['From'] = "Ludwig Nussel <ludwig.nussel@suse.de>" if options.verbose:
msg['To'] = "opensuse-factory@opensuse.org" print >>sys.stderr, "no changes or file corrupt? not sending anything"
sys.exit(1)
s = smtplib.SMTP('relay.suse.de') msg = MIMEText(txt)
s.sendmail('ludwig.nussel@suse.de', [msg['To']], msg.as_string()) msg['Subject'] = 'New Factory snapshot %s released!'%version
s.quit() msg['From'] = options.sender
msg['To'] = options.to
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()
tmpfn = os.path.join(os.path.dirname(__file__), ".announcer-current-version") tmpfn = os.path.join(os.path.dirname(__file__), ".announcer-current-version")
os.symlink(version, tmpfn) os.symlink(version, tmpfn)