From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 54411384D152 for ; Thu, 6 Oct 2022 09:16:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 54411384D152 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3F4FF1F8F1 for ; Thu, 6 Oct 2022 09:16:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1665047778; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3lqZcBPDNSgXXXZlbx9zdhYVVw0WAzRG1nG0mDLOkb4=; b=HOIi+MaD7aYOKzXLXEGxZJZBTfxfeagA9Xqy2l3wk+cclaDejcyvJu8V+Kx6s9zc+laaIn InPZ2oidfwoFHAt8dzjeljsV7VnVbb/YBeOBwUB7uWG9RjCux6KPc2j0qJOXIlVJfYexkz dleqIL4tyZlMmzLQoNwSKSeiNI9QJWM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1665047778; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3lqZcBPDNSgXXXZlbx9zdhYVVw0WAzRG1nG0mDLOkb4=; b=xRLh1s8vVR+yHgvMbvEkKCxwNjwyrX/P43IXXlLD1MdMZ5t7wQueLHxQxhnFXH1NmCXqmZ VfntcAZFsDwx1/Cw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2BF301376E for ; Thu, 6 Oct 2022 09:16:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id bk7fCeKcPmPxTQAAMHmgww (envelope-from ) for ; Thu, 06 Oct 2022 09:16:18 +0000 Message-ID: <045f9965-d9fd-2c0e-7f14-0f0c1027d633@suse.cz> Date: Thu, 6 Oct 2022 11:16:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH][pushed] git_update_version: add robust logging To: gcc-patches@gcc.gnu.org Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_SOFTFAIL,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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