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 EE0353857827 for ; Tue, 25 Oct 2022 11:19:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EE0353857827 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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 368A71F8F5 for ; Tue, 25 Oct 2022 11:19:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1666696786; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tCXZgkJ6Om2lb13JsXyJ7AN9r/iLAWP6MQxQu9QMEsM=; b=P2vw1U3afV4fFEK0pmdCzb/iu3w/FYKF7OOaNL9elBZftIY8LxqoaVqYTNH5VL4VEVJ2x+ /KIPywBHNE6+y8pJWemD72pMmW9MyTV0/k6wx66svT8kzMUCcLUUNhu9KCd33OE6TYcC4Q E4oTN4NSU/vtCTUFx3WDH5muubhnwlM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1666696786; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tCXZgkJ6Om2lb13JsXyJ7AN9r/iLAWP6MQxQu9QMEsM=; b=059DWSldCH7VTwppYMnGHKhB+1MzAytLMYmkGaLdK5fNHmnZo5oyoGvW7IvRP/E3TFQqMX S7cbp4C6sSxo4eDw== 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 240AF134CA for ; Tue, 25 Oct 2022 11:19:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id uK21B1LGV2O1dAAAMHmgww (envelope-from ) for ; Tue, 25 Oct 2022 11:19:46 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [RFC 3/5] [gdb/contrib] Add refactor.py Date: Tue, 25 Oct 2022 13:19:43 +0200 Message-Id: <20221025111945.23886-4-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221025111945.23886-1-tdevries@suse.de> References: <20221025111945.23886-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,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: Add a refactoring script gdb/contrib/refactor.py that takes a transformation script as argument, for instance a script gdb/contrib/transform.py, like so: ... $ ./gdb/contrib/refactor.py transform ... --- gdb/contrib/refactor.py | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 gdb/contrib/refactor.py diff --git a/gdb/contrib/refactor.py b/gdb/contrib/refactor.py new file mode 100755 index 00000000000..de2f58bc077 --- /dev/null +++ b/gdb/contrib/refactor.py @@ -0,0 +1,61 @@ +#! /usr/bin/env python3 + +# Copyright (C) 2022 Free Software Foundation, Inc. +# +# This file is part of GDB. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import os +import sys +import re + +# Define scope of refactoring. +dirs = ["gdb", "gdbserver", "gdbsupport"] +avoid_dir = "/testsuite/" +exts = [".c", ".cc", ".h"] + +transform_file = sys.argv[1] +transform_file = re.sub(r"\.py$", r"", transform_file) + +transformation = __import__(transform_file) + +def handle_file(filename): + file = open(filename, 'r+') + data = file.read() + file.close() + + transformation.have_match = False + data = transformation.transform(data) + if transformation.have_match: + file = open(filename, 'w') + file.write(data) + file.close() + +def main(): + for dir in dirs: + for walk_root, walk_dirs, walk_files in os.walk(dir): + for file in walk_files: + full = os.path.join(walk_root, file) + if avoid_dir in full: + continue + found = False + for ext in exts: + if file.endswith(ext): + found = True + break + if found: + handle_file(full) + +main() -- 2.35.3