[Pkg-isocodes-devel] [SCM] ISO language, territory, currency, script codes and their translations branch, master, updated. 03570ff21c5b274fa394e207b5343689711250ca
Tobias Quathamer
toddy at debian.org
Sun Jun 24 11:51:07 UTC 2012
- Previous message: [Pkg-isocodes-devel] [SCM] ISO language, territory, currency, script codes and their translations branch, master, updated. 03570ff21c5b274fa394e207b5343689711250ca
- Next message: [Pkg-isocodes-devel] [SCM] ISO language, territory, currency, script codes and their translations branch, master, updated. cea8f9e002179794a43724c41b28d7cd306434e9
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
The following commit has been merged in the master branch:
commit 03570ff21c5b274fa394e207b5343689711250ca
Author: Tobias Quathamer <toddy at debian.org>
Date: Sat Jun 23 20:37:36 2012 +0200
Refactoring: Use a custom function for creating the XML entry
diff --git a/iso_639_3/iso-dis-639-tab-parse.py b/iso_639_3/iso-dis-639-tab-parse.py
index b216c66..be91ebf 100755
--- a/iso_639_3/iso-dis-639-tab-parse.py
+++ b/iso_639_3/iso-dis-639-tab-parse.py
@@ -35,6 +35,19 @@ names.close()
# Set up a dictionary for the one letter abbreviations
status_codes = {'A': 'Active', 'R': 'Retired'}
+def create_iso_639_3_entry(entry):
+ result = '\t<iso_639_3_entry\n'
+ result += '\t\tid="%s"\n' % entry['code']
+ result += '\t\tstatus="%s"\n' % entry['status']
+ if entry['iso_639_1'] != '':
+ result += '\t\tpart1_code="%s"\n' % entry['iso_639_1']
+ if entry['iso_639_2'] != '':
+ result += '\t\tpart2_code="%s"\n' % entry['iso_639_2']
+ result += '\t\tscope="%s"\n' % entry['element_scope']
+ result += '\t\ttype="%s"\n' % entry['language_type']
+ result += '\t\tname="%s" />\n' % entry['reference_name']
+ return result
+
tabular_file = open("iso_639_3.tab")
xml_file = open("iso_639_3.xml","w")
@@ -84,8 +97,8 @@ Source: <http://www.sil.org/iso639-3/>
# The first line only contains a header, so discard it
tabular_file.readline()
-# Set up a container for XML element 'iso_639_3_entry'
-iso_639_3_entry = ''
+# Set up a dictionary for XML element 'iso_639_3_entry'
+iso_639_3_entry = {}
for li in tabular_file.readlines():
# Split the line into parts and look for quotes
@@ -114,25 +127,24 @@ for li in tabular_file.readlines():
language_type = parts.pop()
documentation = parts.pop()
# Write the last entry, before starting a new one
- if iso_639_3_entry != '':
- xml_file.write(iso_639_3_entry)
- iso_639_3_entry = ''
+ if iso_639_3_entry.has_key('code'):
+ entry = create_iso_639_3_entry(iso_639_3_entry)
+ xml_file.write(entry)
+ iso_639_3_entry = {}
# Assemble the iso_639_3_entry
- iso_639_3_entry = '\t<iso_639_3_entry\n'
- iso_639_3_entry += '\t\tid="%s"\n' % code
- iso_639_3_entry += '\t\tstatus="%s"\n' % status_codes[status]
- if iso_639_1 != '':
- iso_639_3_entry += '\t\tpart1_code="%s"\n' % iso_639_1
- if iso_639_2 != '':
- iso_639_3_entry += '\t\tpart2_code="%s"\n' % iso_639_2
- iso_639_3_entry += '\t\tscope="%s"\n' % element_scope
- iso_639_3_entry += '\t\ttype="%s"\n' % language_type
+ iso_639_3_entry['code'] = code
+ iso_639_3_entry['status'] = status_codes[status]
+ iso_639_3_entry['iso_639_1'] = iso_639_1
+ iso_639_3_entry['iso_639_2'] = iso_639_2
+ iso_639_3_entry['element_scope'] = element_scope
+ iso_639_3_entry['language_type'] = language_type
if inverted_names.has_key(code):
reference_name = inverted_names[code]
- iso_639_3_entry += '\t\tname="%s" />\n' % reference_name
+ iso_639_3_entry['reference_name'] = reference_name
# Finally, write the last entry and close the XML file
-xml_file.write(iso_639_3_entry)
+entry = create_iso_639_3_entry(iso_639_3_entry)
+xml_file.write(entry)
xml_file.write('</iso_639_3_entries>\n')
xml_file.close()
--
ISO language, territory, currency, script codes and their translations
- Previous message: [Pkg-isocodes-devel] [SCM] ISO language, territory, currency, script codes and their translations branch, master, updated. 03570ff21c5b274fa394e207b5343689711250ca
- Next message: [Pkg-isocodes-devel] [SCM] ISO language, territory, currency, script codes and their translations branch, master, updated. cea8f9e002179794a43724c41b28d7cd306434e9
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Pkg-isocodes-devel
mailing list