Back to index

enigmail  1.4.3
Functions | Variables
preprocess-locale Namespace Reference

Functions

def open_utf16le_file
def get_locale_strings
def lookup
def preprocess_locale_files
def convert_utf8_utf16le

Variables

string usage
tuple p = OptionParser(usage=usage)
string dest = 'preprocess'
string help = "Add directory to lookup for locale files"
list pargs = args[:]
list l10n_dirs = [args[1]]

Function Documentation

def preprocess-locale.convert_utf8_utf16le (   in_file_path,
  out_file_path 
)
Converts a UTF-8 file to a new UTF-16LE file

Arguments:
in_file_path  - the path to the UTF-8 source file to convert
out_file_path - the path to the UTF-16LE destination file to create

Definition at line 145 of file preprocess-locale.py.

00145 
00146 def convert_utf8_utf16le(in_file_path, out_file_path):
00147     """
00148     Converts a UTF-8 file to a new UTF-16LE file
00149 
00150     Arguments:
00151     in_file_path  - the path to the UTF-8 source file to convert
00152     out_file_path - the path to the UTF-16LE destination file to create
00153     """
00154     in_fp = open(in_file_path, "r")
00155     out_fp = open_utf16le_file(out_file_path)
00156     out_fp.write(unicode(in_fp.read(), "utf-8").encode("utf-16-le"))
00157     in_fp.close()
00158     out_fp.close()

Here is the call graph for this function:

def preprocess-locale.get_locale_strings (   path,
  prefix,
  middle,
  add_cr 
)
Returns a string created by converting an installer locale properties file
into the format required by NSIS locale files.

Parameters:
path   - the path to the installer locale properties file to preprocess
prefix - a string to prefix each line with
middle - a string to insert between the name and value for each line
add_cr - boolean for whether to add an NSIS carriage return before NSIS
         linefeeds when there isn't one already

Definition at line 27 of file preprocess-locale.py.

00027 
00028 def get_locale_strings(path, prefix, middle, add_cr):
00029     """
00030     Returns a string created by converting an installer locale properties file
00031     into the format required by NSIS locale files.
00032 
00033     Parameters:
00034     path   - the path to the installer locale properties file to preprocess
00035     prefix - a string to prefix each line with
00036     middle - a string to insert between the name and value for each line
00037     add_cr - boolean for whether to add an NSIS carriage return before NSIS
00038              linefeeds when there isn't one already
00039     """
00040     output = ""
00041     fp = open(path, "r")
00042     for line in fp:
00043         line = line.strip()
00044         if line == "" or line[0] == "#":
00045             continue
00046 
00047         name, value = line.split("=", 1)
00048         value = value.strip() # trim whitespace from the start and end
00049         if value[-1] == "\"" and value[0] == "\"":
00050             value = value[1:-1] # remove " from the start and end
00051 
00052         if add_cr:
00053             value = value.replace("\\n", "\\r\\n") # prefix $\n with $\r
00054             value = value.replace("\\r\\r", "\\r") # replace $\r$\r with $\r
00055 
00056         value = value.replace("\"", "$\\\"") # prefix " with $\
00057         value = value.replace("\\r", "$\\r") # prefix \r with $
00058         value = value.replace("\\n", "$\\n") # prefix \n with $
00059         value = value.replace("\\t", "$\\t") # prefix \t with $
00060 
00061         output += prefix + name.strip() + middle + " \"" + value + "\"\n"
00062     fp.close()
00063     return output

Here is the caller graph for this function:

def preprocess-locale.lookup (   path,
  l10ndirs 
)

Definition at line 64 of file preprocess-locale.py.

00064 
00065 def lookup(path, l10ndirs):
00066     for d in l10ndirs:
00067         if isfile(join(d, path)):
00068             return join(d, path)
00069     return join(l10ndirs[-1], path)

Here is the caller graph for this function:

def preprocess-locale.open_utf16le_file (   path)
Returns an opened file object with a a UTF-16LE byte order mark.

Definition at line 19 of file preprocess-locale.py.

00019 
00020 def open_utf16le_file(path):
00021     """
00022     Returns an opened file object with a a UTF-16LE byte order mark.
00023     """
00024     fp = open(path, "w+b")
00025     fp.write(BOM_UTF16_LE)
00026     return fp

Here is the caller graph for this function:

def preprocess-locale.preprocess_locale_files (   moz_dir,
  ab_cd,
  config_dir,
  l10ndirs 
)
Preprocesses the installer localized properties files into the format
required by NSIS and creates a basic NSIS nlf file.

Parameters:
moz_dir    - the path to top source directory for the toolkit source
ab_cd      - the locale code
config_dir - the path to the destination directory
l10ndirs  - list of paths to search for installer locale files

Definition at line 70 of file preprocess-locale.py.

00070 
00071 def preprocess_locale_files(moz_dir, ab_cd, config_dir, l10ndirs):
00072     """
00073     Preprocesses the installer localized properties files into the format
00074     required by NSIS and creates a basic NSIS nlf file.
00075 
00076     Parameters:
00077     moz_dir    - the path to top source directory for the toolkit source
00078     ab_cd      - the locale code
00079     config_dir - the path to the destination directory
00080     l10ndirs  - list of paths to search for installer locale files
00081     """
00082 
00083     # Set the language ID to 0 to make this locale the default locale. An
00084     # actual ID will need to be used to create a multi-language installer
00085     # (e.g. for CD distributions, etc.).
00086     lang_id = "0"
00087     rtl = "-"
00088 
00089     # Check whether the locale is right to left from locales.nsi.
00090     fp = open(join(moz_dir, "toolkit/mozapps/installer/windows/nsis/locales.nsi"), "r")
00091     for line in fp:
00092         line = line.strip()
00093         if line == "!define " + ab_cd + "_rtl":
00094             rtl = "RTL"
00095             break
00096 
00097     fp.close()
00098 
00099     # Create the main NSIS language file with RTL for right to left locales
00100     # along with the default codepage, font name, and font size represented
00101     # by the '-' character.
00102     fp = open_utf16le_file(join(config_dir, "baseLocale.nlf"))
00103     fp.write((u"""# Header, don't edit
00104 NLF v6
00105 # Start editing here
00106 # Language ID
00107 %s
00108 # Font and size - dash (-) means default
00109 -
00110 -
00111 # Codepage - dash (-) means ANSI code page
00112 -
00113 # RTL - anything else than RTL means LTR
00114 %s
00115 """ % (lang_id, rtl)).encode("utf-16-le"))
00116     fp.close()
00117 
00118     # Create the main NSIS language file
00119     fp = open_utf16le_file(join(config_dir, "overrideLocale.nsh"))
00120     locale_strings = get_locale_strings(lookup("override.properties", l10ndirs),
00121                                         "LangString ^", " " + lang_id + " ", False)
00122     fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
00123     fp.close()
00124 
00125     # Create the Modern User Interface language file
00126     fp = open_utf16le_file(join(config_dir, "baseLocale.nsh"))
00127     fp.write((u""";NSIS Modern User Interface - Language File
00128 ;Compatible with Modern UI 1.68
00129 ;Language: baseLocale (%s)
00130 !insertmacro MOZ_MUI_LANGUAGEFILE_BEGIN \"baseLocale\"
00131 !define MUI_LANGNAME \"baseLocale\"
00132 """ % (lang_id)).encode("utf-16-le"))
00133     locale_strings = get_locale_strings(lookup("mui.properties", l10ndirs),
00134                                         "!define ", " ", True)
00135     fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
00136     fp.write(u"!insertmacro MOZ_MUI_LANGUAGEFILE_END\n".encode("utf-16-le"))
00137     fp.close()
00138 
00139     # Create the custom language file for our custom strings
00140     fp = open_utf16le_file(join(config_dir, "customLocale.nsh"))
00141     locale_strings = get_locale_strings(lookup("custom.properties", l10ndirs),
00142                         "LangString ", " " + lang_id + " ", True)
00143     fp.write(unicode(locale_strings, "utf-8").encode("utf-16-le"))
00144     fp.close()

Here is the call graph for this function:


Variable Documentation

string preprocess-locale.dest = 'preprocess'

Definition at line 186 of file preprocess-locale.py.

string preprocess-locale.help = "Add directory to lookup for locale files"

Definition at line 189 of file preprocess-locale.py.

preprocess-locale.l10n_dirs = [args[1]]

Definition at line 204 of file preprocess-locale.py.

tuple preprocess-locale.p = OptionParser(usage=usage)

Definition at line 184 of file preprocess-locale.py.

list preprocess-locale.pargs = args[:]

Definition at line 202 of file preprocess-locale.py.

string preprocess-locale.usage
Initial value:
00001 """usage: %prog command <args>
00002 
00003 Commands:
00004  --convert-utf8-utf16le - preprocesses installer locale properties files and
00005                           creates a basic NSIS nlf file
00006  --preprocess-locale    - Preprocesses the installer localized properties files
00007                           into the format required by NSIS and creates a basic
00008                           NSIS nlf file.
00009 
00010 preprocess-locale.py --preprocess-locale <src> <locale> <code> <dest>
00011 
00012 Arguments:
00013  <src>   \tthe path to top source directory for the toolkit source
00014  <locale>\tthe path to the installer's locale files
00015  <code>  \tthe locale code
00016  <dest>  \tthe path to the destination directory
00017 
00018 
00019 preprocess-locale.py --convert-utf8-utf16le <src> <dest>
00020 
00021 Arguments:
00022  <src> \tthe path to the UTF-8 source file to convert
00023  <dest>\tthe path to the UTF-16LE destination file to create
00024 """

Definition at line 160 of file preprocess-locale.py.