Package src :: Package inspectors :: Module ooo_meta_inspector
[hide private]
[frames] | no frames]

Source Code for Module src.inspectors.ooo_meta_inspector

  1  #!/usr/bin/python 
  2  # -*- coding: UTF-8 -*- 
  3  # 
  4  #The MIT License 
  5  # 
  6  #Copyright (c) 2011 
  7  # 
  8  #Permission is hereby granted, free of charge, to any person obtaining a copy 
  9  #of this software and associated documentation files (the "Software"), to deal 
 10  #in the Software without restriction, including without limitation the rights 
 11  #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 12  #copies of the Software, and to permit persons to whom the Software is 
 13  #furnished to do so, subject to the following conditions: 
 14  # 
 15  #The above copyright notice and this permission notice shall be included in 
 16  #all copies or substantial portions of the Software. 
 17  # 
 18  #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 19  #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 20  #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 21  #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 22  #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 23  #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
 24  #THE SOFTWARE. 
 25  # 
 26  #Authors: 
 27  #   Vili Auvinen (vili.k.auvinen@jyu.fi) 
 28  #   Olli Kauppinen (olli.kauppinen@jyu.fi) 
 29  #   Juho Tammela (juho.i.tammela@jyu.fi) 
 30   
 31  ''' 
 32  The module provides the methods for getting OpenOffice.org file formats' odt, odp, and ods meta informations. 
 33   
 34  @author: Olli Kauppinen 
 35  ''' 
 36   
 37  import sys 
 38  import zipfile 
 39  import xml.dom.minidom 
 40  import fnmatch 
 41     
 42          
43 -def getMetaInformation(documentDict,elementTagName):
44 '''Gets the meta information by the given elementTagName from odt,odp and ods documents. 45 46 @return: The meta information. 47 ''' 48 element=documentDict['meta.xml'].getElementsByTagName(elementTagName) 49 if element: 50 return element[0].firstChild.nodeValue 51 else: 52 return 'not defined'
53
54 -def getDocumentStatistic(documentDict,attributeName):
55 '''Gets the document statistic by the given attributeName. 56 57 @return: The statistic value. 58 ''' 59 element=documentDict['meta.xml'].getElementsByTagName('meta:document-statistic') 60 if element: 61 return element[0].getAttribute (attributeName) 62 else: 63 return 'Statistic not defined'
64 65
66 -def getMeta(documentDict):
67 '''Gets all the document meta information. 68 69 @return: The meta information in the dictionary. Tag names are the key values in the dictionary. 70 ''' 71 meta = {'dc:title': None, 72 'meta:creation-date': None, 73 'meta:initial-creator': None, 74 'meta:editing-duration': None, 75 'dc:date': None, 76 'dc:creator': None, 77 'meta:editing-cycles': None} 78 79 for metaName in meta.keys(): 80 meta[metaName] = getMetaInformation(documentDict,metaName) 81 82 return meta
83 84
85 -def getOdtStatistic (documentDict):
86 '''Gets all the odt document statistic information. 87 88 @return: The statistic information in the dictionary. Attribute names are the key values in the dictionary. 89 ''' 90 odtStatistic = {'meta:table-count': None, 91 'meta:image-count': None, 92 'meta:object-count': None, 93 'meta:page-count': None, 94 'meta:paragraph-count': None, 95 'meta:paragraph-count': None, 96 'meta:word-count': None, 97 'meta:character-count': None} 98 99 for odtStatisticName in odtStatistic.keys(): 100 odtStatistic[odtStatisticName] = getDocumentStatistic(documentDict,odtStatisticName) 101 102 return odtStatistic
103
104 -def getOdsStatistic (documentDict):
105 '''Gets all the ods document statistic information. 106 107 @return: The statistic information in the dictionary. Attribute names are the key values in the dictionary. 108 ''' 109 odsStatistic = {'meta:table-count': None, 110 'meta:cell-count': None, 111 'meta:object-count': None} 112 113 for odsStatisticName in odtStatistic.keys(): 114 odsStatistic[odtStatisticName] = getDocumentStatistic(documentDict,odtStatisticName) 115 116 return odsStatistic
117
118 -def printOdpStatistic ():
119 '''Get all the odp document statistic information. 120 121 @return: The statistic information in the dictionary. Attribute names are the key values in the dictionary. 122 ''' 123 odpStatistic = {'meta:object-count': None} 124 odpStatistic['meta:object-count'] = getDocumentStatistic(documentDict,odtStatisticName) 125 return odpStatistic
126