[ooo-build-commit] .: 5 commits - bin/parse-scp2.py

Kohei Yoshida kohei at kemper.freedesktop.org
Thu Jul 15 21:30:49 PDT 2010


 bin/parse-scp2.py |  215 ++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 160 insertions(+), 55 deletions(-)

New commits:
commit 511f1b590bf8ccd99788072e71c24e3167af454a
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Jul 16 00:30:07 2010 -0400

    More attributes for RegistryItem nodes, and default to en-US locales.
    
    * bin/parse-scp2.py:

diff --git a/bin/parse-scp2.py b/bin/parse-scp2.py
index 9d60d32..90779c4 100755
--- a/bin/parse-scp2.py
+++ b/bin/parse-scp2.py
@@ -75,9 +75,6 @@ top_modules = [
     'gid_Module_Optional_OGLTrans'
 ]
 
-def error (msg):
-    sys.stderr.write(msg + "\n")
-
 class ErrorBase(Exception):
     
     def __init__ (self, name, msg, sev):
@@ -108,6 +105,16 @@ class LinkedNode(object):
 
 # ----------------------------------------------------------------------------
 
+def error (msg):
+    sys.stderr.write(msg + "\n")
+
+def get_attr_or_fail (name, key, attrs):
+    if not attrs.has_key(key):
+        raise ParseError("%s doesn't have %s attribute, but expected."%(name, key), 1)
+    return attrs[key]
+
+# ----------------------------------------------------------------------------
+
 class Scp2Tokenizer(object):
     """Tokenizer for scp files."""
 
@@ -246,14 +253,8 @@ class Scp2Parser(object):
                 self.__link_simple(key, attrs, nodetree, 'ProfileID')
                 
 
-    def __get_attr_or_fail (self, name, key, attrs):
-        if not attrs.has_key(key):
-            raise ParseError("%s doesn't have %s attribute, but expected."%(name, key), 1)
-        return attrs[key]
-
-
     def __link_simple (self, name, attrs, nodetree, pid_attr):
-        parentID = self.__get_attr_or_fail(name, pid_attr, attrs)
+        parentID = get_attr_or_fail(name, pid_attr, attrs)
         if not nodetree.has_key(parentID):
             nodetree[parentID] = LinkedNode(parentID)
         if not nodetree.has_key(name):
@@ -391,6 +392,19 @@ class XMLFunc:
         return s
 
     @staticmethod
+    def add_attr_localized (attrs, key, locale):
+        if attrs.has_key(key):
+            # Try non-localized name first.
+            return " %s=\"%s\""%(XMLFunc.to_xml_name(key), attrs[key])
+        
+        key_localized = key + "(%s)"%locale
+        if attrs.has_key(key_localized):
+            # Try non-localized name first.
+            return " %s=\"%s\" locale=\"%s\""%(XMLFunc.to_xml_name(key), attrs[key_localized], locale)
+
+        return ''
+
+    @staticmethod
     def add_attr_vars (attrs, key, vars):
         if not attrs.has_key(key):
             return ''
@@ -437,6 +451,7 @@ class Scp2Processor(object):
         self.scp_files = []
         self.nodedata = {}
         self.nodetree = {}
+        self.locale = 'en-US'
 
         # Check file paths first.
         if not os.path.isfile("%s/scp2/inc/macros.inc"%self.cur_dir):
@@ -520,16 +535,17 @@ class Scp2Processor(object):
         node = self.nodetree[root]
         self.__print_summary_tree_node(node, 0)
 
-    def __get_fullpath (self, fileID):
+    def __get_fullpath (self, fileID, locale):
         """Given a file identifier, construct the absolute path for that file."""
 
         nodedata = self.nodedata[fileID]
         filename = None
         localized = False
+        key_localized = "Name(%s)"%locale
         if nodedata.has_key('Name'):
             filename = nodedata['Name']
-        elif nodedata.has_key('Name(en-US)'):
-            filename = nodedata['Name(en-US)']
+        elif nodedata.has_key(key_localized):
+            filename = nodedata[key_localized]
             localized = True
         else:
             raise DirError("%s doesn't have a name attribute."%fileID)
@@ -576,7 +592,6 @@ class Scp2Processor(object):
 
         if not self.nodedata.has_key(node.name):
             # This node is referenced but is not defined.  Skip it.
-            #error("Node '%s' is referenced but not defined."%node.name)
             return
 
         nodedata = self.nodedata[node.name]
@@ -589,7 +604,7 @@ class Scp2Processor(object):
         localized = False
         if node_type in ['File', 'Unixlink', 'Shortcut', 'Profile']:
             try:
-                name, localized = self.__get_fullpath(node.name)
+                name, localized = self.__get_fullpath(node.name, self.locale)
                 name = XMLFunc.resolve_vars(name, self.vars)
             except DirError as e:
                 error(e.value)
@@ -618,8 +633,14 @@ class Scp2Processor(object):
         elif node_type == 'Unixlink':
             s += XMLFunc.add_attr_vars(nodedata, 'Target', self.vars)
 
+        elif node_type == 'RegistryItem':
+            val_path = get_attr_or_fail(node.name, 'ParentID', nodedata)
+            val_path += '\\' + get_attr_or_fail(node.name, 'Subkey', nodedata)
+            s += " path=\"%s\""%val_path
+            s += XMLFunc.add_attr_localized(nodedata, 'Value', self.locale)
+
         if localized:
-            s += " localized=\"true\""
+            s += " locale=\"%s\""%self.locale
 
         if len(node.children) > 0:
             s += ">"
commit 3f75ab1ac53356a85cfc52efb2284f517190ffc5
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Thu Jul 15 23:54:26 2010 -0400

    Pick up Profile and ProfileItem nodes.
    
    These two nodes are used to construct *rc files on unix, and *.ini
    files on windows during installation.
    
    * bin/parse-scp2.py:

diff --git a/bin/parse-scp2.py b/bin/parse-scp2.py
index d4f400c..9d60d32 100755
--- a/bin/parse-scp2.py
+++ b/bin/parse-scp2.py
@@ -236,15 +236,22 @@ class Scp2Parser(object):
             if node_type == 'Module':
                 self.__link_module_node(key, attrs, nodetree)
             elif node_type == 'RegistryItem':
-                self.__link_registry_item(key, attrs, nodetree)
+                # RegistryItem entries have ModuleID to link back to a module.
+                self.__link_simple(key, attrs, nodetree, 'ModuleID')
             elif node_type == 'Shortcut':
-                self.__link_shortcut(key, attrs, nodetree)
+                self.__link_simple(key, attrs, nodetree, 'FileID')
+            elif node_type == 'Profile':
+                self.__link_simple(key, attrs, nodetree, 'ModuleID')
+            elif node_type == 'ProfileItem':
+                self.__link_simple(key, attrs, nodetree, 'ProfileID')
+                
 
     def __get_attr_or_fail (self, name, key, attrs):
         if not attrs.has_key(key):
             raise ParseError("%s doesn't have %s attribute, but expected."%(name, key), 1)
         return attrs[key]
 
+
     def __link_simple (self, name, attrs, nodetree, pid_attr):
         parentID = self.__get_attr_or_fail(name, pid_attr, attrs)
         if not nodetree.has_key(parentID):
@@ -258,15 +265,6 @@ class Scp2Parser(object):
         nodetree[name].parent = nodetree[parentID]
 
 
-    def __link_shortcut (self, name, attrs, nodetree):
-        self.__link_simple(name, attrs, nodetree, 'FileID')
-
-
-    def __link_registry_item (self, name, attrs, nodetree):
-        # RegistryItem entries have ModuleID to link back to a module.
-        self.__link_simple(name, attrs, nodetree, 'ModuleID')
-
-
     def __link_files (self, name, files, nodetree):
 
         # file list strings are formatted like this '(file1,file2,file3,....)'
@@ -347,6 +345,30 @@ class Scp2Parser(object):
 class XMLFunc:
 
     @staticmethod
+    def resolve_vars (s, vars):
+        """Replace all ${...}s with their respective values."""
+
+        ret = ''
+        
+        while True:
+            start = s.find('${')
+            if start == -1:
+                ret += s
+                break
+    
+            end = s.find('}', start+2)
+            if end == -1:
+                ret += s
+                break
+    
+            key = s[start+2:end]
+            if vars.has_key(key):
+                ret += s[:start] + vars[key]
+            s = s[end+1:]
+    
+        return ret
+
+    @staticmethod
     def to_xml_name (name):
         """CamelCase to camel-case"""
         s = ''
@@ -369,6 +391,15 @@ class XMLFunc:
         return s
 
     @staticmethod
+    def add_attr_vars (attrs, key, vars):
+        if not attrs.has_key(key):
+            return ''
+
+        s = " %s=\"%s\""%(XMLFunc.to_xml_name(key), XMLFunc.resolve_vars(attrs[key], vars))
+        return s
+
+
+    @staticmethod
     def add_attr_array (attrs, key):
 
         if not attrs.has_key(key):
@@ -536,24 +567,6 @@ class Scp2Processor(object):
 
         return filename, localized
 
-    def __resolve_vars (self, s):
-        """Replace all ${...}s with their respective values."""
-
-        while True:
-            start = s.find('${')
-            if start == -1:
-                break
-    
-            end = s.find('}', start+2)
-            if end == -1:
-                break
-    
-            key = s[start+2:end]
-            if self.vars.has_key(key):
-                s = s[:start] + self.vars[key] + s[end+1:]
-    
-        return s
-
     def __print_summary_tree_node (self, node, level):
 
         indent = '    '*level
@@ -574,10 +587,10 @@ class Scp2Processor(object):
 
         name = ''
         localized = False
-        if node_type in ['File', 'Unixlink', 'Shortcut']:
+        if node_type in ['File', 'Unixlink', 'Shortcut', 'Profile']:
             try:
                 name, localized = self.__get_fullpath(node.name)
-                name = self.__resolve_vars(name)
+                name = XMLFunc.resolve_vars(name, self.vars)
             except DirError as e:
                 error(e.value)
                 return
@@ -594,10 +607,16 @@ class Scp2Processor(object):
             s += XMLFunc.add_attr(nodedata, 'UnixRights')
             s += XMLFunc.add_attr_array(nodedata, 'Styles')
 
+        elif node_type == 'Profile':
+            s += XMLFunc.add_attr_array(nodedata, 'Styles')
+
+        elif node_type == 'ProfileItem':
+            s += XMLFunc.add_attr(nodedata, 'Section')
+            s += XMLFunc.add_attr(nodedata, 'Key')
+            s += XMLFunc.add_attr_vars(nodedata, 'Value', self.vars)
+
         elif node_type == 'Unixlink':
-            target = nodedata['Target']
-            target = self.__resolve_vars(target)
-            s += " target=\"%s\""%target
+            s += XMLFunc.add_attr_vars(nodedata, 'Target', self.vars)
 
         if localized:
             s += " localized=\"true\""
commit 892b0328ec8cbe85b42d68e44282be77db7ed432
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Thu Jul 15 23:00:08 2010 -0400

    Pick up Styles attribute for Module nodes.
    
    * bin/parse-scp2.py:

diff --git a/bin/parse-scp2.py b/bin/parse-scp2.py
index 9574e9d..d4f400c 100755
--- a/bin/parse-scp2.py
+++ b/bin/parse-scp2.py
@@ -378,6 +378,9 @@ class XMLFunc:
         if len(raw_str) == 0 or raw_str[0] != '(' or raw_str[-1] != ')':
             raise ParseError("%s attribute is not formatted properly: '%s'"%(key, raw_str), 1)
 
+        if raw_str == '()':
+            return ''
+
         val = raw_str[1:-1].lower().replace('_', '-')
         s = " %s=\"%s\""%(XMLFunc.to_xml_name(key), val)
         return s
@@ -584,11 +587,14 @@ class Scp2Processor(object):
         if len(name) > 0:
             s += " name=\"%s\""%name
 
-        if node_type == 'File':
+        if node_type == 'Module':
+            s += XMLFunc.add_attr_array(nodedata, 'Styles')
+
+        elif node_type == 'File':
             s += XMLFunc.add_attr(nodedata, 'UnixRights')
             s += XMLFunc.add_attr_array(nodedata, 'Styles')
 
-        if node_type == 'Unixlink':
+        elif node_type == 'Unixlink':
             target = nodedata['Target']
             target = self.__resolve_vars(target)
             s += " target=\"%s\""%target
commit 2d980ad46c51383696932ea1a3ae3dfea1f3754d
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Thu Jul 15 22:49:55 2010 -0400

    Determine if the file names are localized.
    
    * bin/parse-scp2.py:

diff --git a/bin/parse-scp2.py b/bin/parse-scp2.py
index bf2c7a9..9574e9d 100755
--- a/bin/parse-scp2.py
+++ b/bin/parse-scp2.py
@@ -491,10 +491,12 @@ class Scp2Processor(object):
 
         nodedata = self.nodedata[fileID]
         filename = None
+        localized = False
         if nodedata.has_key('Name'):
             filename = nodedata['Name']
         elif nodedata.has_key('Name(en-US)'):
             filename = nodedata['Name(en-US)']
+            localized = True
         else:
             raise DirError("%s doesn't have a name attribute."%fileID)
 
@@ -507,7 +509,8 @@ class Scp2Processor(object):
 
             if parent_dir_name == 'PREDEFINED_PROGDIR':
                 # special directory name
-                return parent_dir_name + '/' + filename
+                filename = parent_dir_name + '/' + filename
+                break
 
             if not self.nodedata.has_key(parent_dir_name):
                 # directory is referenced but not defined.  Skip it for now.
@@ -528,7 +531,7 @@ class Scp2Processor(object):
             else:
                 parent_dir_name = None
 
-        return filename
+        return filename, localized
 
     def __resolve_vars (self, s):
         """Replace all ${...}s with their respective values."""
@@ -567,9 +570,10 @@ class Scp2Processor(object):
         node_type = nodedata['__node_type__']
 
         name = ''
+        localized = False
         if node_type in ['File', 'Unixlink', 'Shortcut']:
             try:
-                name = self.__get_fullpath(node.name)
+                name, localized = self.__get_fullpath(node.name)
                 name = self.__resolve_vars(name)
             except DirError as e:
                 error(e.value)
@@ -589,6 +593,9 @@ class Scp2Processor(object):
             target = self.__resolve_vars(target)
             s += " target=\"%s\""%target
 
+        if localized:
+            s += " localized=\"true\""
+
         if len(node.children) > 0:
             s += ">"
             print (s)
commit 98681ad735cde0e21de3638aa75c83283a6f71d7
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Thu Jul 15 22:38:38 2010 -0400

    Extra attributes for File nodes such as UnixRights and Styles.
    
    * bin/parse-scp2.py:

diff --git a/bin/parse-scp2.py b/bin/parse-scp2.py
index aad491d..bf2c7a9 100755
--- a/bin/parse-scp2.py
+++ b/bin/parse-scp2.py
@@ -7,6 +7,7 @@ arg_desc = ""
 desc = """
 Run this script at the root of OOo source tree."""
 
+# taken from setup_native/source/packinfo/packinfo_office.txt
 top_modules = [
     'gid_Module_Optional_Gnome',
     'gid_Module_Optional_Kde',
@@ -108,6 +109,7 @@ class LinkedNode(object):
 # ----------------------------------------------------------------------------
 
 class Scp2Tokenizer(object):
+    """Tokenizer for scp files."""
 
     def __init__ (self, content):
         self.content = content
@@ -148,8 +150,8 @@ class Scp2Tokenizer(object):
 
 # ----------------------------------------------------------------------------
 
-# Parse each .scp file.
 class Scp2Parser(object):
+    """Parser for scp files."""
 
     class Type:
         File       = 0
@@ -162,7 +164,7 @@ class Scp2Parser(object):
         'File',                # done, linked from within Module
         'Folder',              # ignored
         'FolderItem',          # ignored for now.  windows specific?
-        'Installation',        # ignore.  I don't know what this is for.
+        'Installation',        # ignored.  I don't know what this is for.
         'Module',              # done
         'Profile',             # ignored
         'ProfileItem',         # ignored
@@ -342,8 +344,48 @@ class Scp2Parser(object):
 
 # ----------------------------------------------------------------------------
 
-# Collect all .scp files in scp2 directory, and run preprocessor.
+class XMLFunc:
+
+    @staticmethod
+    def to_xml_name (name):
+        """CamelCase to camel-case"""
+        s = ''
+        n = len(name)
+        for i in xrange(0, n):
+            c = name[i]
+            if 'A' <= c and c <= 'Z':
+                if i > 0:
+                    s += '-'
+                s += c.lower()
+            else:
+                s += c
+        return s
+
+    @staticmethod
+    def add_attr (attrs, key):
+        s = ''
+        if attrs.has_key(key):
+            s = " %s=\"%s\""%(XMLFunc.to_xml_name(key), attrs[key])
+        return s
+
+    @staticmethod
+    def add_attr_array (attrs, key):
+
+        if not attrs.has_key(key):
+            return ''
+
+        raw_str = attrs[key]
+        if len(raw_str) == 0 or raw_str[0] != '(' or raw_str[-1] != ')':
+            raise ParseError("%s attribute is not formatted properly: '%s'"%(key, raw_str), 1)
+
+        val = raw_str[1:-1].lower().replace('_', '-')
+        s = " %s=\"%s\""%(XMLFunc.to_xml_name(key), val)
+        return s
+
+
+
 class Scp2Processor(object):
+    """Collect all .scp files in scp2 directory, and run preprocessor."""
 
     tmpin  = "/tmp/parse-scp2.py.cpp"
     tmpout = "/tmp/parse-scp2.py.out"
@@ -445,6 +487,8 @@ class Scp2Processor(object):
         self.__print_summary_tree_node(node, 0)
 
     def __get_fullpath (self, fileID):
+        """Given a file identifier, construct the absolute path for that file."""
+
         nodedata = self.nodedata[fileID]
         filename = None
         if nodedata.has_key('Name'):
@@ -487,6 +531,7 @@ class Scp2Processor(object):
         return filename
 
     def __resolve_vars (self, s):
+        """Replace all ${...}s with their respective values."""
 
         while True:
             start = s.find('${')
@@ -530,9 +575,15 @@ class Scp2Processor(object):
                 error(e.value)
                 return
 
-        s = indent + "<%s id=\"%s\""%(node_type, node.name)
+        s = indent + "<%s id=\"%s\""%(XMLFunc.to_xml_name(node_type), node.name)
+
         if len(name) > 0:
             s += " name=\"%s\""%name
+
+        if node_type == 'File':
+            s += XMLFunc.add_attr(nodedata, 'UnixRights')
+            s += XMLFunc.add_attr_array(nodedata, 'Styles')
+
         if node_type == 'Unixlink':
             target = nodedata['Target']
             target = self.__resolve_vars(target)
@@ -547,7 +598,7 @@ class Scp2Processor(object):
             for child in children:
                 self.__print_summary_tree_node(child, level+1)
     
-            print (indent + "</%s>"%node_type)
+            print (indent + "</%s>"%XMLFunc.to_xml_name(node_type))
         else:
             s += "/>"
             print (s)
@@ -563,6 +614,7 @@ class Scp2Processor(object):
 # ----------------------------------------------------------------------------
 
 class OOLstParser(object):
+    """Parser for openoffice.lst file."""
 
     def __init__ (self):
         self.vars = {}


More information about the ooo-build-commit mailing list