Browse Source

Switch to using iso_3166.xml rather than the deprecated iso_3166.tab, by the

crude method of copying iso3166tab.py from the iso-codes source to convert
it to the old .tab format for us on the fly.

r28156
tags/1.12
Colin Watson 16 years ago
parent
commit
e74dc630bf
7 changed files with 80 additions and 14 deletions
  1. +1
    -2
      README
  2. +9
    -0
      debian/changelog
  3. +1
    -1
      debian/control
  4. +4
    -3
      get-iso-codes
  5. +56
    -0
      iso3166tab.py
  6. +4
    -3
      map-cc
  7. +5
    -5
      mktemplates

+ 1
- 2
README View File

@@ -27,8 +27,7 @@ The system for building the country list
Mirrors.masterlist (this file is fetched at build time if possible).

Then, the codes list is transformed into a country name list (in English)
by using the iso_3166.tab file from the iso-codes package.
THIS FILE IS DEPRECATED-->TODO, use the iso_3166.xml file
by using the iso_3166.xml file from the iso-codes package.

This list is transformed into a comma-separated list (NOTE : country "names"
may contain commas which need to be escaped) and inserted into the Choices


+ 9
- 0
debian/changelog View File

@@ -1,3 +1,12 @@
choose-mirror (1.12) UNRELEASED; urgency=low

* Colin Watson
- Switch to using iso_3166.xml rather than the deprecated iso_3166.tab,
by the crude method of copying iso3166tab.py from the iso-codes source
to convert it to the old .tab format for us on the fly.

-- Colin Watson <cjwatson@debian.org> Fri, 3 Jun 2005 12:10:54 +0100

choose-mirror (1.11) unstable; urgency=low

* Colin Watson


+ 1
- 1
debian/control View File

@@ -3,7 +3,7 @@ Section: debian-installer
Priority: extra
Maintainer: Debian Install System Team <debian-boot@lists.debian.org>
Uploaders: Joey Hess <joeyh@debian.org>, Martin Sjogren <sjogren@debian.org>, Matt Kraai <kraai@debian.org>, Christian Perrier <bubulle@debian.org>, Colin Watson <cjwatson@debian.org>
Build-Depends: debhelper (>= 4.2), dpkg-dev (>= 1.7.0), libdebconfclient0-dev (>= 0.47), wget, po-debconf (>= 0.5.0), libdebian-installer-dev, locales, iso-codes
Build-Depends: debhelper (>= 4.2), dpkg-dev (>= 1.7.0), libdebconfclient0-dev (>= 0.47), wget, po-debconf (>= 0.5.0), libdebian-installer-dev, locales, iso-codes, python, python-xml

Package: choose-mirror
XC-Package-Type: udeb


+ 4
- 3
get-iso-codes View File

@@ -5,7 +5,7 @@ set -e
#
# Get ISO codes from the iso-codes package and extract translations
set -e
[ -r /usr/share/iso-codes/iso_3166.tab ] || exit 1
[ -r /usr/share/xml/iso-codes/iso_3166.xml ] || exit 1
rm -rf debian/iso-codes >/dev/null 2>&1
mkdir debian/iso-codes
for i in `find /usr/share/locale/ -name iso_3166.mo` ; do
@@ -27,5 +27,6 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\\n"

EOF
perl -pe 's/.*?\t(.*)/msgid "$1"\nmsgstr "$1"\n/' \
</usr/share/iso-codes/iso_3166.tab >>debian/iso-codes/en.po
./iso3166tab.py /usr/share/xml/iso-codes/iso_3166.xml \
| perl -pe 's/.*?\t(.*)/msgid "$1"\nmsgstr "$1"\n/' \
>>debian/iso-codes/en.po

+ 56
- 0
iso3166tab.py View File

@@ -0,0 +1,56 @@
#!/usr/bin/python
#
# Read iso-codes data file and output a .tab file
#
# Copyright (C) 2004 Alastair McKinstry <mckinstry@debian.org>
# Released under the GPL.
# $Id: iso3166tab.py,v 1.2 2005/01/08 18:06:46 mckinstry Exp $

from xml.sax import saxutils, make_parser, saxlib, saxexts, ContentHandler
from xml.sax.handler import feature_namespaces
import sys, os, getopt, urllib2

class printLines(saxutils.DefaultHandler):
def __init__(self, ofile):
self.ofile = ofile

def startElement(self, name, attrs):
if name != 'iso_3166_entry':
return
code = attrs.get('alpha_2_code', None)
if code == None:
raise RunTimeError, "Bad file"
if type(code) == unicode:
code = code.encode('UTF-8')
name = attrs.get('name', None)
if name == None:
raise RunTimeError, " BadFile"
if type(name) == unicode:
name = name.encode('UTF-8')
common_name = attrs.get('common_name', None)
if common_name != None:
if type(common_name) == unicode:
name = common_name.encode('UTF-8')
else:
name = common_name
self.ofile.write (code + '\t' + name + '\n')


##
## MAIN
##


ofile = sys.stdout
p = make_parser()
p.setErrorHandler(saxutils.ErrorPrinter())
try:
dh = printLines(ofile)
p.setContentHandler(dh)
p.parse(sys.argv[1])
except IOError,e:
print in_sysID+": "+str(e)
except saxlib.SAXException,e:
print str(e)

ofile.close()

+ 4
- 3
map-cc View File

@@ -1,12 +1,13 @@
#! /usr/bin/perl -w
use strict;

my $iso3166tab = shift;
my $iso3166xml = shift;

# Get mapping of country names to country codes (i.e. reverse of
# iso_3166.tab).
# iso3166tab.py output).
my %iso3166rev;
open ISO3166TAB, '<:utf8', "$iso3166tab" or die "open $iso3166tab: $!";
open ISO3166TAB, '-|:utf8', './iso3166tab.py', "$iso3166xml"
or die "open iso3166tab.py $iso3166xml: $!";
while (<ISO3166TAB>) {
/^([A-Z]+)\t(.*)$/ or next;
$iso3166rev{$2} = $1;


+ 5
- 5
mktemplates View File

@@ -7,12 +7,12 @@ set -e
# iso-codes package
#
# Some variables
ISO3166TAB=/usr/share/iso-codes/iso_3166.tab
export ISO3166TAB
ISO3166XML=/usr/share/xml/iso-codes/iso_3166.xml
export ISO3166XML
# Translations location (relative to the build root directory)
ISO3166TRANSLATIONS=debian/iso-codes

# Get the ordered list of countries from the iso_3166.tab, sorted
# Get the ordered list of countries from the iso_3166.xml, sorted
# according to the regionmap.
#
# We need to escape commas by preceding them with a backslash.
@@ -72,7 +72,7 @@ for pofile in debian/po/*.po ; do
msgconv -t UTF-8 debian/po/$pofilename \
> debian/pobuild/$pofilename.other
msgconv -t UTF-8 "$ISO3166TRANSLATIONS/$pofilename" \
| ./map-cc "$ISO3166TAB" \
| ./map-cc "$ISO3166XML" \
> debian/pobuild/$pofilename.iso-codes
# Update other template translations with templates.pot
msgmerge -U debian/pobuild/$pofilename.other \
@@ -93,7 +93,7 @@ done

if [ ! -f debian/po/en.po ]; then
printf " en..."
./map-cc "$ISO3166TAB" < "$ISO3166TRANSLATIONS/en.po" > debian/pobuild/en.po
./map-cc "$ISO3166XML" < "$ISO3166TRANSLATIONS/en.po" > debian/pobuild/en.po
msgmerge -U debian/pobuild/en.po debian/pobuild/templates.pot 2>/dev/null
printf "Done.\n"
fi


Loading…
Cancel
Save