From 5847e09ae78d3f3d8ca8fccb1c11a7df1f0d89a4 Mon Sep 17 00:00:00 2001 From: Sandro Bonazzola Date: Thu, 16 Jan 2025 11:15:03 +0100 Subject: [PATCH] Fix pylint W1201 and W1202 Fixing pylint warnings: W1201: Use lazy % formatting in logging functions (logging-not-lazy) W1202: Use lazy % or % formatting in logging functions (logging-format-interpolation) Signed-off-by: Sandro Bonazzola --- .pre-commit-config.yaml | 1 + .pylintrc | 3 ++ did/base.py | 6 ++-- did/cli.py | 6 ++-- did/plugins/bodhi.py | 7 ++-- did/plugins/bugzilla.py | 18 +++++----- did/plugins/confluence.py | 15 ++++---- did/plugins/gerrit.py | 69 ++++++++++++++++++------------------- did/plugins/git.py | 7 ++-- did/plugins/github.py | 20 +++++------ did/plugins/gitlab.py | 25 +++++--------- did/plugins/google.py | 8 ++--- did/plugins/jira.py | 30 ++++++++++------ did/plugins/koji.py | 2 +- did/plugins/nitrate.py | 8 ++--- did/plugins/pagure.py | 12 +++---- did/plugins/public_inbox.py | 38 +++++++++----------- did/plugins/redmine.py | 4 +-- did/plugins/rt.py | 10 +++--- did/plugins/sentry.py | 8 ++--- did/plugins/trac.py | 16 ++++----- did/plugins/zammad.py | 9 +++-- did/stats.py | 5 ++- did/utils.py | 9 ++--- 24 files changed, 164 insertions(+), 172 deletions(-) create mode 100644 .pylintrc diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f41f7856..25208e12 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ +--- # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks repos: diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 00000000..b4286fa4 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,3 @@ +[MESSAGES] +disable=all +enable=W1201,W1202 diff --git a/did/base.py b/did/base.py index 82652d7c..c51073c6 100644 --- a/did/base.py +++ b/did/base.py @@ -101,7 +101,7 @@ def __init__(self, config=None, path=None): path = Config.path() # Parse the config from file try: - log.info("Inspecting config file '{0}'.".format(path)) + log.info("Inspecting config file '%s'.", path) self.parser.read_file(codecs.open(path, "r", "utf8")) except IOError as error: log.debug(error) @@ -497,12 +497,12 @@ def alias(self, aliases, stats): # Update login/email if alias detected if email is not None: self.email = email - log.info("Using email alias '{0}' for '{1}'".format(email, stats)) + log.info("Using email alias '%s' for '%s'", email, stats) if login is None: login = email.split("@")[0] if login is not None: self.login = login - log.info("Using login alias '{0}' for '{1}'".format(login, stats)) + log.info("Using login alias '%s' for '%s'", login, stats) def get_token( diff --git a/did/cli.py b/did/cli.py index 0f801906..cb740a13 100644 --- a/did/cli.py +++ b/did/cli.py @@ -69,8 +69,8 @@ def __init__(self, arguments=None): log.debug("Loading Sample Stats group to build Options") self.sample_stats = UserStats() self.sample_stats.add_option(self.parser) - log.info("Default command line: did {0}".format(" ".join( - [f'--{stat.option}' for stat in self.sample_stats.stats]))) + log.info("Default command line: did %s", + (" ".join([f'--{stat.option}' for stat in self.sample_stats.stats]))) # Formating options group = self.parser.add_argument_group("Format") @@ -161,7 +161,7 @@ def parse(self): # Finito log.debug("Gathered options:") - log.debug('options = {0}'.format(opt)) + log.debug('options = %s', opt) return opt, header def check(self): diff --git a/did/plugins/bodhi.py b/did/plugins/bodhi.py index d47ae118..31c0fd3b 100644 --- a/did/plugins/bodhi.py +++ b/did/plugins/bodhi.py @@ -34,12 +34,11 @@ def search(self, query): current_page = 1 original_query = query while current_page: - log.debug("Bodhi query: {0}".format(query)) + log.debug("Bodhi query: %s", query) client = BodhiClient(self.url) data = client.send_request(query, verb='GET') objects = data['updates'] - log.debug("Result: {0} fetched".format( - listed(len(objects), "item"))) + log.debug("Result: %s fetched", listed(len(objects), "item")) log.data(pretty(data)) result.extend(objects) if current_page < data['pages']: @@ -82,7 +81,7 @@ class UpdatesCreated(Stats): """ Updates created """ def fetch(self): - log.info('Searching for updates created by {0}'.format(self.user)) + log.info('Searching for updates created by %s', self.user) self.stats = [ Update(update, self.parent.options.format) for update in self.parent.bodhi.search( diff --git a/did/plugins/bugzilla.py b/did/plugins/bugzilla.py index 06755867..7f0e7b54 100644 --- a/did/plugins/bugzilla.py +++ b/did/plugins/bugzilla.py @@ -289,7 +289,7 @@ class VerifiedBugs(Stats): """ def fetch(self): - log.info("Searching for bugs verified by {0}".format(self.user)) + log.info("Searching for bugs verified by %s", self.user) # Common query options query = { # Status changed to VERIFIED @@ -337,7 +337,7 @@ class ReturnedBugs(Stats): """ def fetch(self): - log.info("Searching for bugs returned by {0}".format(self.user)) + log.info("Searching for bugs returned by %s", self.user) query = { # User is not the assignee "f1": "assigned_to", @@ -374,7 +374,7 @@ class FiledBugs(Stats): """ def fetch(self): - log.info("Searching for bugs filed by {0}".format(self.user)) + log.info("Searching for bugs filed by %s", self.user) query = { # User is the reporter "f1": "reporter", @@ -402,7 +402,7 @@ class FixedBugs(Stats): """ def fetch(self): - log.info("Searching for bugs fixed by {0}".format(self.user)) + log.info("Searching for bugs fixed by %s", self.user) query = { # User is the assignee "f1": "assigned_to", @@ -438,7 +438,7 @@ class ClosedBugs(Stats): """ def fetch(self): - log.info("Searching for bugs closed by {0}".format(self.user)) + log.info("Searching for bugs closed by %s", self.user) query = { # Status changed by the user "f1": "bug_status", @@ -476,7 +476,7 @@ class PostedBugs(Stats): """ def fetch(self): - log.info("Searching for bugs posted by {0}".format(self.user)) + log.info("Searching for bugs posted by %s", self.user) query = { # User is the assignee "f1": "assigned_to", @@ -511,7 +511,7 @@ class PatchedBugs(Stats): """ def fetch(self): - log.info("Searching for bugs patched by {0}".format(self.user)) + log.info("Searching for bugs patched by %s", self.user) query = { # Keywords field changed by the user "f1": "keywords", @@ -576,7 +576,7 @@ class CommentedBugs(Stats): """ def fetch(self): - log.info("Searching for bugs commented by {0}".format(self.user)) + log.info("Searching for bugs commented by %s", self.user) query = { # Commented by the user "f1": "longdesc", @@ -605,7 +605,7 @@ class SubscribedBugs(Stats): """ def fetch(self): - log.info("Searching for bugs subscribed by {0}".format(self.user)) + log.info("Searching for bugs subscribed by %s", self.user) query = { # Subscribed by the user "f1": "cc", diff --git a/did/plugins/confluence.py b/did/plugins/confluence.py index 1871577c..136d8c0d 100644 --- a/did/plugins/confluence.py +++ b/did/plugins/confluence.py @@ -67,7 +67,7 @@ class Confluence(object): @staticmethod def search(query, stats, expand=None): """ Perform page/comment search for given stats instance """ - log.debug("Search query: {0}".format(query)) + log.debug("Search query: %s", query) content = [] # Fetch data from the server in batches of MAX_RESULTS issues @@ -81,8 +81,11 @@ def search(query, stats, expand=None): "start": batch * MAX_RESULTS}))) data = response.json() log.debug( - "Batch {0} result: {1} fetched".format( - batch, listed(data["results"], "object"))) + "Batch %s result: %s fetched", + batch, + listed( + data["results"], + "object")) log.data(pretty(data)) content.extend(data["results"]) # If all issues fetched, we're done @@ -129,7 +132,7 @@ class PageCreated(Stats): """ Created pages """ def fetch(self): - log.info("Searching for pages created by {0}".format(self.user)) + log.info("Searching for pages created by %s", self.user) query = ( "type=page AND creator = '{0}' " "AND created >= {1} AND created < {2}".format( @@ -140,7 +143,7 @@ def fetch(self): class CommentAdded(Stats): def fetch(self): - log.info("Searching for comments added by {0}".format(self.user)) + log.info("Searching for comments added by %s", self.user) query = ( "type=comment AND creator = '{0}' " "AND created >= {1} AND created < {2}".format( @@ -241,7 +244,7 @@ def session(self): """ Initialize the session """ if self._session is None: self._session = requests.Session() - log.debug("Connecting to {0}".format(self.auth_url)) + log.debug("Connecting to %s", self.auth_url) # Disable SSL warning when ssl_verify is False if not self.ssl_verify: requests.packages.urllib3.disable_warnings( diff --git a/did/plugins/gerrit.py b/did/plugins/gerrit.py index e19c9f2c..1569b631 100644 --- a/did/plugins/gerrit.py +++ b/did/plugins/gerrit.py @@ -74,7 +74,7 @@ def join_URL_frags(base, query): return urllib.parse.urlunsplit(split) def get_query_result(self, url): - log.debug('url = {0}'.format(url)) + log.debug('url = %s', url) res = self.opener.open(url) if res.getcode() != 200: raise IOError( @@ -96,12 +96,12 @@ def get_changelog(self, chg): messages_url = self.join_URL_frags( self.baseurl, '/changes/{0}/detail'.format(chg.change_id)) changelog = self.get_query_result(messages_url) - log.debug("changelog = {0}".format(changelog)) + log.debug("changelog = %s", changelog) return changelog def search(self, query): full_url = self.join_URL_frags(self.baseurl, '/changes/?q=' + query) - log.debug('full_url = {0}'.format(full_url)) + log.debug('full_url = %s', full_url) tickets = [] # Get tickets @@ -154,9 +154,11 @@ def fetch(self, query_string="", common_query_options=None, results to eliminate items created after since option. """ work_list = [] - log.info("Searching for changes by {0}".format(self.user)) - log.debug('query_string = {0}, common_query_options = {1}'.format( - query_string, common_query_options)) + log.info("Searching for changes by %s", self.user) + log.debug( + 'query_string = %s, common_query_options = %s', + query_string, + common_query_options) self.since_date = self.get_gerrit_date(self.options.since) @@ -184,9 +186,9 @@ def fetch(self, query_string="", common_query_options=None, len(common_query_options) > 0: query_string += common_query_options - log.debug('query_string = {0}'.format(query_string)) - log.debug('self.prefix = {0}'.format(self.prefix)) - log.debug('[fetch] self.base_url = {0}'.format(self.base_url)) + log.debug('query_string = %s', query_string) + log.debug('self.prefix = %s', self.prefix) + log.debug('[fetch] self.base_url = %s', self.base_url) work_list = self.repo.search(query_string) if limit_since: @@ -194,13 +196,13 @@ def fetch(self, query_string="", common_query_options=None, log.debug('Limiting by since option') self.stats = [] for chg in work_list: - log.debug('chg = {0}'.format(chg)) + log.debug('chg = %s', chg) chg_created = self.get_gerrit_date(chg['created'][:10]) - log.debug('chg_created = {0}'.format(chg_created)) + log.debug('chg_created = %s', chg_created) if chg_created >= self.since_date: tmplist.append(chg) work_list = tmplist[:] - log.debug("work_list = {0}".format(work_list)) + log.debug("work_list = %s", work_list) # Return the list of tick_data objects return [Change(ticket, prefix=self.prefix) for ticket in work_list] @@ -213,9 +215,9 @@ class AbandonedChanges(GerritUnit): """ def fetch(self): - log.info("Searching for changes abandoned by {0}".format(self.user)) + log.info("Searching for changes abandoned by %s", self.user) self.stats = GerritUnit.fetch(self, 'status:abandoned') - log.debug("self.stats = {0}".format(self.stats)) + log.debug("self.stats = %s", self.stats) class MergedChanges(GerritUnit): @@ -225,9 +227,9 @@ class MergedChanges(GerritUnit): """ def fetch(self): - log.info("Searching for changes merged by {0}".format(self.user)) + log.info("Searching for changes merged by %s", self.user) self.stats = GerritUnit.fetch(self, 'status:merged') - log.debug("self.stats = {0}".format(self.stats)) + log.debug("self.stats = %s", self.stats) class SubmitedChanges(GerritUnit): @@ -244,14 +246,14 @@ class SubmitedChanges(GerritUnit): """ def fetch(self): - log.info("Searching for changes opened by {0}".format(self.user)) + log.info("Searching for changes opened by %s", self.user) if 'wip' in self.server_features: query_string = 'status:open -is:wip' else: query_string = 'status:open' self.stats = GerritUnit.fetch(self, query_string, limit_since=True) - log.debug("self.stats = {0}".format(self.stats)) + log.debug("self.stats = %s", self.stats) class WIPChanges(GerritUnit): @@ -260,13 +262,13 @@ class WIPChanges(GerritUnit): """ def fetch(self): - log.info("Searching for WIP changes opened by {0}".format(self.user)) + log.info("Searching for WIP changes opened by %s", self.user) if 'wip' not in self.server_features: log.debug("WIP reviews are not supported by this server") return [] self.stats = GerritUnit.fetch(self, 'status:open is:wip', limit_since=True) - log.debug("self.stats = {0}".format(self.stats)) + log.debug("self.stats = %s", self.stats) class AddedPatches(GerritUnit): @@ -277,8 +279,7 @@ class AddedPatches(GerritUnit): """ def fetch(self): - log.info("Searching for patches added to changes by {0}".format( - self.user)) + log.info("Searching for patches added to changes by %s", self.user) reviewer = self.user.login self.stats = [] tickets = GerritUnit.fetch( @@ -286,18 +287,16 @@ def fetch(self): reviewer), '') for tck in tickets: - log.debug("ticket = {0}".format(tck)) + log.debug("ticket = %s", tck) try: changes = self.repo.get_changelog(tck) except IOError: - log.debug('Failing to retrieve details for {0}'.format( - tck.change_id)) + log.debug('Failing to retrieve details for %s', tck.change_id) continue owner = changes['owner']['email'] - log.debug("changes.messages = {0}".format( - pretty(changes['messages']))) + log.debug("changes.messages = %s", pretty(changes['messages'])) cmnts_by_user = [] for chg in changes['messages']: # TODO This is a very bad algorithm for recognising @@ -319,7 +318,7 @@ def fetch(self): self.stats.append( Change(tck.ticket, changelog=changes, prefix=self.prefix)) - log.debug("self.stats = {0}".format(self.stats)) + log.debug("self.stats = %s", self.stats) class ReviewedChanges(GerritUnit): @@ -330,7 +329,7 @@ class ReviewedChanges(GerritUnit): """ def fetch(self): - log.info("Searching for changes reviewed by {0}".format(self.user)) + log.info("Searching for changes reviewed by %s", self.user) # Collect ALL changes opened (and perhaps now closed) after # given date and collect all reviews from them ... then limit by # actual reviewer (not reviewer: because that doesn’t @@ -343,15 +342,13 @@ def fetch(self): self.user.login), '', limit_since=True) for tck in tickets: - log.debug("ticket = {0}".format(tck)) + log.debug("ticket = %s", tck) try: changes = self.repo.get_changelog(tck) except IOError: - log.debug('Failing to retrieve details for {0}'.format( - tck.change_id)) + log.debug('Failing to retrieve details for %s', tck.change_id) continue - log.debug("changes.messages = {0}".format( - pretty(changes['messages']))) + log.debug("changes.messages = %s", pretty(changes['messages'])) cmnts_by_user = [] for chg in changes['messages']: if 'author' not in chg: @@ -366,7 +363,7 @@ def fetch(self): self.stats.append( Change(tck.ticket, changelog=changes, prefix=self.prefix)) - log.debug("self.stats = {0}".format(self.stats)) + log.debug("self.stats = %s", self.stats) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -404,7 +401,7 @@ def __init__(self, option, name=None, parent=None, user=None): raise IOError( 'No gerrit URL set in the [{0}] section'.format(option)) self.repo_url = self.config['url'] - log.debug('repo_url = {0}'.format(self.repo_url)) + log.debug('repo_url = %s', self.repo_url) if "prefix" not in self.config: raise ReportError( diff --git a/did/plugins/git.py b/did/plugins/git.py index b54abcc5..3ef8e37f 100644 --- a/did/plugins/git.py +++ b/did/plugins/git.py @@ -51,7 +51,7 @@ def commits(self, user, options): command.append("--format=format:%n%h - %s") else: command.append("--format=format:%h - %s") - log.info("Checking commits in {0}".format(self.path)) + log.info("Checking commits in %s", self.path) log.details(pretty(command)) # Get the commit messages @@ -93,7 +93,7 @@ def commits(self, user, options): return commits else: log.debug(errors.strip()) - log.warning("Unable to check commits in '{0}'".format(self.path)) + log.warning("Unable to check commits in '%s'", self.path) return [] @@ -152,8 +152,7 @@ def __init__(self, option, name=None, parent=None, user=None): continue # Silently ignore non-git directories if not os.path.exists(os.path.join(repo_path, ".git")): - log.debug("Skipping non-git directory '{0}'.".format( - repo_path)) + log.debug("Skipping non-git directory '%s'.", repo_path) continue self.stats.append(GitCommits( option="{0}-{1}".format(repo, repo_dir), diff --git a/did/plugins/github.py b/did/plugins/github.py index e269df1c..a5f33015 100644 --- a/did/plugins/github.py +++ b/did/plugins/github.py @@ -126,7 +126,7 @@ def search(self, query): else: break - log.debug("Result: {0} fetched".format(listed(len(result), "item"))) + log.debug("Result: %s fetched", listed(len(result), "item")) log.data(pretty(result)) return result @@ -181,7 +181,7 @@ class IssuesCreated(Stats): """ Issues created """ def fetch(self): - log.info("Searching for issues created by {0}".format(self.user)) + log.info("Searching for issues created by %s", self.user) query = "search/issues?q=author:{0}+created:{1}..{2}".format( self.user.login, self.options.since, self.options.until) query += "+type:issue" @@ -193,7 +193,7 @@ class IssuesClosed(Stats): """ Issues closed """ def fetch(self): - log.info("Searching for issues closed by {0}".format(self.user)) + log.info("Searching for issues closed by %s", self.user) query = "search/issues?q=assignee:{0}+closed:{1}..{2}".format( self.user.login, self.options.since, self.options.until) query += "+type:issue" @@ -205,7 +205,7 @@ class IssueCommented(Stats): """ Issues commented """ def fetch(self): - log.info("Searching for issues commented on by {0}".format(self.user)) + log.info("Searching for issues commented on by %s", self.user) query = "search/issues?q=commenter:{0}+updated:{1}..{2}".format( self.user.login, self.options.since, self.options.until) query += "+type:issue" @@ -217,8 +217,7 @@ class PullRequestsCreated(Stats): """ Pull requests created """ def fetch(self): - log.info("Searching for pull requests created by {0}".format( - self.user)) + log.info("Searching for pull requests created by %s", self.user) query = "search/issues?q=author:{0}+created:{1}..{2}".format( self.user.login, self.options.since, self.options.until) query += "+type:pr" @@ -230,8 +229,7 @@ class PullRequestsCommented(Stats): """ Pull requests commented """ def fetch(self): - log.info("Searching for pull requests commented on by {0}".format( - self.user)) + log.info("Searching for pull requests commented on by %s", self.user) query = "search/issues?q=commenter:{0}+updated:{1}..{2}".format( self.user.login, self.options.since, self.options.until) query += "+type:pr" @@ -243,8 +241,7 @@ class PullRequestsClosed(Stats): """ Pull requests closed """ def fetch(self): - log.info("Searching for pull requests closed by {0}".format( - self.user)) + log.info("Searching for pull requests closed by %s", self.user) query = "search/issues?q=assignee:{0}+closed:{1}..{2}".format( self.user.login, self.options.since, self.options.until) query += "+type:pr" @@ -256,8 +253,7 @@ class PullRequestsReviewed(Stats): """ Pull requests reviewed """ def fetch(self): - log.info("Searching for pull requests reviewed by {0}".format( - self.user)) + log.info("Searching for pull requests reviewed by %s", self.user) query = "search/issues?q=reviewed-by:{0}+-author:{0}+closed:{1}..{2}".format( self.user.login, self.options.since, self.options.until) query += "+type:pr" diff --git a/did/plugins/gitlab.py b/did/plugins/gitlab.py index a505517b..187dff13 100644 --- a/did/plugins/gitlab.py +++ b/did/plugins/gitlab.py @@ -91,7 +91,7 @@ def _get_gitlab_api(self, endpoint): return self._get_gitlab_api_raw(url) def _get_gitlab_api_json(self, endpoint): - log.debug("Query: {0}".format(endpoint)) + log.debug("Query: %s", endpoint) result = self._get_gitlab_api(endpoint).json() log.data(pretty(result)) return result @@ -180,7 +180,7 @@ def search(self, user, since, until, target_type, action_name): event['action_name'] == action_name and since.date <= created_at and until.date >= created_at): result.append(event) - log.debug("Result: {0} fetched".format(listed(len(result), "item"))) + log.debug("Result: %s fetched", listed(len(result), "item")) return result @@ -259,8 +259,7 @@ class IssuesCreated(Stats): """ Issue created """ def fetch(self): - log.info("Searching for Issues created by {0}".format( - self.user)) + log.info("Searching for Issues created by %s", self.user) results = self.parent.gitlab.search( self.user.login, self.options.since, self.options.until, 'Issue', 'opened') @@ -273,8 +272,7 @@ class IssuesCommented(Stats): """ Issue commented """ def fetch(self): - log.info("Searching for Issues commented by {0}".format( - self.user)) + log.info("Searching for Issues commented by %s", self.user) results = self.parent.gitlab.search( self.user.login, self.options.since, self.options.until, 'Note', 'commented on') @@ -288,8 +286,7 @@ class IssuesClosed(Stats): """ Issue closed """ def fetch(self): - log.info("Searching for Issues closed by {0}".format( - self.user)) + log.info("Searching for Issues closed by %s", self.user) results = self.parent.gitlab.search( self.user.login, self.options.since, self.options.until, 'Issue', 'closed') @@ -302,8 +299,7 @@ class MergeRequestsCreated(Stats): """ Merge requests created """ def fetch(self): - log.info("Searching for Merge requests created by {0}".format( - self.user)) + log.info("Searching for Merge requests created by %s", self.user) results = self.parent.gitlab.search( self.user.login, self.options.since, self.options.until, 'MergeRequest', 'opened') @@ -316,8 +312,7 @@ class MergeRequestsCommented(Stats): """ MergeRequests commented """ def fetch(self): - log.info("Searching for MergeRequests commented by {0}".format( - self.user)) + log.info("Searching for MergeRequests commented by %s", self.user) results = self.parent.gitlab.search( self.user.login, self.options.since, self.options.until, 'Note', 'commented on') @@ -331,8 +326,7 @@ class MergeRequestsClosed(Stats): """ Merge requests closed """ def fetch(self): - log.info("Searching for Merge requests closed by {0}".format( - self.user)) + log.info("Searching for Merge requests closed by %s", self.user) results = self.parent.gitlab.search( self.user.login, self.options.since, self.options.until, 'MergeRequest', 'accepted') @@ -345,8 +339,7 @@ class MergeRequestsApproved(Stats): """ Merge requests approved """ def fetch(self): - log.info("Searching for Merge requests approved by {0}".format( - self.user)) + log.info("Searching for Merge requests approved by %s", self.user) results = self.parent.gitlab.search( self.user.login, self.options.since, self.options.until, 'MergeRequest', 'approved') diff --git a/did/plugins/google.py b/did/plugins/google.py index 369d60be..cb89add0 100644 --- a/did/plugins/google.py +++ b/did/plugins/google.py @@ -243,7 +243,7 @@ def tasks(self): self._tasks = self.parent.tasks.tasks( tasklist="@default", showCompleted="true", showHidden="true", completedMin=self.since, completedMax=self.until) - log.info("NB TASKS {0}".format(len(self._tasks))) + log.info("NB TASKS %s", len(self._tasks)) return self._tasks @@ -251,7 +251,7 @@ class GoogleEventsOrganized(GoogleStatsBase): """ Events organized """ def fetch(self): - log.info("Searching for events organized by {0}".format(self.user)) + log.info("Searching for events organized by %s", self.user) self.stats = [ event for event in self.events if event.organized_by(self.user.email) @@ -262,7 +262,7 @@ class GoogleEventsAttended(GoogleStatsBase): """ Events attended """ def fetch(self): - log.info("Searching for events attended by {0}".format(self.user)) + log.info("Searching for events attended by %s", self.user) self.stats = [ event for event in self.events if event.attended_by(self.user.email) @@ -273,7 +273,7 @@ class GoogleTasksCompleted(GoogleStatsBase): """ Tasks completed """ def fetch(self): - log.info("Searching for completed tasks by {0}".format(self.user)) + log.info("Searching for completed tasks by %s", self.user) self.stats = self.tasks diff --git a/did/plugins/jira.py b/did/plugins/jira.py index a6a9a6c7..8878c4d5 100644 --- a/did/plugins/jira.py +++ b/did/plugins/jira.py @@ -147,7 +147,7 @@ def __eq__(self, other): @staticmethod def search(query, stats): """ Perform issue search for given stats instance """ - log.debug("Search query: {0}".format(query)) + log.debug("Search query: %s", query) issues = [] # Fetch data from the server in batches of MAX_RESULTS issues for batch in range(MAX_BATCHES): @@ -168,8 +168,12 @@ def search(query, stats): f"Failed to fetch jira issues for query '{query}'. " f"The reason was '{response.reason}' " f"and the error was '{error}'.") - log.debug("Batch {0} result: {1} fetched".format( - batch, listed(data["issues"], "issue"))) + log.debug( + "Batch %s result: %s fetched", + batch, + listed( + data["issues"], + "issue")) log.data(pretty(data)) issues.extend(data["issues"]) # If all issues fetched, we're done @@ -203,8 +207,10 @@ class JiraCreated(Stats): """ Created issues """ def fetch(self): - log.info("Searching for issues created in {0} by {1}".format( - self.parent.project, self.user)) + log.info( + "Searching for issues created in %s by %s", + self.parent.project, + self.user) query = ( "creator = '{0}' AND " "created >= {1} AND created <= {2}".format( @@ -219,8 +225,10 @@ class JiraUpdated(Stats): """ Updated issues """ def fetch(self): - log.info("Searching for issues updated in {0} by {1}".format( - self.parent.project, self.user)) + log.info( + "Searching for issues updated in %s by %s", + self.parent.project, + self.user) if self.parent.use_scriptrunner: query = ( "issueFunction in commented" @@ -247,8 +255,10 @@ class JiraResolved(Stats): """ Resolved issues """ def fetch(self): - log.info("Searching for issues resolved in {0} by {1}".format( - self.parent.project, self.user)) + log.info( + "Searching for issues resolved in %s by %s", + self.parent.project, + self.user) query = ( "assignee = '{0}' AND " "resolved >= {1} AND resolved <= {2}".format( @@ -386,7 +396,7 @@ def session(self): """ Initialize the session """ if self._session is None: self._session = requests.Session() - log.debug("Connecting to {0}".format(self.auth_url)) + log.debug("Connecting to %s", self.auth_url) # Disable SSL warning when ssl_verify is False if not self.ssl_verify: requests.packages.urllib3.disable_warnings( diff --git a/did/plugins/koji.py b/did/plugins/koji.py index bdfdd97c..dd18d8c0 100644 --- a/did/plugins/koji.py +++ b/did/plugins/koji.py @@ -32,7 +32,7 @@ def __init__(self, option, name=None, parent=None, user=None, options=None, self.userinfo = userinfo def fetch(self): - log.info("Searching for builds by {0}".format(self.user)) + log.info("Searching for builds by %s", self.user) builds = self.server.listBuilds( userID=self.user['id'], completeAfter=str(self.options.since), diff --git a/did/plugins/nitrate.py b/did/plugins/nitrate.py index 68e05b83..e424c826 100644 --- a/did/plugins/nitrate.py +++ b/did/plugins/nitrate.py @@ -22,7 +22,7 @@ class TestPlans(Stats): def fetch(self): import nitrate - log.info("Searching for test plans created by {0}".format(self.user)) + log.info("Searching for test plans created by %s", self.user) self.stats.extend(nitrate.TestPlan.search( is_active=True, author__email=self.user.email, @@ -35,7 +35,7 @@ class TestRuns(Stats): def fetch(self): import nitrate - log.info("Searching for test runs finished by {0}".format(self.user)) + log.info("Searching for test runs finished by %s", self.user) self.stats.extend(nitrate.TestRun.search( default_tester__email=self.user.email, stop_date__gt=str(self.options.since), @@ -104,7 +104,7 @@ def cases(self): """ All test cases created by the user """ import nitrate if self._cases is None: - log.info("Searching for cases created by {0}".format(self.user)) + log.info("Searching for cases created by %s", self.user) self._cases = [ case for case in nitrate.TestCase.search( author__email=self.user.email, @@ -118,7 +118,7 @@ def copies(self): """ All test case copies created by the user """ import nitrate if self._copies is None: - log.info("Searching for cases copied by {0}".format(self.user)) + log.info("Searching for cases copied by %s", self.user) self._copies = [ case for case in nitrate.TestCase.search( author__email=self.user.email, diff --git a/did/plugins/pagure.py b/did/plugins/pagure.py index b440cec4..ed61f92b 100644 --- a/did/plugins/pagure.py +++ b/did/plugins/pagure.py @@ -45,7 +45,7 @@ def search(self, query, pagination, result_field): result = [] url = "/".join((self.url, query)) while url: - log.debug("Pagure query: {0}".format(url)) + log.debug("Pagure query: %s", url) try: response = requests.get(url, headers=self.headers) log.data("Response headers:\n{0}".format(response.headers)) @@ -54,8 +54,7 @@ def search(self, query, pagination, result_field): raise ReportError("Pagure search {0} failed.".format(self.url)) data = response.json() objects = data[result_field] - log.debug("Result: {0} fetched".format( - listed(len(objects), "item"))) + log.debug("Result: %s fetched", listed(len(objects), "item")) log.data(pretty(data)) # FIXME later: # Work around https://pagure.io/pagure/issue/4057 @@ -109,7 +108,7 @@ class IssuesCreated(Stats): """ Issues created """ def fetch(self): - log.info('Searching for issues created by {0}'.format(self.user)) + log.info('Searching for issues created by %s', self.user) issues = [Issue(issue, self.options) for issue in self.parent.pagure.search( query='user/{0}/issues?assignee=false&created={1}..{2}'.format( self.user.login, self.options.since, self.options.until), @@ -122,7 +121,7 @@ class IssuesClosed(Stats): """ Issues closed """ def fetch(self): - log.info('Searching for issues closed by {0}'.format(self.user)) + log.info('Searching for issues closed by %s', self.user) issues = [Issue(issue, self.options) for issue in self.parent.pagure.search( query='user/{0}/issues?status=all&author=false&since={1}'.format( self.user.login, self.options.since), @@ -140,8 +139,7 @@ class PullRequestsCreated(Stats): """ Pull requests created """ def fetch(self): - log.info('Searching for pull requests created by {0}'.format( - self.user)) + log.info('Searching for pull requests created by %s', self.user) issues = [Issue(issue, self.options) for issue in self.parent.pagure.search( query='user/{0}/requests/filed?status=all&created={1}..{2}'.format( self.user.login, self.options.since, self.options.until), diff --git a/did/plugins/public_inbox.py b/did/plugins/public_inbox.py index 958a72f3..c488a956 100644 --- a/did/plugins/public_inbox.py +++ b/did/plugins/public_inbox.py @@ -119,11 +119,11 @@ def __get_msgs_from_mbox(self, mbox: mailbox.mbox) -> list[Message]: for msg in _unique_messages(mbox): msg_id = msg.id() - log.debug("Found message %s." % msg_id) + log.debug("Found message %s.", msg_id) msgs.append(msg) if msg_id not in self.messages_cache: - log.debug("Message %s is new, adding to the cache." % msg_id) + log.debug("Message %s is new, adding to the cache.", msg_id) self.messages_cache[msg_id] = msg return msgs @@ -132,16 +132,16 @@ def __fetch_thread_root(self, msg: Message) -> Message: msg_id = msg.id() url = self.__get_url("/all/%s/t.mbox.gz" % msg_id) - log.debug("Fetching message %s thread (%s)" % (msg_id, url)) + log.debug("Fetching message %s thread (%s)", msg_id, url) resp = requests.get(url) mbox = self.__get_mbox_from_content(resp.content) for msg in self.__get_msgs_from_mbox(mbox): if msg.is_thread_root(): - log.debug("Found message %s thread root: %s." % (msg_id, msg.id())) + log.debug("Found message %s thread root: %s.", msg_id, msg.id()) return msg def __get_thread_root(self, msg: Message) -> Message: - log.debug("Looking for thread root of message %s" % msg.id()) + log.debug("Looking for thread root of message %s", msg.id()) if msg.is_thread_root(): log.debug("Message is thread root already. Returning.") return msg @@ -149,11 +149,11 @@ def __get_thread_root(self, msg: Message) -> Message: parent_id = msg.parent_id() if parent_id not in self.messages_cache: root = self.__fetch_thread_root(msg) - log.debug("Found root message %s for message %s" % (root.id(), msg.id())) + log.debug("Found root message %s for message %s", root.id(), msg.id()) return root while True: - log.debug("Parent is %s" % parent_id) + log.debug("Parent is %s", parent_id) assert parent_id in self.messages_cache parent = self.messages_cache[parent_id] if parent.is_thread_root(): @@ -163,17 +163,15 @@ def __get_thread_root(self, msg: Message) -> Message: parent_id = parent.parent_id() if parent_id not in self.messages_cache: root = self.__fetch_thread_root(msg) - log.debug( - "Found root message %s for message %s" % - (root.id(), msg.id())) + log.debug("Found root message %s for message %s", root.id(), msg.id()) return root def __fetch_all_threads(self, since: Date, until: Date) -> list[Message]: since_str = since.date.isoformat() until_str = until.date.isoformat() - log.info("Fetching all mails on server %s from %s between %s and %s" % - (self.url, self.user, since_str, until_str)) + log.info("Fetching all mails on server %s from %s between %s and %s", + self.url, self.user, since_str, until_str) resp = requests.post( self.__get_url("/all/"), headers={"Content-Length": "0"}, @@ -221,11 +219,9 @@ class ThreadsStarted(Stats): def fetch(self): log.info( - "Searching for new threads on {0} started by {1}".format( - self.parent.url, - self.user, - ) - ) + "Searching for new threads on %s started by %s", + self.parent.url, + self.user) self.stats = [ msg @@ -249,11 +245,9 @@ class ThreadsInvolved(Stats): def fetch(self): log.info( - "Searching for mail threads on {0} where {1} was involved".format( - self.parent.url, - self.user, - ) - ) + "Searching for mail threads on %s where %s was involved", + self.parent.url, + self.user) self.stats = [ msg diff --git a/did/plugins/redmine.py b/did/plugins/redmine.py index 11cff654..05424115 100644 --- a/did/plugins/redmine.py +++ b/did/plugins/redmine.py @@ -51,7 +51,7 @@ class RedmineActivity(Stats): """ Redmine Activity Stats """ def fetch(self): - log.info("Searching for activity by {0}".format(self.user)) + log.info("Searching for activity by %s", self.user) results = [] from_date = self.options.until.date @@ -59,7 +59,7 @@ def fetch(self): feed_url = '{0}/activity.atom?user_id={1}&from={2}'.format( self.parent.url, self.user.login, from_date.strftime('%Y-%m-%d')) - log.debug(f"Feed url: {feed_url}") + log.debug("Feed url: %s", feed_url) feed = feedparser.parse(feed_url) for entry in feed.entries: updated = dateutil.parser.parse(entry.updated).date() diff --git a/did/plugins/rt.py b/did/plugins/rt.py index 95616e4f..4962f900 100644 --- a/did/plugins/rt.py +++ b/did/plugins/rt.py @@ -43,7 +43,7 @@ def get(self, path): # Make the connection connection = http.client.HTTPSConnection(self.url.netloc, 443) - log.debug("GET {0}".format(path)) + log.debug("GET %s", path) connection.putrequest("GET", path) connection.putheader("Authorization", "Negotiate {0}".format(data)) connection.putheader("Referer", self.url_string) @@ -62,13 +62,13 @@ def get(self, path): def search(self, query): """ Perform request tracker search """ # Prepare the path - log.debug("Query: {0}".format(query)) + log.debug("Query: %s", query) path = self.url.path + '?Format=__id__+__Subject__' path += "&Order=ASC&OrderBy=id&Query=" + urllib.parse.quote(query) # Get the tickets lines = self.get(path) - log.info("Fetched tickets: {0}".format(len(lines))) + log.info("Fetched tickets: %s", len(lines)) return [self.parent.ticket(line, self.parent) for line in lines] @@ -98,7 +98,7 @@ class ReportedTickets(Stats): """ Tickets reported """ def fetch(self): - log.info("Searching for tickets reported by {0}".format(self.user)) + log.info("Searching for tickets reported by %s", self.user) query = "Requestor.EmailAddress = '{0}'".format(self.user.email) query += " AND Created > '{0}'".format(self.options.since) query += " AND Created < '{0}'".format(self.options.until) @@ -109,7 +109,7 @@ class ResolvedTickets(Stats): """ Tickets resolved """ def fetch(self): - log.info("Searching for tickets resolved by {0}".format(self.user)) + log.info("Searching for tickets resolved by %s", self.user) query = "Owner.EmailAddress = '{0}'".format(self.user.email) query += "AND Resolved > '{0}'".format(self.options.since) query += "AND Resolved < '{0}'".format(self.options.until) diff --git a/did/plugins/sentry.py b/did/plugins/sentry.py index 22d5b656..fa888910 100644 --- a/did/plugins/sentry.py +++ b/did/plugins/sentry.py @@ -97,7 +97,7 @@ def _fetch_activities(self): while url: # Fetch one page of activities try: - log.debug('Fetching activity data: {0}'.format(url)) + log.debug('Fetching activity data: %s', url) response = requests.get(url, headers=self.headers) if not response.ok: log.error(response.text) @@ -105,7 +105,7 @@ def _fetch_activities(self): data = response.json() log.data("Response headers:\n{0}".format( pretty(response.headers))) - log.debug("Fetched {0}.".format(listed(len(data), 'activity'))) + log.debug("Fetched %s.", listed(len(data), 'activity')) log.data(pretty(data)) for activity in [Activity(item) for item in data]: # We've reached the last page, older records not @@ -136,7 +136,7 @@ class ResolvedIssues(Stats): """ Issues resolved """ def fetch(self): - log.info("Searching for issues resolved by {0}".format(self.user)) + log.info("Searching for issues resolved by %s", self.user) self.stats = self.parent.sentry.issues( kind='set_resolved', email=self.user.email) @@ -145,7 +145,7 @@ class CommentedIssues(Stats): """ Issues commented """ def fetch(self): - log.info("Searching issues commented by {0}".format(self.user)) + log.info("Searching issues commented by %s", self.user) self.stats = self.parent.sentry.issues( kind='note', email=self.user.email) diff --git a/did/plugins/trac.py b/did/plugins/trac.py index eadb3922..81c8cc97 100644 --- a/did/plugins/trac.py +++ b/did/plugins/trac.py @@ -62,7 +62,7 @@ def search(query, parent, options): """ Perform Trac search """ # Extend the default max number of tickets to be fetched query = "{0}&max={1}".format(query, MAX_TICKETS) - log.debug("Search query: {0}".format(query)) + log.debug("Search query: %s", query) try: result = parent.proxy.ticket.query(query) except xmlrpc.client.Fault as error: @@ -70,10 +70,10 @@ def search(query, parent, options): raise ReportError(error) except xmlrpc.client.ProtocolError as error: log.debug(error) - log.error("Trac url: {0}".format(parent.url)) + log.error("Trac url: %s", parent.url) raise ReportError( "Unable to contact Trac server. Is the url above correct?") - log.debug("Search result: {0}".format(result)) + log.debug("Search result: %s", result) # Fetch tickets and their history using multicall multicall = xmlrpc.client.MultiCall(parent.proxy) for ticket_id in sorted(result): @@ -85,7 +85,7 @@ def search(query, parent, options): changelogs = result[1::2] # Print debugging info for ticket, changelog in zip(tickets, changelogs): - log.debug("Fetched ticket #{0}".format(ticket[0])) + log.debug("Fetched ticket #%s", ticket[0]) log.debug(pretty(ticket)) log.debug("Changelog:") log.debug(pretty(changelog)) @@ -145,7 +145,7 @@ class TracCreated(TracCommon): """ Created tickets """ def fetch(self): - log.info("Searching for tickets created by {0}".format(self.user)) + log.info("Searching for tickets created by %s", self.user) query = "reporter=~{0}&time={1}..{2}".format( self.user.login, self.options.since, self.options.until) self.stats = Trac.search(query, self.parent, self.options) @@ -155,7 +155,7 @@ class TracAccepted(TracCommon): """ Accepted tickets """ def fetch(self): - log.info("Searching for tickets accepted by {0}".format(self.user)) + log.info("Searching for tickets accepted by %s", self.user) query = "time=..{2}&modified={1}..&owner=~{0}".format( self.user.login, self.options.since, self.options.until) self.stats = [ @@ -167,7 +167,7 @@ class TracUpdated(TracCommon): """ Updated tickets """ def fetch(self): - log.info("Searching for tickets updated by {0}".format(self.user)) + log.info("Searching for tickets updated by %s", self.user) query = "time=..{1}&modified={0}..".format( self.options.since, self.options.until) self.stats = [ @@ -179,7 +179,7 @@ class TracClosed(TracCommon): """ Closed tickets """ def fetch(self): - log.info("Searching for tickets closed by {0}".format(self.user)) + log.info("Searching for tickets closed by %s", self.user) query = "owner=~{0}&time=..{2}&modified={1}..".format( self.user.login, self.options.since, self.options.until) self.stats = [ diff --git a/did/plugins/zammad.py b/did/plugins/zammad.py index f23054ad..433ed016 100644 --- a/did/plugins/zammad.py +++ b/did/plugins/zammad.py @@ -46,12 +46,11 @@ def __init__(self, url, token): def search(self, query): """ Perform Zammad query """ url = self.url + "/" + query - log.debug("Zammad query: {0}".format(url)) + log.debug("Zammad query: %s", url) try: request = urllib.request.Request(url, headers=self.headers) response = urllib.request.urlopen(request) - log.debug("Response headers:\n{0}".format( - str(response.info()).strip())) + log.debug("Response headers:\n%s", str(response.info()).strip()) except urllib.error.URLError as error: log.debug(error) raise ReportError( @@ -61,7 +60,7 @@ def search(self, query): result = result["Ticket"] except KeyError: result = dict() - log.debug("Result: {0} fetched".format(listed(len(result), "item"))) + log.debug("Result: %s fetched", listed(len(result), "item")) log.data(pretty(result)) return result @@ -92,7 +91,7 @@ class TicketsUpdated(Stats): """ Tickets updated """ def fetch(self): - log.info("Searching for tickets updated by {0}".format(self.user)) + log.info("Searching for tickets updated by %s", self.user) search = "article.from:\"{0}\" and article.created_at:[{1} TO {2}]".format( self.user.name, self.options.since, self.options.until) query = "tickets/search?query={0}".format(urllib.parse.quote(search)) diff --git a/did/stats.py b/did/stats.py index 2aae87ab..d7bffb8d 100644 --- a/did/stats.py +++ b/did/stats.py @@ -36,8 +36,7 @@ def __init__( self.user = self.parent.user else: self.user = user - log.debug( - 'Loading {0} Stats instance for {1}'.format(option, self.user)) + log.debug('Loading %s Stats instance for %s', option, self.user) @property def name(self): @@ -129,7 +128,7 @@ def __init__(cls, name, bases, attrs): if plugin_name in registry: orig = registry[plugin_name] - log.warning("%s overriding %s" % (cls.__module__, orig.__module__)) + log.warning("%s overriding %s", cls.__module__, orig.__module__) registry[plugin_name] = cls diff --git a/did/utils.py b/did/utils.py index a3eb6b14..82731b25 100644 --- a/did/utils.py +++ b/did/utils.py @@ -63,7 +63,7 @@ def _import(path, continue_on_error): """ Eats or raises import exceptions based on ``continue_on_error``. """ - log.debug("Importing %s" % path) + log.debug("Importing %s", path) try: # importlib is available in stdlib from 2.7+ return importlib.import_module(path) @@ -504,9 +504,10 @@ def set(self, mode=None): raise RuntimeError("Invalid color mode '{0}'".format(mode)) self._mode = mode log.debug( - "Coloring {0} ({1})".format( - "enabled" if self.enabled() else "disabled", - self.MODES[self._mode])) + "Coloring %s (%s)", + "enabled" if self.enabled() else "disabled", + self.MODES[self._mode] + ) def get(self): """ Get the current color mode """