[Skencil-commits] r774 - skencil/branches/skencil-0.6

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Oct 30 21:44:28 CEST 2010


Author: igor_n
Date: 2010-10-30 21:44:28 +0200 (Sat, 30 Oct 2010)
New Revision: 774

Modified:
   skencil/branches/skencil-0.6/setup.py
Log:
build_locales command is implemented

Modified: skencil/branches/skencil-0.6/setup.py
===================================================================
--- skencil/branches/skencil-0.6/setup.py	2010-10-30 19:43:39 UTC (rev 773)
+++ skencil/branches/skencil-0.6/setup.py	2010-10-30 19:44:28 UTC (rev 774)
@@ -28,18 +28,118 @@
 # --------------------------------------------------------------------------
 #  to create binary RPM distribution:  python setup.py bdist_rpm
 # --------------------------------------------------------------------------
+#  to create localization .mo files: python setup.py build_locales (Linux only)
+# --------------------------------------------------------------------------
 #
 #  help on available distribution formats: python setup.py bdist --help-formats
 #
 
-import os
+import os, sys
 
 
 COPY = False
 DEBIAN = False
 VERSION = '1.0alpha'
 
+############################################################
+#
+# Routines for build procedure
+#
+############################################################
 
+#Return directory list for provided path
+def get_dirs(path='.'):
+    list=[]
+    if path:
+        if os.path.isdir(path):
+            try:
+                names = os.listdir(path)
+            except os.error:
+                return []
+        names.sort()
+        for name in names:
+            if os.path.isdir(os.path.join(path, name)):
+                list.append(name)
+        return list
+            
+#Return full  directory names list for provided path    
+def get_dirs_withpath(path='.'):
+    list=[]
+    names=[]
+    if os.path.isdir(path):
+        try:
+            names = os.listdir(path)
+        except os.error:
+            return names
+    names.sort()
+    for name in names:
+        if os.path.isdir(os.path.join(path, name)) and not name=='.svn':
+            list.append(os.path.join(path, name))
+    return list
+
+#Return file list for provided path
+def get_files(path='.', ext='*'):    
+    list=[]
+    if path:
+        if os.path.isdir(path):
+            try:
+                names = os.listdir(path)
+            except os.error:
+                return []
+        names.sort()
+        for name in names:
+            if not os.path.isdir(os.path.join(path, name)):
+                if ext=='*':
+                    list.append(name)
+                elif '.'+ext==name[-1*(len(ext)+1):]:
+                    list.append(name)                
+    return list
+
+#Return full file names list for provided path
+def get_files_withpath(path='.', ext='*'):
+    import glob
+    list = glob.glob(os.path.join(path, "*."+ext))
+    list.sort()
+    result=[]
+    for file in list:
+        if os.path.isfile(file):
+            result.append(file)
+    return result
+
+#Return recursive directories list for provided path
+def get_dirs_tree(path='.'):
+    tree=get_dirs_withpath(path)
+    res=[]+tree
+    for node in tree:
+        subtree=get_dirs_tree(node)
+        res+=subtree
+    return res    
+    
+#Return recursive files list for provided path
+def get_files_tree(path='.', ext='*'):
+    tree=[]
+    dirs=[path,]    
+    dirs+=get_dirs_tree(path)
+    for dir in dirs:
+        list = get_files_withpath(dir,ext)
+        list.sort()
+        tree+=list
+    return tree
+ 
+#Generates *.mo files Resources/Messages
+def generate_locales():
+    print 'LOCALES BUILD'
+    files=get_files('po','po')
+    if len(files):
+        for file in files:
+            lang=file.split('.')[0]    
+            po_file=os.path.join('po',file)        
+            mo_file=os.path.join('src','Resources','Messages',lang,'LC_MESSAGES','skencil.mo')
+            if not os.path.lexists(os.path.join('src','Resources','Messages',lang,'LC_MESSAGES')):
+                os.makedirs(os.path.join('src','Resources','Messages',lang,'LC_MESSAGES'))
+            print po_file, '==>',mo_file
+            os.system('msgfmt -o '+mo_file+' '+po_file)        
+
 ############################################################
 #
 # Main build procedure
@@ -48,6 +148,10 @@
 
 if __name__ == "__main__":
     
+    if len(sys.argv)>1 and sys.argv[1]=='build_locales':
+        generate_locales()
+        sys.exit(0)
+    
     from distutils.core import setup, Extension
 
     src_path = 'src/'



More information about the Skencil-commits mailing list