Advertisement
mwtoews

test_pgsql_locale_windows.py

Sep 12th, 2012
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. '''Get a list of locales used in the PostgreSQL installer, and test them with initdb.exe
  2.  
  3. See: http://archives.postgresql.org/pgsql-bugs/2012-09/msg00083.php
  4.  
  5. Mike Toews
  6. 13 Sept 2012
  7. '''
  8.  
  9. import os
  10. import re
  11. import subprocess
  12.  
  13. # Switch to a PostgreSQL installation directory
  14. #os.chdir(r'C:\Program Files\PostgreSQL\9.1')
  15. os.chdir(r'C:\Program Files\PostgreSQL\9.2')
  16.  
  17. # Get locales supported on the system
  18. getlocales = subprocess.check_output(r'installer\server\getlocales.exe')
  19. inloc = re.findall(r'=(.+)\b', getlocales)
  20.  
  21. print('Testing %i locales'%len(inloc))
  22.  
  23. # Helper function
  24. def retinfo(loc):
  25.     '''Return the used locale and default text search config'''
  26.     try:
  27.         subprocess.check_output([r'bin\initdb.exe',
  28.                                  '--pgdata=NUL',
  29.                                  '--encoding=UTF-8',
  30.                                  '--locale=' + loc],
  31.                                 stderr=subprocess.STDOUT)
  32.     except subprocess.CalledProcessError as e:
  33.         assert e.output
  34.     locale_used = re.findall(r'with locale "?(.+)"?\b', e.output)[0]
  35.     lang_used = re.findall(r'will be set to "?(.+)"?\b', e.output)[0]
  36.     if bool(re.findall('invalid locale name', e.output)):
  37.         valid = 'invalid'
  38.     else:
  39.         valid = 'valid'
  40.     return locale_used, lang_used, valid
  41.  
  42. ''' Make a tab-delimited output with eight columns:
  43. - Original locale string, currently used
  44.     - Locale used from original
  45.     - Language used from original
  46.     - Was original valid
  47. - Modified locale string, where the first ", " is replaced with "_"
  48.     - Locale used from modified
  49.     - Language used from modified
  50.     - Was modified valid
  51. '''
  52. for loc1 in inloc:
  53.     res1 = retinfo(loc1)
  54.     loc2 = loc1.replace(', ','_', 1)
  55.     res2 = retinfo(loc2)
  56.     print '\t'.join((loc1,) + res1 + (loc2,) + res2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement