2008-10-22 20:20:29 +02:00
|
|
|
#!/usr/bin/env python
|
2009-06-26 11:38:36 +02:00
|
|
|
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
|
|
|
#this repository contains the full copyright notices and license terms.
|
2008-10-22 20:20:29 +02:00
|
|
|
|
2012-08-21 11:05:37 +02:00
|
|
|
import sys
|
2008-10-22 20:20:29 +02:00
|
|
|
import pycountry
|
|
|
|
|
|
2013-09-02 17:38:55 +02:00
|
|
|
sys.stdout.write(u' <data skiptest="1" grouped="1">\n')
|
2008-10-22 20:20:29 +02:00
|
|
|
for country in pycountry.countries:
|
2012-08-21 11:05:37 +02:00
|
|
|
record = u'''
|
2008-10-22 20:20:29 +02:00
|
|
|
<record model="country.country" id="%s">
|
|
|
|
|
<field name="name">%s</field>
|
|
|
|
|
<field name="code">%s</field>
|
2012-08-21 11:05:37 +02:00
|
|
|
</record>\n''' % (country.alpha2.lower(), country.name,
|
2008-10-22 20:20:29 +02:00
|
|
|
country.alpha2)
|
2012-08-21 11:05:37 +02:00
|
|
|
sys.stdout.write(record.encode('utf-8'))
|
2013-09-02 17:38:55 +02:00
|
|
|
sys.stdout.write(u' </data>\n')
|
2008-10-22 20:20:29 +02:00
|
|
|
|
2013-09-02 17:38:55 +02:00
|
|
|
existing_parents = set()
|
|
|
|
|
while len(existing_parents) != len(pycountry.subdivisions):
|
|
|
|
|
sys.stdout.write(u' <data skiptest="1" grouped="1">\n')
|
|
|
|
|
new_parents = set()
|
|
|
|
|
for subdivision in pycountry.subdivisions:
|
|
|
|
|
if (subdivision.code.lower() in existing_parents
|
|
|
|
|
or (subdivision.parent_code
|
|
|
|
|
and subdivision.parent_code.lower() not in
|
|
|
|
|
existing_parents)):
|
|
|
|
|
continue
|
|
|
|
|
new_parents.add(subdivision.code.lower())
|
|
|
|
|
#XXX fix for second level of regional divisions
|
|
|
|
|
subdivision.country_code = subdivision.country_code.split(' ', 1)[0]
|
|
|
|
|
record = u'''
|
2008-10-22 20:20:29 +02:00
|
|
|
<record model="country.subdivision" id="%s">
|
|
|
|
|
<field name="name">%s</field>
|
|
|
|
|
<field name="code">%s</field>
|
2012-08-21 11:05:37 +02:00
|
|
|
<field name="type">%s</field>\n''' % (subdivision.code.lower(),
|
2013-09-02 17:38:55 +02:00
|
|
|
subdivision.name, subdivision.code,
|
|
|
|
|
subdivision.type.lower())
|
|
|
|
|
if subdivision.parent_code:
|
|
|
|
|
record += u'''\
|
2013-02-23 17:29:40 +01:00
|
|
|
<field name="parent" ref="%s"/>\n''' % \
|
2013-09-02 17:38:55 +02:00
|
|
|
subdivision.parent.code.lower()
|
|
|
|
|
record += u'''\
|
2008-10-22 20:20:29 +02:00
|
|
|
<field name="country" ref="%s"/>
|
2012-08-21 11:05:37 +02:00
|
|
|
</record>\n''' % subdivision.country.alpha2.lower()
|
|
|
|
|
|
2013-09-02 17:38:55 +02:00
|
|
|
sys.stdout.write(record.encode('utf-8'))
|
|
|
|
|
sys.stdout.write(u' </data>\n')
|
|
|
|
|
existing_parents |= new_parents
|