bapro2qtpro.py :  » GUI » Kodos » kodos-2.4.9 » scripts » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » GUI » Kodos 
Kodos » kodos 2.4.9 » scripts » bapro2qtpro.py
#!/bin/env python
import os, sys, re

# regular expressions from Kodos (http://kodos.sourceforge.net)
rx_folder = re.compile(r'''\<folder name="(?P<folder>.*?)" \>
(?P<data>.*?)
 *\</folder\>''', re.DOTALL)

rx_modules = re.compile(r'''name="(?P<module>.*\.py)"''')

rx_translations = re.compile(r'''TRANSLATIONS *= *(?P<files>.*)''')

class Convert:
    def __init__(self, infile, outfile):
        modules = self.getModules(infile)
        translations = self.getTranslations(outfile)
        self.saveQtFile(outfile, modules, translations)


    def getTranslations(self, outfile):
        translations = ""
        try:
            fp = open(outfile, "r")
            data = fp.read()
            fp.close()

            m = rx_translations.search(data)
            if m:
                translations = m.group("files")
        except:
            pass
        
        return translations


    def getModules(self, infile):
        fp = open(infile, "r")
        data = fp.read()
        fp.close()
        
        modules = []

        m = rx_folder.search(data)
        if m:
            start = m.start()
        else:
            start = len(data)
            
        while m:
            folder = m.group("folder")
            moduledata = m.group("data")

            modules += self.__getModules(folder, moduledata)
            pos = m.end()
            m = rx_folder.search(data, pos)

        modules += self.__getModules(None, data, start)
        return modules

            
    def __getModules(self, folder, moduledata, end=None):
        modules = []
        pos = 0

        while 1:
            if end:
                m = rx_modules.search(moduledata, pos, end)
            else:
                m = rx_modules.search(moduledata, pos)
                
            if not m: break

            pos = m.end()
            name = m.group("module")

            if folder:
                modules.append( os.path.join(folder, name) )
            else:
                modules.append(name)

        return modules


    def saveQtFile(self, outfile, modules, translations):
        fp = open(outfile, "w")
        fp.write("# This file was produced by a script -- editing is not recommended\n")
        fp.write("SOURCES = ");

        for module in modules:
            fp.write("%s " % module)
            
        fp.write("\n")
        fp.write("TRANSLATIONS = %s\n" % translations)


##################################################################################

def usage():
    print "Usage: ", sys.argv[0], " ba.pro qt.pro"
    sys.exit(1)

def convert():
    try:
        infile = sys.argv[1]
        outfile = sys.argv[2]

        if infile == outfile:
            print "ba.pro and qt.pro must refer to different filenames\n"
            usage()
    except:
        usage()
        
    c = Convert(infile, outfile)

##################################################################################
    
if __name__ == '__main__':
    convert()

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.