public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3110] git_update_version: add robust logging
@ 2022-10-06  9:17 Martin Liska
  0 siblings, 0 replies; only message in thread
From: Martin Liska @ 2022-10-06  9:17 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ed7278d98e4727a7def30ab91fcef4658e34baa4

commit r13-3110-ged7278d98e4727a7def30ab91fcef4658e34baa4
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Oct 6 11:14:48 2022 +0200

    git_update_version: add robust logging
    
    contrib/ChangeLog:
    
            * gcc-changelog/git_update_version.py: Use logging module
            and provide robust debugging output.

Diff:
---
 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('')

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-06  9:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-06  9:17 [gcc r13-3110] git_update_version: add robust logging Martin Liska

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).