Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Commit

Permalink
More Python3
Browse files Browse the repository at this point in the history
Signed-off-by: Nils Philippsen <[email protected]>
  • Loading branch information
nphilipp committed Jul 1, 2020
1 parent 4fa717e commit 88ea5e6
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 40 deletions.
47 changes: 24 additions & 23 deletions pdcupdater/commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

import logging
import logging.config
import sys
Expand Down Expand Up @@ -79,7 +77,7 @@ def audit():

def _print_audit_report(results, verbose):
fail = False
for key, values in list(results.items()):
for key, values in results.items():
present, absent = values
fail = fail or present or absent

Expand All @@ -88,30 +86,33 @@ def _print_audit_report(results, verbose):
else:
print("WARNING - audit script detected something is wrong.")

print("\nSummary")
print("=======\n")
print()
print("Summary")
print("=======")
print()

for key, values in list(results.items()):
for key, values in results.items():
present, absent = values
if not present and not absent:
print(( "- [x]", key))
print(f"- [x] {key}")
else:
print(("- [!]", key))
print((" ", len(present), "extra entries in PDC unaccounted for"))
print((" ", len(absent), "entries absent from PDC"))
print(f"- [!] {key}")
print(f" {len(present)} extra entries in PDC unaccounted for")
print(f" {len(absent)} entries absent from PDC")

print("\nDetails")
print()
print("Details")
print("=======")

limit = 100
for key, values in list(results.items()):
for key, values in results.items():
present, absent = values
if not present and not absent:
continue

print()
print(key)
print(("-" * len(key)))
print("-" * len(key))
print()

if not present:
Expand All @@ -121,16 +122,16 @@ def _print_audit_report(results, verbose):
print()
if verbose or len(present) < limit:
for value in present:
print(("-", value))
print(f"- {value}")
if isinstance(present, dict):
print((" ", present[value]))
print(f" {present[value]}")
else:
present = list(present)
for value in present[:limit]:
print(("-", value))
print(f"- {value}")
if isinstance(present, dict):
print((" ", present[value]))
print(("- (plus %i more... truncated.)" % (len(present) - limit)))
print(f" {present[value]}")
print(f"- (plus {len(present) - limit} more... truncated.)")
print()

if not absent:
Expand All @@ -140,16 +141,16 @@ def _print_audit_report(results, verbose):
print()
if verbose or len(absent) < limit:
for value in absent:
print("-", value)
print(f"- {value}")
if isinstance(absent, dict):
print(" ", absent[value])
print(f" {absent[value]}")
else:
absent = list(absent)
for value in absent[:limit]:
print("-", value)
print(f"- {value}")
if isinstance(absent, dict):
print(" ", absent[value])
print("- (plus %i more... truncated.)" % (len(absent) - limit))
print(f" {absent[value]}")
print(f"- (plus {len(absent) - limit} more... truncated.)")

if not fail:
return 0
Expand Down
15 changes: 8 additions & 7 deletions pdcupdater/handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import abc
from abc import ABCMeta, abstractmethod

import fedmsg.utils

Expand All @@ -11,7 +11,7 @@ def load_handlers(config):
yield handler


class BaseHandler(object, metaclass=abc.ABCMeta):
class BaseHandler(object, metaclass=ABCMeta):
""" An abstract base class for handlers to enforce API. """

def __init__(self, config):
Expand All @@ -31,21 +31,22 @@ def construct_topics(self, config):
for topic in self.topic_suffixes
]

@abc.abstractproperty
@property
@abstractmethod
def topic_suffixes(self):
pass

@abc.abstractmethod
@abstractmethod
def can_handle(self, pdc, msg):
""" Return True or False if this handler can handle this message. """
pass

@abc.abstractmethod
@abstractmethod
def handle(self, pdc, msg):
""" Handle a fedmsg and update PDC if necessary. """
pass

@abc.abstractmethod
@abstractmethod
def audit(self, pdc):
""" This is intended to be called from a cronjob once every few days
and is meant to (in a read-only fashion) check that what PDC thinks is
Expand All @@ -60,7 +61,7 @@ def audit(self, pdc):
"""
pass

@abc.abstractmethod
@abstractmethod
def initialize(self, pdc):
""" This needs to be called only once when pdc-updater is first
installed. It should query the original data source and initialize PDC
Expand Down
2 changes: 1 addition & 1 deletion pdcupdater/handlers/atomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def audit(self, pdc):

# Associate the two by release and normalize
present, absent = {}, {}
for release in set(list(git_groups.keys()) + list(pdc_groups.keys())):
for release in set(git_groups) | set(pdc_groups):
# Convert each group to a set
left = set(git_groups.get(release, []))
right = set(pdc_groups.get(release, []))
Expand Down
6 changes: 3 additions & 3 deletions pdcupdater/handlers/depchain/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def _yield_managed_pdc_relationships_from_release(self, pdc, release_id):

# Construct and yield a three-tuple result.
keys = ('name', 'release')
parent = dict(list(zip(keys, [entry['from_component'][key] for key in keys])))
child = dict(list(zip(keys, [entry['to_component'][key] for key in keys])))
parent = {key: entry['from_component'][key] for key in keys}
child = {key: entry['to_component'][key] for key in keys}
yield parent, relationship_type, child

def handle(self, pdc, msg):
Expand Down Expand Up @@ -154,7 +154,7 @@ def handle(self, pdc, msg):
by_parent[parent_name].add((relationship, child_name,))

# Finally, iterate over all those, now grouped by parent_name
for parent_name, koji_relationships in list(by_parent.items()):
for parent_name, koji_relationships in by_parent.items():
# TODO -- pass in global_component_name to this function?
parent = pdcupdater.utils.ensure_release_component_exists(
pdc, release_id, parent_name, type=self.parent_type)
Expand Down
8 changes: 4 additions & 4 deletions pdcupdater/handlers/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def get_module_rpms(self, pdc, module):
# For SRPM packages, include the hash and branch from which is
# has been built.
if (rpm['arch'] == 'src'
and rpm['name'] in list(mmd.get_rpm_components().keys())
and 'rpms' in list(mmd.get_xmd()['mbs'].keys())
and rpm['name'] in mmd.get_rpm_components()
and 'rpms' in mmd.get_xmd()['mbs']
and rpm['name'] in mmd.get_xmd()['mbs']['rpms']):
mmd_rpm = mmd.get_rpm_components()[rpm['name']]
xmd_rpm = mmd.get_xmd()['mbs']['rpms'][rpm['name']]
Expand Down Expand Up @@ -172,11 +172,11 @@ def create_module(self, pdc, body):
runtime_deps = []
build_deps = []
for deps in mmd.get_dependencies():
for dependency, streams in list(deps.get_requires().items()):
for dependency, streams in deps.get_requires().items():
for stream in streams.get():
runtime_deps.append(
{'dependency': dependency, 'stream': stream})
for dependency, streams in list(deps.get_buildrequires().items()):
for dependency, streams in deps.get_buildrequires().items():
for stream in streams.get():
build_deps.append(
{'dependency': dependency, 'stream': stream})
Expand Down
2 changes: 1 addition & 1 deletion pdcupdater/handlers/rpms.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _gather_koji_rpms(self):
}

# Flatten into a list and augment the koji dict with tag info.
for tag, rpms in list(koji_rpms.items()):
for tag, rpms in koji_rpms.items():
yield [
dict(
name=rpm['name'],
Expand Down
2 changes: 1 addition & 1 deletion pdcupdater/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def koji_yield_rpm_requires(url, nvra):
rpm.RPMSENSE_GREATER: '>',
rpm.RPMSENSE_EQUAL: '=',
}
relevant_flags = reduce(operator.ior, list(header_lookup.keys()))
relevant_flags = reduce(operator.ior, header_lookup)

# Query koji and step over all the deps listed in the raw rpm headers.
deps = session.getRPMDeps(nvra, koji.DEP_REQUIRE)
Expand Down

0 comments on commit 88ea5e6

Please sign in to comment.