From 214dedae86434397591cd5cbd9e0668f07e53a2c Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Mon, 18 Nov 2019 11:28:18 +0100 Subject: [PATCH] make the script a plain python file Replace template variables by normal Python ones, which we want to be able to set in a configuration file in the future. Signed-off-by: Nils Philippsen --- ...-bugzilla.py.j2 => pagure-sync-bugzilla.py | 86 +++++++++---------- 1 file changed, 42 insertions(+), 44 deletions(-) rename pagure-sync-bugzilla.py.j2 => pagure-sync-bugzilla.py (94%) diff --git a/pagure-sync-bugzilla.py.j2 b/pagure-sync-bugzilla.py similarity index 94% rename from pagure-sync-bugzilla.py.j2 rename to pagure-sync-bugzilla.py index 0a55a86..b6fd6a4 100644 --- a/pagure-sync-bugzilla.py.j2 +++ b/pagure-sync-bugzilla.py @@ -1,7 +1,7 @@ #!/usr/bin/python -tt # -*- coding: utf-8 -*- # -# Copyright © 2013-2017 Red Hat, Inc. +# Copyright © 2013-2019 Red Hat, Inc. # # This copyrighted material is made available to anyone wishing to use, modify, # copy, or redistribute it subject to the terms and conditions of the GNU @@ -60,6 +60,8 @@ from requests.adapters import HTTPAdapter from requests.packages.urllib3.util.retry import Retry +env = 'staging' + cache = dogpile.cache.make_region().configure( 'dogpile.cache.memory', expiration_time=3600, @@ -81,11 +83,10 @@ def retry_session(): return session -{% if env == 'staging' %} -BZSERVER = 'https://partner-bugzilla.redhat.com' -{% else %} -BZSERVER = 'https://bugzilla.redhat.com' -{% endif %} +if env == 'staging': + BZSERVER = 'https://partner-bugzilla.redhat.com' +else: + BZSERVER = 'https://bugzilla.redhat.com' BZUSER = '{{ bugzilla_user }}' BZPASS = '{{ bugzilla_password }}' @@ -100,21 +101,20 @@ NOTIFYEMAIL = [ VERBOSE = False DRYRUN = False -{% if env == 'staging' %} -FASURL = 'https://admin.stg.fedoraproject.org/accounts' -FASINSECURE = True -PAGUREURL = 'https://stg.pagure.io' -PAGURE_DIST_GIT_URL = 'https://src.stg.fedoraproject.org' -PDCURL = 'https://pdc.stg.fedoraproject.org/rest_api/v1/' -MDAPIURL = 'https://apps.stg.fedoraproject.org/mdapi/' -{% else %} -FASURL = 'https://admin.fedoraproject.org/accounts' -FASINSECURE = False -PAGUREURL = 'https://pagure.io' -PAGURE_DIST_GIT_URL = 'https://src.fedoraproject.org' -PDCURL = 'https://pdc.fedoraproject.org/rest_api/v1/' -MDAPIURL = 'https://apps.fedoraproject.org/mdapi/' -{% endif %} +if env == 'staging': + FASURL = 'https://admin.stg.fedoraproject.org/accounts' + FASINSECURE = True + PAGUREURL = 'https://stg.pagure.io' + PAGURE_DIST_GIT_URL = 'https://src.stg.fedoraproject.org' + PDCURL = 'https://pdc.stg.fedoraproject.org/rest_api/v1/' + MDAPIURL = 'https://apps.stg.fedoraproject.org/mdapi/' +else: + FASURL = 'https://admin.fedoraproject.org/accounts' + FASINSECURE = False + PAGUREURL = 'https://pagure.io' + PAGURE_DIST_GIT_URL = 'https://src.fedoraproject.org' + PDCURL = 'https://pdc.fedoraproject.org/rest_api/v1/' + MDAPIURL = 'https://apps.fedoraproject.org/mdapi/' EMAIL_FROM = 'accounts@fedoraproject.org' @@ -452,22 +452,21 @@ def send_email(fromAddress, toAddress, subject, message, ccAddress=None): This will be replaced by sending messages to a log later. ''' -{% if env == 'staging' %} - # Send no email in staging... - pass -{% else %} - msg = Message() - msg.add_header('To', ','.join(toAddress)) - msg.add_header('From', fromAddress) - msg.add_header('Subject', subject) - if ccAddress is not None: - msg.add_header('Cc', ','.join(ccAddress)) - toAddress = toAddress + ccAddress - msg.set_payload(message) - smtp = smtplib.SMTP('bastion') - smtp.sendmail(fromAddress, toAddress, msg.as_string()) - smtp.quit() -{% endif %} + if env == 'staging': + # Send no email in staging... + pass + else: + msg = Message() + msg.add_header('To', ','.join(toAddress)) + msg.add_header('From', fromAddress) + msg.add_header('Subject', subject) + if ccAddress is not None: + msg.add_header('Cc', ','.join(ccAddress)) + toAddress = toAddress + ccAddress + msg.set_payload(message) + smtp = smtplib.SMTP('bastion') + smtp.sendmail(fromAddress, toAddress, msg.as_string()) + smtp.quit() def notify_users(errors): @@ -723,13 +722,12 @@ if __name__ == '__main__': poc=poc, watchers=pagure_namespace_to_cc[namespace][name], )) -{% if env == 'staging' %} - # Filter out any modules, since we don't have rights to create new - # components in the "Fedora Modules" project yet - pagure_projects = [ - p for p in pagure_projects if p['namespace'] != 'modules' - ] -{% endif %} + if env == 'staging': + # Filter out any modules, since we don't have rights to create new + # components in the "Fedora Modules" project yet + pagure_projects = [ + p for p in pagure_projects if p['namespace'] != 'modules' + ] branches_url = PDCURL.split('rest_api')[0] + 'extras/active_branches.json' if VERBOSE: