eggification
[iso_3166_1.git] / _sources / make.py
diff --git a/_sources/make.py b/_sources/make.py
deleted file mode 100755 (executable)
index d05c711..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-####################################################
-# Copyright © 2009 Luxia SAS. All rights reserved. #
-#                                                  #
-# Contributors:                                    #
-#  - Benoît Pin <pinbe@luxia.fr>                   #
-####################################################
-""" generates python, po and mo files from xml sources.
-
-
-
-"""
-
-
-import os
-from xml.dom.minidom import parse
-from os.path import exists, sep
-from os import mkdir
-from subprocess import Popen
-
-POHEADER ="""msgid ""
-msgstr ""
-"Project-Id-Version: ISO-3166_1\\n"
-"MIME-Version: 1.0\\n"
-"Content-Type: text/plain; charset=%(charset)s\\n"
-"Content-Transfer-Encoding: 8bit\\n"
-"Language-Code: %(lang)s\\n"
-"Preferred-Encodings: %(charset)s latin1\\n"
-"Domain: iso_3166_1\\n"
-
-"""
-
-def main():
-       xmlFileNames = [name for name in os.listdir('.') if not name.startswith('.') and name.endswith('.xml')]
-               
-       for name in xmlFileNames:
-               lang = os.path.splitext(name)[0].split('_')[-1]
-               entries = getEntries(name)
-               makePy(lang, entries)
-               makePo(lang, entries)
-               
-               
-       
-
-def getEntries(name):
-       d = parse(name)
-       countries = []
-       for entry in d.documentElement.getElementsByTagName('ISO_3166-1_Entry') :
-               code = entry.getElementsByTagName('ISO_3166-1_Alpha-2_code')[0].firstChild.nodeValue
-               value = entry.getElementsByTagName('ISO_3166-1_Country_name')[0].firstChild.nodeValue
-               countries.append((code, value))
-       
-       return countries
-
-def makePy(lang, entries, encoding='utf-8'):
-       out = open('../%s.py' % lang, 'w')
-       out.write('# -*- coding: %s -*-\n\n' % encoding)
-       out.write('__allow_access_to_unprotected_subobjects__ = 1\n\n')
-       out.write('countries = (\n')
-
-       for e in entries :
-               encodedEntry = tuple(map(lambda s : s.encode(encoding), e))
-               out.write('''   ('%s', "%s"),\n''' % encodedEntry)
-
-       out.write('     )')
-       out.close()
-
-def makePo(lang, entries, encoding='utf-8'):
-       path = ('..', 'locales', lang, 'LC_MESSAGES')
-       poFilepath = ''
-       for p in path :
-               poFilepath = poFilepath + p + sep
-               if not exists(poFilepath) :
-                       mkdir(poFilepath)
-       
-       poFilepath = poFilepath + 'iso_3166_1.po'
-       out = open(poFilepath, 'w')
-       
-       header = POHEADER % {'charset':encoding, 'lang':lang}
-       out.write(header)
-       
-       for e in entries :
-               id, msg = tuple(map(lambda s : s.encode(encoding), e))
-               out.write('msgid "%s"\n' % id)
-               out.write('msgstr "%s"\n\n' % msg)
-       out.close()
-       
-       moFilepath = poFilepath[:-3] + '.mo'
-       MSGFMT = "msgfmt -o %s %s" % (moFilepath, poFilepath)
-       p = Popen(MSGFMT, shell=True)
-       p.wait()        
-       
-               
-
-if __name__ == '__main__' :
-       main()