From: "Martin Liška" <mliska@suse.cz>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH][pushed] git_update_version: add robust logging
Date: Thu, 6 Oct 2022 11:16:17 +0200 [thread overview]
Message-ID: <045f9965-d9fd-2c0e-7f14-0f0c1027d633@suse.cz> (raw)
Let's add more robust logging.
Martin
contrib/ChangeLog:
* gcc-changelog/git_update_version.py: Use logging module
and provide robust debugging output.
---
contrib/gcc-changelog/git_update_version.py | 36 ++++++++++++++-------
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/contrib/gcc-changelog/git_update_version.py b/contrib/gcc-changelog/git_update_version.py
index 8462179b5ab..36995d2520b 100755
--- a/contrib/gcc-changelog/git_update_version.py
+++ b/contrib/gcc-changelog/git_update_version.py
@@ -18,6 +18,7 @@
import argparse
import datetime
+import logging
import os
from git import Repo
@@ -34,6 +35,13 @@ IGNORED_COMMITS = (
'3ab5c8cd03d92bf4ec41e351820349d92fbc40c4',
'86d8e0c0652ef5236a460b75c25e4f7093cc0651')
+FORMAT = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
+logging.basicConfig(level=logging.INFO, format=FORMAT,
+ handlers=[
+ logging.FileHandler('/tmp/git_update_version.txt'),
+ logging.StreamHandler()
+ ])
+
def read_timestamp(path):
with open(path) as f:
@@ -43,11 +51,11 @@ def read_timestamp(path):
def prepend_to_changelog_files(repo, folder, git_commit, add_to_git):
if not git_commit.success:
for error in git_commit.errors:
- print(error)
+ logging.info(error)
raise AssertionError()
for entry, output in git_commit.to_changelog_entries(use_commit_ts=True):
full_path = os.path.join(folder, entry, 'ChangeLog')
- print('writing to %s' % full_path)
+ logging.info('writing to %s' % full_path)
if os.path.exists(full_path):
with open(full_path) as f:
content = f.read()
@@ -95,7 +103,7 @@ def update_current_branch(ref_name):
commit = commit.parents[-1]
commit_count += 1
- print('%d revisions since last Daily bump' % commit_count)
+ logging.info('%d revisions since last Daily bump' % commit_count)
datestamp_path = os.path.join(args.git_path, 'gcc/DATESTAMP')
if (read_timestamp(datestamp_path) != current_timestamp
or args.dry_mode or args.current):
@@ -117,11 +125,11 @@ def update_current_branch(ref_name):
branch.name.split('/')[-1] + '.patch')
with open(patch, 'w+') as f:
f.write(diff)
- print('branch diff written to %s' % patch)
+ logging.info('branch diff written to %s' % patch)
repo.git.checkout(force=True)
else:
# update timestamp
- print('DATESTAMP will be changed:')
+ logging.info('DATESTAMP will be changed:')
with open(datestamp_path, 'w+') as f:
f.write(current_timestamp)
repo.git.add(datestamp_path)
@@ -129,14 +137,17 @@ def update_current_branch(ref_name):
repo.index.commit('Daily bump.')
origin.fetch()
if args.push:
- repo.git.push('origin', branch)
- print('branch is pushed')
+ try:
+ repo.git.push('origin', branch)
+ logging.info('branch is pushed')
+ except Exception:
+ logging.exception('git push failed')
else:
- print('DATESTAMP unchanged')
+ logging.info('DATESTAMP unchanged')
if args.current:
- print('=== Working on the current branch ===', flush=True)
+ logging.info('=== Working on the current branch ===')
update_current_branch()
else:
for ref in origin.refs:
@@ -147,10 +158,11 @@ else:
branch = repo.branches[name]
else:
branch = repo.create_head(name, ref).set_tracking_branch(ref)
- print('=== Working on: %s ===' % branch, flush=True)
+ logging.info('=== Working on: %s ===' % branch)
branch.checkout()
origin.pull(rebase=True)
- print('branch pulled and checked out', flush=True)
+ logging.info('branch pulled and checked out')
update_current_branch(name)
assert not repo.index.diff(None)
- print('branch is done\n', flush=True)
+ logging.info('branch is done')
+ logging.info('')
--
2.37.3
reply other threads:[~2022-10-06 9:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=045f9965-d9fd-2c0e-7f14-0f0c1027d633@suse.cz \
--to=mliska@suse.cz \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).