Commit 0ec8555a authored by Kevin Deldycke's avatar Kevin Deldycke

Change method names to fit in ERP5 naming conventions;

Close the file correctly;
Better permission on openFile method;
Call of __init__ was useless.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2980 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 784456c1
...@@ -65,7 +65,7 @@ class OOoParser: ...@@ -65,7 +65,7 @@ class OOoParser:
self.ns = {} self.ns = {}
security.declarePublic('openFile') security.declareProtected('Import/Export objects', 'openFile')
def openFile(self, file_descriptor): def openFile(self, file_descriptor):
""" """
Load all files in the zipped OpenOffice document Load all files in the zipped OpenOffice document
...@@ -79,12 +79,10 @@ class OOoParser: ...@@ -79,12 +79,10 @@ class OOoParser:
if oo_unzipped.testzip() != None: if oo_unzipped.testzip() != None:
raise CorruptedOOoFile raise CorruptedOOoFile
# Initialize internal variables
self.__init__()
# List and load the content of the zip file # List and load the content of the zip file
for name in oo_unzipped.namelist(): for name in oo_unzipped.namelist():
self.oo_files[name] = oo_unzipped.read(name) self.oo_files[name] = oo_unzipped.read(name)
oo_unzipped.close()
# Get the main content and style definitions # Get the main content and style definitions
self.oo_content_dom = self.reader.fromString(self.oo_files["content.xml"]) self.oo_content_dom = self.reader.fromString(self.oo_files["content.xml"])
...@@ -99,8 +97,8 @@ class OOoParser: ...@@ -99,8 +97,8 @@ class OOoParser:
self.ns[name[6:]] = doc_ns[0].attributes.item(i).value self.ns[name[6:]] = doc_ns[0].attributes.item(i).value
security.declarePublic('getPictures') security.declarePublic('getPicturesMapping')
def getPictures(self): def getPicturesMapping(self):
""" """
Return a dictionnary of all pictures in the document Return a dictionnary of all pictures in the document
""" """
...@@ -113,41 +111,41 @@ class OOoParser: ...@@ -113,41 +111,41 @@ class OOoParser:
return self.pictures return self.pictures
security.declarePublic('getContentAsDom') security.declarePublic('getContentDom')
def getContentAsDom(self): def getContentDom(self):
""" """
Return the DOM tree of the main OpenOffice content Return the DOM tree of the main OpenOffice content
""" """
return self.oo_content_dom return self.oo_content_dom
security.declarePublic('getSpreadsheetsAsDom') security.declarePublic('getSpreadsheetsDom')
def getSpreadsheetsAsDom(self, include_embedded=False): def getSpreadsheetsDom(self, include_embedded=False):
""" """
Return a list of DOM tree spreadsheets (optionnaly included embedded ones) Return a list of DOM tree spreadsheets (optionnaly included embedded ones)
""" """
spreadsheets = [] spreadsheets = []
spreadsheets = self.getPlainSpreadsheetsAsDom() spreadsheets = self.getPlainSpreadsheetsDom()
if include_embedded == True: if include_embedded == True:
spreadsheets += self.getEmbeddedSpreadsheetsAsDom() spreadsheets += self.getEmbeddedSpreadsheetsDom()
return spreadsheets return spreadsheets
security.declarePublic('getSpreadsheetsAsTable') security.declarePublic('getSpreadsheetsMapping')
def getSpreadsheetsAsTable(self, include_embedded=False, no_empty_lines=False): def getSpreadsheetsMapping(self, include_embedded=False, no_empty_lines=False):
""" """
Return a list of table-like spreadsheets (optionnaly included embedded ones) Return a list of table-like spreadsheets (optionnaly included embedded ones)
""" """
tables = {} tables = {}
tables = self.getPlainSpreadsheetsAsTable(no_empty_lines) tables = self.getPlainSpreadsheetsMapping(no_empty_lines)
if include_embedded == True: if include_embedded == True:
embedded_tables = self.getEmbeddedSpreadsheetsAsTable(no_empty_lines) embedded_tables = self.getEmbeddedSpreadsheetsMapping(no_empty_lines)
tables = self._getTableListUnion(tables, embedded_tables) tables = self._getTableListUnion(tables, embedded_tables)
return tables return tables
security.declarePublic('getPlainSpreadsheetsAsDom') security.declarePublic('getPlainSpreadsheetsDom')
def getPlainSpreadsheetsAsDom(self): def getPlainSpreadsheetsDom(self):
""" """
Retrieve every spreadsheets from the document and get they DOM tree Retrieve every spreadsheets from the document and get they DOM tree
""" """
...@@ -158,21 +156,21 @@ class OOoParser: ...@@ -158,21 +156,21 @@ class OOoParser:
return spreadsheets return spreadsheets
security.declarePublic('getPlainSpreadsheetsAsTable') security.declarePublic('getPlainSpreadsheetsMapping')
def getPlainSpreadsheetsAsTable(self, no_empty_lines=False): def getPlainSpreadsheetsMapping(self, no_empty_lines=False):
""" """
Return a list of plain spreadsheets from the document and transform them as table Return a list of plain spreadsheets from the document and transform them as table
""" """
tables = {} tables = {}
for spreadsheet in self.getPlainSpreadsheetsAsDom(): for spreadsheet in self.getPlainSpreadsheetsDom():
new_table = self.getSpreadsheetAsTable(spreadsheet, no_empty_lines) new_table = self.getSpreadsheetMapping(spreadsheet, no_empty_lines)
if new_table != None: if new_table != None:
tables = self._getTableListUnion(tables, new_table) tables = self._getTableListUnion(tables, new_table)
return tables return tables
security.declarePublic('getEmbeddedSpreadsheetsAsDom') security.declarePublic('getEmbeddedSpreadsheetsDom')
def getEmbeddedSpreadsheetsAsDom(self): def getEmbeddedSpreadsheetsDom(self):
""" """
Return a list of existing embedded spreadsheets in the file as DOM tree Return a list of existing embedded spreadsheets in the file as DOM tree
""" """
...@@ -191,21 +189,21 @@ class OOoParser: ...@@ -191,21 +189,21 @@ class OOoParser:
return spreadsheets return spreadsheets
security.declarePublic('getEmbeddedSpreadsheetsAsTable') security.declarePublic('getEmbeddedSpreadsheetsMapping')
def getEmbeddedSpreadsheetsAsTable(self, no_empty_lines=False): def getEmbeddedSpreadsheetsMapping(self, no_empty_lines=False):
""" """
Return a list of embedded spreadsheets in the document as table Return a list of embedded spreadsheets in the document as table
""" """
tables = {} tables = {}
for spreadsheet in self.getEmbeddedSpreadsheetsAsDom(): for spreadsheet in self.getEmbeddedSpreadsheetsDom():
new_table = self.getSpreadsheetAsTable(spreadsheet, no_empty_lines) new_table = self.getSpreadsheetMapping(spreadsheet, no_empty_lines)
if new_table != None: if new_table != None:
tables = self._getTableListUnion(tables, new_table) tables = self._getTableListUnion(tables, new_table)
return tables return tables
security.declarePublic('getSpreadsheetAsTable') security.declarePublic('getSpreadsheetMapping')
def getSpreadsheetAsTable(self, spreadsheet=None, no_empty_lines=False): def getSpreadsheetMapping(self, spreadsheet=None, no_empty_lines=False):
""" """
This method convert an OpenOffice spreadsheet to a simple table. This method convert an OpenOffice spreadsheet to a simple table.
This code is based on the oo2pt tool (http://cvs.sourceforge.net/viewcvs.py/collective/CMFReportTool/oo2pt). This code is based on the oo2pt tool (http://cvs.sourceforge.net/viewcvs.py/collective/CMFReportTool/oo2pt).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment