Package fliesclient :: Module publican
[hide private]
[frames] | no frames]

Source Code for Module fliesclient.publican

 1  # vim:set et sts=4 sw=4:  
 2  #  
 3  # Flies Python Client 
 4  # 
 5  # Copyright (c) 2010 Jian Ni <jni@redhat.com> 
 6  # Copyright (c) 2010 Red Hat, Inc. 
 7  # 
 8  # This library is free software; you can redistribute it and/or 
 9  # modify it under the terms of the GNU Lesser General Public 
10  # License as published by the Free Software Foundation; either 
11  # version 2 of the License, or (at your option) any later version. 
12  # 
13  # This library is distributed in the hope that it will be useful, 
14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  # GNU Lesser General Public License for more details. 
17  # 
18  # You should have received a copy of the GNU Lesser General Public 
19  # License along with this program; if not, write to the 
20  # Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
21  # Boston, MA  02111-1307  USA 
22   
23  __all__ = ( 
24              "Publican", 
25            ) 
26   
27  import polib 
28  import hashlib 
29   
30 -class Publican:
31 - def __init__(self, filepath):
32 self.path = filepath
33
34 - def covert_txtflow(self):
35 """ 36 Convert the content of the po file to a list of text flow. 37 @return: the dictionary object of textflow 38 """ 39 po = polib.pofile(self.path) 40 textflows = [] 41 for entry in po: 42 m = hashlib.md5() 43 m.update(entry.msgid.encode('utf-8')) 44 textflowId = m.hexdigest() 45 textflow = {'id': textflowId, 'lang':'en', 'content':entry.msgid, 'extensions':[]} 46 textflows.append(textflow) 47 return textflows
48
49 - def load_po(self):
50 """ 51 Convert the po file to a pofile object in polib. 52 @return: pofile object 53 """ 54 return polib.pofile(self.path)
55