Skip to content

Instantly share code, notes, and snippets.

@ewdurbin
Created October 13, 2017 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ewdurbin/ba3304b6c0d6c48ccace903d3a567755 to your computer and use it in GitHub Desktop.
Save ewdurbin/ba3304b6c0d6c48ccace903d3a567755 to your computer and use it in GitHub Desktop.
from collections import defaultdict
import psycopg2
from psycopg2.extras import DictCursor
project_owners = defaultdict(set)
project_maintainers = defaultdict(set)
conn = psycopg2.connect("dbname=journals")
cur = conn.cursor(cursor_factory=DictCursor)
cur.execute("SELECT * FROM journals ORDER BY submitted_date asc")
def normalize_user(user):
return user.lower().replace(' ', '.')
for journal in cur:
project_name = journal['name'].lower()
action = journal['action']
if action.startswith('add Owner '):
user = normalize_user(' '.join(action.split()[2:]))
project_owners[project_name].add(user)
if action.startswith('add Maintainer '):
user = normalize_user(' '.join(action.split()[2:]))
project_maintainers[project_name].add(user)
if action.startswith('remove Owner '):
user = normalize_user(' '.join(action.split()[2:]))
try:
project_owners[project_name].remove(user)
except KeyError:
pass
if action.startswith('remove Maintainer '):
user = normalize_user(' '.join(action.split()[2:]))
try:
project_maintainers[project_name].remove(user)
except KeyError:
pass
if action.startswith('remove file'):
action_user = normalize_user(journal['submitted_by'])
if action_user not in project_owners[project_name] and action_user not in project_maintainers[project_name]:
if action_user not in ['dstufft', 'ewdurbin', 'deleted-user', 'deleted.user']:
print('Package maliciously removed by %s'%(action_user))
print(journal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment