~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to project/scripts/extractConfigGroups.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-21 23:19:11 UTC
  • mfrom: (1.2.33 upstream) (3.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20101221231911-z9jip7s5aht1jqn9
Tags: 2:1.7.0-1ubuntu1
* Merge from Debian Experimental. Remaining Ubuntu changes:
  - Export .pot name and copy to plugins in debian/rules
  - Version build-depends on kipi-plugins-dev to ensure build is against the
    same version on all archs
* Drop debian/patches/kubuntu_01_linker.diff, incoporated upstream
* Remove patches directory and unused patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# A simple script that extracts config group entry names from a file,
 
4
# generates variable definitions for d-classes and replaces the strings of
 
5
# these entries with the defined variables. The result is stored in a new file.
 
6
# Expects a file name as argument
 
7
#
 
8
# author: Johannes Wienke <languitar at semipol dot de>
 
9
 
 
10
import sys
 
11
import re
 
12
import os
 
13
 
 
14
filename = sys.argv[1]
 
15
 
 
16
print("Opening file " + filename)
 
17
 
 
18
source = open(filename, "r")
 
19
lines = source.readlines()
 
20
 
 
21
expression = re.compile("readEntry\(\"([\s\w]+)\",")
 
22
 
 
23
configKeys = []
 
24
 
 
25
def makeStringDefinition(key):
 
26
    return '"' + key + '"'
 
27
 
 
28
def makeVariable(key):
 
29
    key = key.replace(" ", "")
 
30
    return "config" + key[0].capitalize() + key[1:] + "Entry";
 
31
 
 
32
for line in lines:
 
33
    match = expression.search(line)
 
34
    
 
35
    if match == None:
 
36
        continue
 
37
    
 
38
    configKey = match.group(1)
 
39
    configKeys.append(configKey)
 
40
    
 
41
# initialization
 
42
print("init:")
 
43
for key in configKeys:
 
44
    print("\t" + makeVariable(key) + " = " + makeStringDefinition(key) + ";")
 
45
    
 
46
print("")
 
47
 
 
48
# definition
 
49
print("def:")
 
50
for key in configKeys:
 
51
    print("\tQString " + makeVariable(key) + ";")
 
52
   
 
53
# generate output file
 
54
outname = filename + ".out"
 
55
print("writing replaced entries to " + outname)
 
56
 
 
57
source.seek(0)
 
58
contents = source.read()
 
59
 
 
60
for key in configKeys:
 
61
    print("replacing " + makeStringDefinition(key) + " with d->" + makeVariable(key))
 
62
    contents = contents.replace(makeStringDefinition(key), "d->" + makeVariable(key))
 
63
    
 
64
out = open(outname, "w")
 
65
out.write(contents)
 
66
out.close()
 
67
 
 
68
source.close()