File indexing completed on 2024-05-19 04:19:14
0001 #!/usr/bin/env python 0002 0003 # ============================================================ 0004 # 0005 # This file is a part of digiKam project 0006 # https://www.digikam.org 0007 # 0008 # Date : 2012-07-14 0009 # Description : A simple script that extracts config group entry 0010 # names from a file, generates variable definitions 0011 # for d-classes and replaces the strings of these 0012 # entries with the defined variables. The result is 0013 # stored in a new file. Expects a file name as argument 0014 # 0015 # SPDX-FileCopyrightText: 2012 by Johannes Wienke <languitar at semipol dot de> 0016 # 0017 # SPDX-License-Identifier: BSD-3-Clause 0018 # 0019 # ============================================================ */ 0020 0021 import sys 0022 import re 0023 import os 0024 0025 filename = sys.argv[1] 0026 0027 print("Opening file " + filename) 0028 0029 source = open(filename, "r") 0030 lines = source.readlines() 0031 0032 expression = re.compile("readEntry\(\"([\s\w]+)\",") 0033 0034 configKeys = [] 0035 0036 def makeStringDefinition(key): 0037 return '"' + key + '"' 0038 0039 def makeVariable(key): 0040 key = key.replace(" ", "") 0041 return "config" + key[0].capitalize() + key[1:] + "Entry"; 0042 0043 for line in lines: 0044 match = expression.search(line) 0045 0046 if match == None: 0047 continue 0048 0049 configKey = match.group(1) 0050 configKeys.append(configKey) 0051 0052 # initialization 0053 print("init:") 0054 for key in configKeys: 0055 print("\t" + makeVariable(key) + " = " + makeStringDefinition(key) + ";") 0056 0057 print("") 0058 0059 # definition 0060 print("def:") 0061 for key in configKeys: 0062 print("\tQString " + makeVariable(key) + ";") 0063 0064 # generate output file 0065 outname = filename + ".out" 0066 print("writing replaced entries to " + outname) 0067 0068 source.seek(0) 0069 contents = source.read() 0070 0071 for key in configKeys: 0072 print("replacing " + makeStringDefinition(key) + " with d->" + makeVariable(key)) 0073 contents = contents.replace(makeStringDefinition(key), "d->" + makeVariable(key)) 0074 0075 out = open(outname, "w") 0076 out.write(contents) 0077 out.close() 0078 0079 source.close()