[ooo-build-commit] .: 5 commits - bin/parse-scp2.py
Kohei Yoshida
kohei at kemper.freedesktop.org
Wed Jul 14 17:58:04 PDT 2010
bin/parse-scp2.py | 177 ++++++++++++++++++++++++++++++++++++------------------
1 file changed, 120 insertions(+), 57 deletions(-)
New commits:
commit a8fc25aff323d67c0073d2caf01373c90a70be24
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Wed Jul 14 20:57:32 2010 -0400
StarRegistry and WindowsCustomAction nodes are ignored.
* bin/parse-scp2.py:
diff --git a/bin/parse-scp2.py b/bin/parse-scp2.py
index 20a428f..8b7826e 100755
--- a/bin/parse-scp2.py
+++ b/bin/parse-scp2.py
@@ -94,9 +94,9 @@ class Scp2Parser(object):
'RegistryItem', # done
'ScpAction', # ignored
'Shortcut', # linked to File? Treat this as a child of File for now.
- 'StarRegistry', #
+ 'StarRegistry', # ignored, probably for StarOffice only
'Unixlink', # done, linked from within Module
- 'WindowsCustomAction' #
+ 'WindowsCustomAction' # ignored
]
def __init__ (self, content, filename):
commit b36321acbeb6cd0dc1004b9948af597a31061ca1
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Wed Jul 14 20:54:28 2010 -0400
Handle Shortcut nodes as child nodes of File's.
* bin/parse-scp2.py:
diff --git a/bin/parse-scp2.py b/bin/parse-scp2.py
index f783be6..20a428f 100755
--- a/bin/parse-scp2.py
+++ b/bin/parse-scp2.py
@@ -87,13 +87,13 @@ class Scp2Parser(object):
'File', # done, linked from within Module
'Folder', # ignored
'FolderItem', # ignored for now. windows specific?
- 'Installation', #
+ 'Installation', # ignore. I don't know what this is for.
'Module', # done
- 'Profile', #
- 'ProfileItem', #
- 'RegistryItem', #
- 'ScpAction', #
- 'Shortcut', #
+ 'Profile', # ignored
+ 'ProfileItem', # ignored
+ 'RegistryItem', # done
+ 'ScpAction', # ignored
+ 'Shortcut', # linked to File? Treat this as a child of File for now.
'StarRegistry', #
'Unixlink', # done, linked from within Module
'WindowsCustomAction' #
@@ -158,6 +158,42 @@ class Scp2Parser(object):
node_type = attrs['__node_type__']
if node_type == 'Module':
self.__link_module_node(key, attrs, nodetree)
+ elif node_type == 'RegistryItem':
+ self.__link_registry_item(key, attrs, nodetree)
+ elif node_type == 'Shortcut':
+ self.__link_shortcut(key, attrs, nodetree)
+
+ 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))
+ return attrs[key]
+
+ def __link_shortcut (self, name, attrs, nodetree):
+ fileID = self.__get_attr_or_fail(name, 'FileID', attrs)
+ if not nodetree.has_key(fileID):
+ nodetree[fileID] = LinkedNode(fileID)
+ if not nodetree.has_key(name):
+ nodetree[name] = LinkedNode(name)
+
+ nodetree[fileID].children.append(nodetree[name])
+ if nodetree[name].parent != None:
+ raise ParseError("parent node instance already exists for '%s'"%name, 1)
+ nodetree[name].parent = nodetree[fileID]
+
+
+ def __link_registry_item (self, name, attrs, nodetree):
+ # RegistryItem entries have ModuleID to link back to a module.
+ moduleID = self.__get_attr_or_fail(name, 'ModuleID', attrs)
+ if not nodetree.has_key(moduleID):
+ nodetree[moduleID] = LinkedNode(moduleID)
+ if not nodetree.has_key(name):
+ nodetree[name] = LinkedNode(name)
+
+ nodetree[moduleID].children.append(nodetree[name])
+ if nodetree[name].parent != None:
+ raise ParseError("parent node instance already exists for '%s'"%name, 1)
+ nodetree[name].parent = nodetree[moduleID]
+
def __link_files (self, name, files, nodetree):
@@ -182,7 +218,7 @@ class Scp2Parser(object):
nodetree[parentID].children.append(nodetree[name])
if nodetree[name].parent != None:
- raise ParseError("parent node instance already exists for '%s'"%parentID, 1)
+ raise ParseError("parent node instance already exists for '%s'"%name, 1)
nodetree[name].parent = nodetree[parentID]
if attrs.has_key('Files'):
@@ -394,7 +430,7 @@ class Scp2Processor(object):
node_type = nodedata['__node_type__']
name = ''
- if node_type in ['File', 'Unixlink']:
+ if node_type in ['File', 'Unixlink', 'Shortcut']:
try:
name = self.__get_fullpath(node.name)
except DirError as e:
commit 9779861126ca217dc0e336d42793b131ee841d0d
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Wed Jul 14 20:28:52 2010 -0400
Skip files whose paths are incomplete.
There are Files entries that appear to be obsolete & no longer exist.
We should just skip them.
* bin/parse-scp2.py:
diff --git a/bin/parse-scp2.py b/bin/parse-scp2.py
index d6740d7..f783be6 100755
--- a/bin/parse-scp2.py
+++ b/bin/parse-scp2.py
@@ -398,7 +398,8 @@ class Scp2Processor(object):
try:
name = self.__get_fullpath(node.name)
except DirError as e:
- name = e.value
+ error(e.value)
+ return
s = indent + "<%s id=\"%s\""%(node_type, node.name)
if len(name) > 0:
commit 38e723cf86e89e42d3353d5bfc4529ba98f530db
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Wed Jul 14 20:12:13 2010 -0400
Handle Unixlink nodes, which represent symbolic links.
* bin/parse-scp2.py:
diff --git a/bin/parse-scp2.py b/bin/parse-scp2.py
index 6222a8b..d6740d7 100755
--- a/bin/parse-scp2.py
+++ b/bin/parse-scp2.py
@@ -82,21 +82,21 @@ class Scp2Parser(object):
FolderItem = 2
NodeTypes = [
- 'DataCarrier',
- 'Directory',
- 'File',
- 'Folder',
- 'FolderItem',
- 'Installation',
- 'Module',
- 'Profile',
- 'ProfileItem',
- 'RegistryItem',
- 'ScpAction',
- 'Shortcut',
- 'StarRegistry',
- 'Unixlink',
- 'WindowsCustomAction'
+ 'DataCarrier', # ignored
+ 'Directory', # ignored, referenced directly from File
+ 'File', # done, linked from within Module
+ 'Folder', # ignored
+ 'FolderItem', # ignored for now. windows specific?
+ 'Installation', #
+ 'Module', # done
+ 'Profile', #
+ 'ProfileItem', #
+ 'RegistryItem', #
+ 'ScpAction', #
+ 'Shortcut', #
+ 'StarRegistry', #
+ 'Unixlink', # done, linked from within Module
+ 'WindowsCustomAction' #
]
def __init__ (self, content, filename):
@@ -109,6 +109,12 @@ class Scp2Parser(object):
tokenizer.run()
self.tokens = tokenizer.tokens
+ def next (self):
+ self.i += 1
+
+ def token (self):
+ return self.tokens[self.i]
+
def parse (self):
if len(self.tokens) == 0:
# No tokens to parse. Bail out.
@@ -152,7 +158,19 @@ class Scp2Parser(object):
node_type = attrs['__node_type__']
if node_type == 'Module':
self.__link_module_node(key, attrs, nodetree)
-
+
+ def __link_files (self, name, files, nodetree):
+
+ # file list strings are formatted like this '(file1,file2,file3,....)'
+ if files[0] != '(' or files[-1] != ')':
+ raise ParseError("file list string is not formatted correctly: %s"%files)
+ files = files[1:-1]
+ list = files.split(',')
+ for file in list:
+ if not nodetree.has_key(file):
+ nodetree[file] = LinkedNode(file)
+ nodetree[name].children.append(nodetree[file])
+
def __link_module_node (self, name, attrs, nodetree):
@@ -168,24 +186,11 @@ class Scp2Parser(object):
nodetree[name].parent = nodetree[parentID]
if attrs.has_key('Files'):
- # file list strings are formatted '(file1,file2,file3,....)'
- files = attrs['Files']
- if files[0] != '(' or files[-1] != ')':
- raise ParseError("file list string is not formatted correctly: %s"%files)
- files = files[1:-1]
- list = files.split(',')
- for file in list:
-
- if not nodetree.has_key(file):
- nodetree[file] = LinkedNode(file)
- nodetree[name].children.append(nodetree[file])
+ self.__link_files(name, attrs['Files'], nodetree)
+ if attrs.has_key('Unixlinks'):
+ self.__link_files(name, attrs['Unixlinks'], nodetree)
- def next (self):
- self.i += 1
-
- def token (self):
- return self.tokens[self.i]
def __parseEntity (self):
self.next()
@@ -389,17 +394,17 @@ class Scp2Processor(object):
node_type = nodedata['__node_type__']
name = ''
- if node_type == 'File':
+ if node_type in ['File', 'Unixlink']:
try:
name = self.__get_fullpath(node.name)
except DirError as e:
name = e.value
- elif node_type == 'Directory':
- name = ndoedata['DosName']
s = indent + "<%s id=\"%s\""%(node_type, node.name)
if len(name) > 0:
s += " name=\"%s\""%name
+ if node_type == 'Unixlink':
+ s += " target=\"%s\""%nodedata['Target']
if len(node.children) > 0:
s += ">"
commit 251cbcc789e7e30bb89999cbfd6f6b6b8a596e2d
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Wed Jul 14 16:24:15 2010 -0400
Separated the scp2 tokenizer into its own class.
* bin/parse-scp2.py:
diff --git a/bin/parse-scp2.py b/bin/parse-scp2.py
index 4ec7651..6222a8b 100755
--- a/bin/parse-scp2.py
+++ b/bin/parse-scp2.py
@@ -34,6 +34,45 @@ class LinkedNode(object):
self.parent = None
self.children = []
+class Scp2Tokenizer(object):
+
+ def __init__ (self, content):
+ self.content = content
+ self.tokens = []
+
+ def flush_buffer (self):
+ if len(self.buf) > 0:
+ self.tokens.append(self.buf)
+ self.buf = ''
+
+ def run (self):
+ self.tokens = []
+ i = 0
+ n = len(self.content)
+ self.buf = ''
+ while i < n:
+ c = self.content[i]
+ if c in '\t\n':
+ c = ' '
+
+ if c in ' ;':
+ self.flush_buffer()
+ if c == ';':
+ self.tokens.append(c)
+ elif c == '"':
+ # String literal. Parse until reaching the closing quote.
+ self.flush_buffer()
+ i += 1
+ c = self.content[i]
+ while c != '"':
+ self.buf += c
+ i += 1
+ c = self.content[i]
+ self.flush_buffer()
+ else:
+ self.buf += c
+ i += 1
+
# Parse each .scp file.
class Scp2Parser(object):
@@ -66,27 +105,9 @@ class Scp2Parser(object):
self.nodedata = {}
def tokenize (self):
- self.tokens = []
- i = 0
- n = len(self.content)
- token = ''
- while i < n:
- c = self.content[i]
- if c in '\t\n':
- c = ' '
-
- if c in ' ;':
- if len(token) > 0:
- if token[0] == '"' and token[-1] == '"':
- # remove quotes.
- token = token[1:-1]
- self.tokens.append(token)
- token = ''
- if c == ';':
- self.tokens.append(c)
- else:
- token += c
- i += 1
+ tokenizer = Scp2Tokenizer(self.content)
+ tokenizer.run()
+ self.tokens = tokenizer.tokens
def parse (self):
if len(self.tokens) == 0:
More information about the ooo-build-commit
mailing list