Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''Get a list of locales used in the PostgreSQL installer, and test them with initdb.exe
- See: http://archives.postgresql.org/pgsql-bugs/2012-09/msg00083.php
- Mike Toews
- 13 Sept 2012
- '''
- import os
- import re
- import subprocess
- # Switch to a PostgreSQL installation directory
- #os.chdir(r'C:\Program Files\PostgreSQL\9.1')
- os.chdir(r'C:\Program Files\PostgreSQL\9.2')
- # Get locales supported on the system
- getlocales = subprocess.check_output(r'installer\server\getlocales.exe')
- inloc = re.findall(r'=(.+)\b', getlocales)
- print('Testing %i locales'%len(inloc))
- # Helper function
- def retinfo(loc):
- '''Return the used locale and default text search config'''
- try:
- subprocess.check_output([r'bin\initdb.exe',
- '--pgdata=NUL',
- '--encoding=UTF-8',
- '--locale=' + loc],
- stderr=subprocess.STDOUT)
- except subprocess.CalledProcessError as e:
- assert e.output
- locale_used = re.findall(r'with locale "?(.+)"?\b', e.output)[0]
- lang_used = re.findall(r'will be set to "?(.+)"?\b', e.output)[0]
- if bool(re.findall('invalid locale name', e.output)):
- valid = 'invalid'
- else:
- valid = 'valid'
- return locale_used, lang_used, valid
- ''' Make a tab-delimited output with eight columns:
- - Original locale string, currently used
- - Locale used from original
- - Language used from original
- - Was original valid
- - Modified locale string, where the first ", " is replaced with "_"
- - Locale used from modified
- - Language used from modified
- - Was modified valid
- '''
- for loc1 in inloc:
- res1 = retinfo(loc1)
- loc2 = loc1.replace(', ','_', 1)
- res2 = retinfo(loc2)
- print '\t'.join((loc1,) + res1 + (loc2,) + res2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement