convert to Python 3 (only)
For Python 3, some modules got renamed or functionality was moved between modules. Also, Python 2 is as good as dead, so get rid of compat quirks and simplify some constructs. Signed-off-by: Nils Philippsen <nils@redhat.com>
This commit is contained in:
parent
992cb560a0
commit
15d20a860a
1 changed files with 28 additions and 35 deletions
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python -tt
|
||||
#!/usr/bin/python3 -tt
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2013-2019 Red Hat, Inc.
|
||||
|
@ -29,7 +29,7 @@ sync information from the Pagure into bugzilla
|
|||
This ... script takes information about package onwership and imports it
|
||||
into bugzilla.
|
||||
'''
|
||||
from __future__ import print_function
|
||||
|
||||
import re
|
||||
import argparse
|
||||
import datetime
|
||||
|
@ -38,26 +38,21 @@ import sys
|
|||
import os
|
||||
import itertools
|
||||
import json
|
||||
import xmlrpclib
|
||||
import codecs
|
||||
import xmlrpc.client
|
||||
import smtplib
|
||||
import traceback
|
||||
import multiprocessing.pool
|
||||
try:
|
||||
from email.Message import Message
|
||||
except ImportError:
|
||||
from email.message import EmailMessage as Message
|
||||
from email.message import EmailMessage
|
||||
|
||||
import bugzilla as bugzilla_lib
|
||||
import dogpile.cache
|
||||
import requests
|
||||
import yaml
|
||||
from six import string_types
|
||||
import fedora.client
|
||||
from fedora.client.fas2 import AccountSystem
|
||||
|
||||
from requests.adapters import HTTPAdapter
|
||||
from requests.packages.urllib3.util.retry import Retry
|
||||
from urllib3.util import Retry
|
||||
|
||||
|
||||
env = 'staging'
|
||||
|
@ -151,7 +146,7 @@ PDC_TYPES = {
|
|||
'modules': 'module',
|
||||
'container': 'container',
|
||||
}
|
||||
INVERSE_PDC_TYPES = dict([(v, k) for k, v in PDC_TYPES.items()])
|
||||
INVERSE_PDC_TYPES = {v: k for k, v in PDC_TYPES.items()}
|
||||
|
||||
|
||||
# When querying for current info, take segments of 1000 packages a time
|
||||
|
@ -231,7 +226,7 @@ class DataChangedError(Exception):
|
|||
def segment(iterable, chunk, fill=None):
|
||||
'''Collect data into `chunk` sized block'''
|
||||
args = [iter(iterable)] * chunk
|
||||
return itertools.izip_longest(*args, fillvalue=fill)
|
||||
return itertools.zip_longest(*args, fillvalue=fill)
|
||||
|
||||
|
||||
class ProductCache(dict):
|
||||
|
@ -256,7 +251,7 @@ class ProductCache(dict):
|
|||
elif BZCOMPAPI == 'component.get':
|
||||
# Way that's undocumented in the partner-bugzilla api but works
|
||||
# currently
|
||||
pkglist = projects_dict[key].keys()
|
||||
pkglist = list(projects_dict[key])
|
||||
products = {}
|
||||
for pkg_segment in segment(pkglist, BZ_PKG_SEGMENT):
|
||||
# Format that bugzilla will understand. Strip None's that
|
||||
|
@ -280,7 +275,7 @@ class ProductCache(dict):
|
|||
return super(ProductCache, self).__getitem__(key)
|
||||
|
||||
|
||||
class BugzillaProxy(object):
|
||||
class BugzillaProxy:
|
||||
|
||||
def __init__(self, bzServer, username, password, acls):
|
||||
self.bzXmlRpcServer = bzServer
|
||||
|
@ -355,11 +350,11 @@ class BugzillaProxy(object):
|
|||
# Lookup product
|
||||
try:
|
||||
product = self.productCache[collection]
|
||||
except xmlrpclib.Fault as e:
|
||||
except xmlrpc.client.Fault as e:
|
||||
# Output something useful in args
|
||||
e.args = (e.faultCode, e.faultString)
|
||||
raise
|
||||
except xmlrpclib.ProtocolError as e:
|
||||
except xmlrpc.client.ProtocolError as e:
|
||||
e.args = ('ProtocolError', e.errcode, e.errmsg)
|
||||
raise
|
||||
|
||||
|
@ -411,11 +406,11 @@ class BugzillaProxy(object):
|
|||
if not DRYRUN:
|
||||
try:
|
||||
self.server.editcomponent(data)
|
||||
except xmlrpclib.Fault as e:
|
||||
except xmlrpc.client.Fault as e:
|
||||
# Output something useful in args
|
||||
e.args = (data, e.faultCode, e.faultString)
|
||||
raise
|
||||
except xmlrpclib.ProtocolError as e:
|
||||
except xmlrpc.client.ProtocolError as e:
|
||||
e.args = ('ProtocolError', e.errcode, e.errmsg)
|
||||
raise
|
||||
else:
|
||||
|
@ -441,7 +436,7 @@ class BugzillaProxy(object):
|
|||
if not DRYRUN:
|
||||
try:
|
||||
self.server.addcomponent(data)
|
||||
except xmlrpclib.Fault as e:
|
||||
except xmlrpc.client.Fault as e:
|
||||
# Output something useful in args
|
||||
e.args = (data, e.faultCode, e.faultString)
|
||||
raise
|
||||
|
@ -456,7 +451,7 @@ def send_email(fromAddress, toAddress, subject, message, ccAddress=None):
|
|||
# Send no email in staging...
|
||||
pass
|
||||
else:
|
||||
msg = Message()
|
||||
msg = EmailMessage()
|
||||
msg.add_header('To', ','.join(toAddress))
|
||||
msg.add_header('From', fromAddress)
|
||||
msg.add_header('Subject', subject)
|
||||
|
@ -638,7 +633,7 @@ def _to_legacy_schema(product_and_project, session=None):
|
|||
# Check if the Bugzilla ticket assignee has been manually overridden
|
||||
override_yaml = _get_override_yaml(project)
|
||||
if override_yaml.get(product) \
|
||||
and isinstance(override_yaml[product], string_types):
|
||||
and isinstance(override_yaml[product], str):
|
||||
owner = override_yaml[product]
|
||||
|
||||
return {
|
||||
|
@ -661,8 +656,6 @@ def _to_legacy_schema(product_and_project, session=None):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Script syncing information between Pagure and bugzilla'
|
||||
)
|
||||
|
@ -775,21 +768,21 @@ if __name__ == '__main__':
|
|||
# Initialize the connection to bugzilla
|
||||
bugzilla = BugzillaProxy(BZSERVER, BZUSER, BZPASS, projects_dict)
|
||||
|
||||
for product in projects_dict.keys():
|
||||
for product, pkgs in projects_dict.items():
|
||||
if product not in PRODUCTS:
|
||||
continue
|
||||
for pkg in sorted(projects_dict[product]):
|
||||
for pkgname, pkginfo in sorted(projects_dict[product].items(),
|
||||
key=lambda x: x[0]):
|
||||
if VERBOSE:
|
||||
print("Assesssing bugzilla status for %r" % pkg)
|
||||
pkgInfo = projects_dict[product][pkg]
|
||||
print("Assesssing bugzilla status for %r" % pkgname)
|
||||
try:
|
||||
bugzilla.add_edit_component(
|
||||
pkg,
|
||||
pkgname,
|
||||
product,
|
||||
pkgInfo['owner'],
|
||||
pkgInfo['summary'],
|
||||
pkgInfo['qacontact'],
|
||||
pkgInfo['cclist']
|
||||
pkginfo['owner'],
|
||||
pkginfo['summary'],
|
||||
pkginfo['qacontact'],
|
||||
pkginfo['cclist']
|
||||
)
|
||||
except ValueError as e:
|
||||
# A username didn't have a bugzilla address
|
||||
|
@ -798,15 +791,15 @@ if __name__ == '__main__':
|
|||
# A Package or Collection was returned via xmlrpc but wasn't
|
||||
# present when we tried to change it
|
||||
errors.append(str(e.args))
|
||||
except xmlrpclib.ProtocolError as e:
|
||||
except xmlrpc.client.ProtocolError as e:
|
||||
# Unrecoverable and likely means that nothing is going to
|
||||
# succeed.
|
||||
errors.append(str(e.args))
|
||||
break
|
||||
except xmlrpclib.Error as e:
|
||||
except xmlrpc.client.Error as e:
|
||||
# An error occurred in the xmlrpc call. Shouldn't happen but
|
||||
# we better see what it is
|
||||
errors.append('%s -- %s' % (pkg, e.args[-1]))
|
||||
errors.append('%s -- %s' % (pkgname, e.args[-1]))
|
||||
|
||||
# Send notification of errors
|
||||
if errors:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue