addon-sdk/source/python-lib/cuddlefish/options_defaults.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/python-lib/cuddlefish/options_defaults.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,26 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +def parse_options_defaults(options, preferencesBranch):
     1.9 +    # this returns a unicode string
    1.10 +    pref_list = []
    1.11 +
    1.12 +    for pref in options:
    1.13 +        if ('value' in pref):
    1.14 +            value = pref["value"]
    1.15 +
    1.16 +            if isinstance(value, float):
    1.17 +                continue
    1.18 +            elif isinstance(value, bool):
    1.19 +                value = str(pref["value"]).lower()
    1.20 +            elif isinstance(value, str): # presumably ASCII
    1.21 +                value = "\"" + unicode(pref["value"]) + "\""
    1.22 +            elif isinstance(value, unicode):
    1.23 +                value = "\"" + pref["value"] + "\""
    1.24 +            else:
    1.25 +                value = str(pref["value"])
    1.26 +
    1.27 +            pref_list.append("pref(\"extensions." + preferencesBranch + "." + pref["name"] + "\", " + value + ");")
    1.28 +
    1.29 +    return "\n".join(pref_list) + "\n"

mercurial