From patchwork Tue Oct 25 11:19:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 59387 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9D8CB385AE58 for ; Tue, 25 Oct 2022 11:20:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D8CB385AE58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666696814; bh=tCXZgkJ6Om2lb13JsXyJ7AN9r/iLAWP6MQxQu9QMEsM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Zo6mVKnihNJ5TzX1E/t+ucONPbaD6VI95Y3UKlHF8ywlqooF4F5o4vnYAFamSIx7y S9C+Vr2UQSYS7dxMOTc6YKvUaCH7U3PII6kxXErFuiRVXfzc3c0lHvbct4BNOu2AbW qE2gvUlM0jTnf4mOIeevXM+NG+S4kLfz7z51vkfE= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 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) 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 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 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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()