pep8: consistently use lower case variable names

Previously, we had a mixture of lower_case_name and mixedCaseName. Use
lower case names except where external APIs force us to do otherwise.

Signed-off-by: Nils Philippsen <nils@redhat.com>
This commit is contained in:
Nils Philippsen 2019-11-21 15:35:06 +01:00
parent 26c3288951
commit be18b8f87a

View file

@ -112,16 +112,16 @@ def segment(iterable, chunk, fill=None):
class BugzillaProxy: class BugzillaProxy:
def __init__(self, bzServer, username, password, config): def __init__(self, bz_server, username, password, config):
self.bzXmlRpcServer = bzServer self.bz_xmlrpc_server = bz_server
self.username = username self.username = username
self.password = password self.password = password
self.server = Bugzilla( self.server = Bugzilla(
url=self.bzXmlRpcServer, url=self.bz_xmlrpc_server,
user=self.username, user=self.username,
password=self.password) password=self.password)
self.productCache = {} self.product_cache = {}
# Connect to the fedora account system # Connect to the fedora account system
self.fas = AccountSystem( self.fas = AccountSystem(
@ -132,13 +132,13 @@ class BugzillaProxy:
self.config = config self.config = config
try: try:
self.userCache = self.fas.people_by_key( self.user_cache = self.fas.people_by_key(
key='username', key='username',
fields=['bugzilla_email']) fields=['bugzilla_email'])
except fedora.client.ServerError: except fedora.client.ServerError:
# Sometimes, building the userCache up front fails with a timeout. # Sometimes, building the user cache up front fails with a timeout.
# It's ok, we build the cache as-needed later in the script. # It's ok, we build the cache as-needed later in the script.
self.userCache = {} self.user_cache = {}
def build_product_cache(self, pagure_project): def build_product_cache(self, pagure_project):
""" Cache the bugzilla info about each package in each product. """ Cache the bugzilla info about each package in each product.
@ -149,7 +149,7 @@ class BugzillaProxy:
# Old API -- in python-bugzilla. But with current server, this # Old API -- in python-bugzilla. But with current server, this
# gives ProxyError # gives ProxyError
for collection, product in self.config["products"].items(): for collection, product in self.config["products"].items():
self.productCache[collection] = self.server.getcomponentsdetails(product) self.product_cache[collection] = self.server.getcomponentsdetails(product)
elif self.config['bugzilla']['compat_api'] == 'component.get': elif self.config['bugzilla']['compat_api'] == 'component.get':
# Way that's undocumented in the partner-bugzilla api but works # Way that's undocumented in the partner-bugzilla api but works
# currently # currently
@ -185,7 +185,7 @@ class BugzillaProxy:
initialcclist=package['default_cc'] initialcclist=package['default_cc']
) )
products[package['name'].lower()] = product products[package['name'].lower()] = product
self.productCache[collection] = products self.product_cache[collection] = products
def _get_bugzilla_email(self, username): def _get_bugzilla_email(self, username):
'''Return the bugzilla email address for a user. '''Return the bugzilla email address for a user.
@ -194,14 +194,14 @@ class BugzillaProxy:
reloads the cache from fas and tries again. reloads the cache from fas and tries again.
''' '''
try: try:
return self.userCache[username]['bugzilla_email'].lower() return self.user_cache[username]['bugzilla_email'].lower()
except KeyError: except KeyError:
if username.startswith('@'): if username.startswith('@'):
group = self.fas.group_by_name(username[1:]) group = self.fas.group_by_name(username[1:])
bz_email = group.mailing_list bz_email = group.mailing_list
if bz_email is None: if bz_email is None:
return return
self.userCache[username] = { self.user_cache[username] = {
'bugzilla_email': bz_email} 'bugzilla_email': bz_email}
else: else:
person = self.fas.person_by_username(username) person = self.fas.person_by_username(username)
@ -209,21 +209,21 @@ class BugzillaProxy:
if bz_email is None: if bz_email is None:
return return
self.userCache[username] = {'bugzilla_email': bz_email} self.user_cache[username] = {'bugzilla_email': bz_email}
return self.userCache[username]['bugzilla_email'].lower() return self.user_cache[username]['bugzilla_email'].lower()
def add_edit_component(self, package, collection, owner, description=None, def add_edit_component(self, package, collection, owner, description=None,
qacontact=None, cclist=None, print_fas_names=False): qacontact=None, cclist=None, print_fas_names=False):
'''Add or update a component to have the values specified. '''Add or update a component to have the values specified.
''' '''
# Turn the cclist into something usable by bugzilla # Turn the cclist into something usable by bugzilla
initialCCEmails = [] initial_cc_emails = []
initialCCFASNames = [] initial_cc_fasnames = []
for watcher in cclist: for watcher in cclist:
bz_email = self._get_bugzilla_email(watcher) bz_email = self._get_bugzilla_email(watcher)
if bz_email: if bz_email:
initialCCEmails.append(bz_email) initial_cc_emails.append(bz_email)
initialCCFASNames.append(watcher) initial_cc_fasnames.append(watcher)
else: else:
print(f"** {watcher} has no bugzilla_email or mailing_list set " print(f"** {watcher} has no bugzilla_email or mailing_list set "
f"({collection}/{package}) **") f"({collection}/{package}) **")
@ -231,13 +231,13 @@ class BugzillaProxy:
# Add owner to the cclist so comaintainers taking over a bug don't # Add owner to the cclist so comaintainers taking over a bug don't
# have to do this manually # have to do this manually
owner_email = self._get_bugzilla_email(owner) owner_email = self._get_bugzilla_email(owner)
if owner_email not in initialCCEmails: if owner_email not in initial_cc_emails:
initialCCEmails.append(owner_email) initial_cc_emails.append(owner_email)
initialCCFASNames.append(owner) initial_cc_fasnames.append(owner)
# Lookup product # Lookup product
try: try:
product = self.productCache[collection] product = self.product_cache[collection]
except xmlrpc.client.Fault as e: except xmlrpc.client.Fault as e:
# Output something useful in args # Output something useful in args
e.args = (e.faultCode, e.faultString) e.args = (e.faultCode, e.faultString)
@ -246,8 +246,8 @@ class BugzillaProxy:
e.args = ('ProtocolError', e.errcode, e.errmsg) e.args = ('ProtocolError', e.errcode, e.errmsg)
raise raise
pkgKey = package.lower() pkg_key = package.lower()
if pkgKey in product: if pkg_key in product:
# edit the package information # edit the package information
data = {} data = {}
@ -258,21 +258,21 @@ class BugzillaProxy:
qacontact_email = 'extras-qa@fedoraproject.org' qacontact_email = 'extras-qa@fedoraproject.org'
# Check for changes to the owner, qacontact, or description # Check for changes to the owner, qacontact, or description
if product[pkgKey]['initialowner'] != owner_email: if product[pkg_key]['initialowner'] != owner_email:
data['initialowner'] = owner_email data['initialowner'] = owner_email
if description and product[pkgKey]['description'] != description: if description and product[pkg_key]['description'] != description:
data['description'] = description data['description'] = description
if qacontact and product[pkg_key]['initialqacontact'] != qacontact_email: if qacontact and product[pkg_key]['initialqacontact'] != qacontact_email:
data['initialqacontact'] = qacontact_email data['initialqacontact'] = qacontact_email
if len(product[pkgKey]['initialcclist']) != len(initialCCEmails): if len(product[pkg_key]['initialcclist']) != len(initial_cc_emails):
data['initialcclist'] = initialCCEmails data['initialcclist'] = initial_cc_emails
else: else:
for cc_member in product[pkgKey]['initialcclist']: for cc_member in product[pkg_key]['initialcclist']:
if cc_member not in initialCCEmails: if cc_member not in initial_cc_emails:
data['initialcclist'] = initialCCEmails data['initialcclist'] = initial_cc_emails
break break
if data: if data:
@ -288,10 +288,10 @@ class BugzillaProxy:
if key == 'initialowner': if key == 'initialowner':
value = owner value = owner
else: else:
value = initialCCFASNames value = initial_cc_fasnames
print(f" {key} changed to `{value}`") print(f" {key} changed to FAS name(s) `{value}`")
else: else:
print(f" {key} changed from `{product[pkgKey][key]} " print(f" {key} changed from `{product[pkg_key][key]} "
f"to `{data.get(key)}`") f"to `{data.get(key)}`")
# FIXME: initialowner has been made mandatory for some # FIXME: initialowner has been made mandatory for some
@ -321,8 +321,8 @@ class BugzillaProxy:
'initialowner': owner_email, 'initialowner': owner_email,
'initialqacontact': qacontact_email 'initialqacontact': qacontact_email
} }
if initialCCEmails: if initial_cc_emails:
data['initialcclist'] = initialCCEmails data['initialcclist'] = initial_cc_emails
if self.config["verbose"]: if self.config["verbose"]:
print('[ADDCOMP] %s/%s' % (data["product"], data["component"])) print('[ADDCOMP] %s/%s' % (data["product"], data["component"]))
@ -338,7 +338,7 @@ class BugzillaProxy:
raise raise
def send_email(fromAddress, toAddress, subject, message, ccAddress=None): def send_email(from_address, to_address, subject, message, cc_address=None):
'''Send an email if there's an error. '''Send an email if there's an error.
This will be replaced by sending messages to a log later. This will be replaced by sending messages to a log later.
@ -348,15 +348,15 @@ def send_email(fromAddress, toAddress, subject, message, ccAddress=None):
pass pass
else: else:
msg = EmailMessage() msg = EmailMessage()
msg.add_header('To', ','.join(toAddress)) msg.add_header('To', ','.join(to_address))
msg.add_header('From', fromAddress) msg.add_header('From', from_address)
msg.add_header('Subject', subject) msg.add_header('Subject', subject)
if ccAddress is not None: if cc_address is not None:
msg.add_header('Cc', ','.join(ccAddress)) msg.add_header('Cc', ','.join(cc_address))
toAddress = toAddress + ccAddress to_address += cc_address
msg.set_payload(message) msg.set_payload(message)
smtp = smtplib.SMTP('bastion') smtp = smtplib.SMTP('bastion')
smtp.sendmail(fromAddress, toAddress, msg.as_string()) smtp.sendmail(from_address, to_address, msg.as_string())
smtp.quit() smtp.quit()
@ -459,7 +459,7 @@ class DistgitBugzillaSync:
[user_email], [user_email],
subject='Please fix your bugzilla.redhat.com account', subject='Please fix your bugzilla.redhat.com account',
message=self.env['tmpl_user_email'], message=self.env['tmpl_user_email'],
ccAddress=self.env['notify_emails'], cc_address=self.env['notify_emails'],
) )
new_data[user_email] = { new_data[user_email] = {