Permalink
Browse files

Watch approved uploads

  • Loading branch information...
athos-ribeiro committed Aug 2, 2018
1 parent 6caa9f8 commit 189083010d99fb7840122ad5e5a697ad6994fce8
Showing with 73 additions and 5 deletions.
  1. +63 −0 salt/files/check_new_uploads
  2. +10 −5 salt/obs.sls
@@ -0,0 +1,63 @@
#!/usr/bin/env python3
import imaplib
import email
import subprocess
from datetime import datetime, timedelta
import time
def parse_message(msg):
lines = msg.split('\n')
mapping = {
'Source': 'name',
'Version': 'version',
'Architecture': 'arch',
'Distribution': 'dist',
'Maintainer': 'maintainer'
}
pkg = {}
for line in lines:
if len(mapping) == 0:
break
for field, target in mapping.items():
if line.startswith('%s: ' % field):
val = line[len(field) + 2:]
pkg[target] = val.strip()
del mapping[field]
break
return pkg
def trigger_build(pkg):
subprocess.run(['trigger_clang_build', pkg['name']])
subprocess.run(['apt', 'update'])
list_id = '<debian-devel-changes.lists.debian.org>'
M = imaplib.IMAP4_SSL(IMAP_SERVER)
M.login(USERNAME, PASSWORD)
M.select()
typ, data = M.search(None, 'UNSEEN')
# typ, data = M.search(None, 'ALL')
for num in data[0].split():
typ, data = M.fetch(num, '(RFC822)')
parsed_email = email.message_from_bytes(data[0][1])
# We want to give some time so the upload can propagate to the mirrors
email_time = email.utils.parsedate_tz(parsed_email['date'])
email_time_utc = email.utils.mktime_tz(email_time)
upload_time_limit = time.time() - 4*60*60
if email_time_utc > upload_time_limit:
# Too recent to be parsed
M.store(num, '-FLAGS', '\\SEEN')
continue
if parsed_email['subject'].startswith('Accepted') and parsed_email['list-id'] == list_id:
pkg = parse_message(parsed_email.get_payload())
if (pkg['dist'] in ['unstable', 'sid']) and 'amd64' in pkg['arch']:
trigger_build(pkg)
# M.store(num, '+FLAGS', '\\Deleted')
# M.expunge()
M.close()
M.logout()
View
@@ -254,11 +254,16 @@ create_debian_testing_test_project:
- group: root
- mode: 755
{% if salt['grains.get']('obs_service_build') != 'done' %}
build_obs_clang_build_package:
cmd.run:
- name: trigger_clang_build obs-service-clang-build
grains.present:
- name: obs_service_build
- value: done
{% endif %}
/usr/local/bin/check_new_uploads:
file.managed:
- source: salt://files/check_new_uploads
- user: root
- group: root
- mode: 755
cron.present:
- user: root
- hour: '*/4'

0 comments on commit 1890830

Please sign in to comment.