summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2016-02-06 16:23:01 +0100
committerLukas Fleischer <lfleischer@archlinux.org>2016-02-06 16:23:01 +0100
commitf8b3cb97e54f9de73c6c2fca0cfade7e1657f1e4 (patch)
tree6fd3b1e9fd15d54e5fb0f2855000655231920dce /scripts
parentaaa138cd38d919072fd56d58b1eb32d5e3bc1e80 (diff)
downloadaurweb-f8b3cb97e54f9de73c6c2fca0cfade7e1657f1e4.tar.xz
Fix issues reported by pyflakes
Fix several style issues and remove unneeded imports/assignments. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/notify.py34
1 files changed, 27 insertions, 7 deletions
diff --git a/scripts/notify.py b/scripts/notify.py
index b5bf518..7b10efb 100755
--- a/scripts/notify.py
+++ b/scripts/notify.py
@@ -4,7 +4,6 @@ import configparser
import email.mime.text
import mysql.connector
import os
-import smtplib
import subprocess
import sys
import textwrap
@@ -29,12 +28,15 @@ reply_to = config.get('notifications', 'reply-to')
def headers_cc(cclist):
return {'Cc': str.join(', ', cclist)}
+
def headers_msgid(thread_id):
return {'Message-ID': thread_id}
+
def headers_reply(thread_id):
return {'In-Reply-To': thread_id, 'References': thread_id}
+
def send_notification(to, subject, body, refs, headers={}):
wrapped = ''
for line in body.splitlines():
@@ -54,23 +56,28 @@ def send_notification(to, subject, body, refs, headers={}):
p = subprocess.Popen([sendmail, '-t', '-oi'], stdin=subprocess.PIPE)
p.communicate(msg.as_bytes())
+
def username_from_id(cur, uid):
cur.execute('SELECT UserName FROM Users WHERE ID = %s', [uid])
return cur.fetchone()[0]
+
def pkgbase_from_id(cur, pkgbase_id):
cur.execute('SELECT Name FROM PackageBases WHERE ID = %s', [pkgbase_id])
return cur.fetchone()[0]
+
def pkgbase_from_pkgreq(cur, reqid):
cur.execute('SELECT PackageBaseID FROM PackageRequests WHERE ID = %s',
[reqid])
return cur.fetchone()[0]
+
def get_user_email(cur, uid):
cur.execute('SELECT Email FROM Users WHERE ID = %s', [uid])
return cur.fetchone()[0]
+
def get_maintainer_email(cur, pkgbase_id):
cur.execute('SELECT Users.Email FROM Users ' +
'INNER JOIN PackageBases ' +
@@ -78,6 +85,7 @@ def get_maintainer_email(cur, pkgbase_id):
'PackageBases.ID = %s', [pkgbase_id])
return cur.fetchone()[0]
+
def get_recipients(cur, pkgbase_id, uid):
cur.execute('SELECT DISTINCT Users.Email FROM Users ' +
'INNER JOIN CommentNotify ' +
@@ -86,6 +94,7 @@ def get_recipients(cur, pkgbase_id, uid):
'CommentNotify.PackageBaseID = %s', [uid, pkgbase_id])
return [row[0] for row in cur.fetchall()]
+
def get_request_recipients(cur, pkgbase_id, uid):
cur.execute('SELECT DISTINCT Users.Email FROM Users ' +
'INNER JOIN PackageBases ' +
@@ -93,25 +102,30 @@ def get_request_recipients(cur, pkgbase_id, uid):
'Users.ID = %s OR PackageBases.ID = %s', [uid, pkgbase_id])
return [row[0] for row in cur.fetchall()]
+
def get_comment(cur, comment_id):
cur.execute('SELECT Comments FROM PackageComments WHERE ID = %s',
[comment_id])
return cur.fetchone()[0]
+
def get_flagger_comment(cur, pkgbase_id):
cur.execute('SELECT FlaggerComment FROM PackageBases WHERE ID = %s',
[pkgbase_id])
return cur.fetchone()[0]
+
def get_request_comment(cur, reqid):
cur.execute('SELECT Comments FROM PackageRequests WHERE ID = %s', [reqid])
return cur.fetchone()[0]
+
def get_request_closure_comment(cur, reqid):
cur.execute('SELECT ClosureComment FROM PackageRequests WHERE ID = %s',
[reqid])
return cur.fetchone()[0]
+
def send_resetkey(cur, uid):
cur.execute('SELECT UserName, Email, ResetKey FROM Users WHERE ID = %s',
[uid])
@@ -126,6 +140,7 @@ def send_resetkey(cur, uid):
send_notification([to], subject, body, refs)
+
def welcome(cur, uid):
cur.execute('SELECT UserName, Email, ResetKey FROM Users WHERE ID = %s',
[uid])
@@ -140,14 +155,13 @@ def welcome(cur, uid):
send_notification([to], subject, body, refs)
+
def comment(cur, uid, pkgbase_id, comment_id):
user = username_from_id(cur, uid)
pkgbase = pkgbase_from_id(cur, pkgbase_id)
to = get_recipients(cur, pkgbase_id, uid)
text = get_comment(cur, comment_id)
- uri = aur_location + '/pkgbase/' + pkgbase + '/'
-
user_uri = aur_location + '/account/' + user + '/'
pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
@@ -164,6 +178,7 @@ def comment(cur, uid, pkgbase_id, comment_id):
send_notification(to, subject, body, refs, headers)
+
def flag(cur, uid, pkgbase_id):
user = username_from_id(cur, uid)
pkgbase = pkgbase_from_id(cur, pkgbase_id)
@@ -182,6 +197,7 @@ def flag(cur, uid, pkgbase_id):
send_notification(to, subject, body, refs)
+
def comaintainer_add(cur, pkgbase_id, uid):
pkgbase = pkgbase_from_id(cur, pkgbase_id)
to = [get_user_email(cur, uid)]
@@ -194,6 +210,7 @@ def comaintainer_add(cur, pkgbase_id, uid):
send_notification(to, subject, body, refs)
+
def comaintainer_remove(cur, pkgbase_id, uid):
pkgbase = pkgbase_from_id(cur, pkgbase_id)
to = [get_user_email(cur, uid)]
@@ -201,12 +218,13 @@ def comaintainer_remove(cur, pkgbase_id, uid):
pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
subject = 'AUR Co-Maintainer Notification for %s' % (pkgbase)
- body = 'You were removed from the co-maintainer list of %s [1].' % \
- (pkgbase)
+ body = ('You were removed from the co-maintainer list of %s [1].' %
+ (pkgbase))
refs = '[1] ' + pkgbase_uri + '\n'
send_notification(to, subject, body, refs)
+
def delete(cur, uid, old_pkgbase_id, new_pkgbase_id=None):
user = username_from_id(cur, uid)
old_pkgbase = pkgbase_from_id(cur, old_pkgbase_id)
@@ -215,7 +233,7 @@ def delete(cur, uid, old_pkgbase_id, new_pkgbase_id=None):
to = get_recipients(cur, old_pkgbase_id, uid)
user_uri = aur_location + '/account/' + user + '/'
- pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
+ pkgbase_uri = aur_location + '/pkgbase/' + old_pkgbase + '/'
subject = 'AUR Package deleted: %s' % (old_pkgbase)
if new_pkgbase_id:
@@ -236,6 +254,7 @@ def delete(cur, uid, old_pkgbase_id, new_pkgbase_id=None):
send_notification(to, subject, body, refs)
+
def request_open(cur, uid, reqid, reqtype, pkgbase_id, merge_into=None):
user = username_from_id(cur, uid)
pkgbase = pkgbase_from_id(cur, pkgbase_id)
@@ -268,12 +287,13 @@ def request_open(cur, uid, reqid, reqtype, pkgbase_id, merge_into=None):
send_notification(to, subject, body, refs, headers)
+
def request_close(cur, uid, reqid, reason):
user = username_from_id(cur, uid)
pkgbase_id = pkgbase_from_pkgreq(cur, reqid)
to = [aur_request_ml]
cc = get_request_recipients(cur, pkgbase_id, uid)
- text = get_request_closure_comment(cur, reqid);
+ text = get_request_closure_comment(cur, reqid)
user_uri = aur_location + '/account/' + user + '/'