tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

__init__.py (996B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 import json
      6 import os
      7 
      8 HERE = os.path.dirname(__file__)
      9 
     10 
     11 def get_customizations():
     12    for f in os.listdir(HERE):
     13        if not f.endswith("json"):
     14            continue
     15        yield os.path.join(HERE, f)
     16 
     17 
     18 def find_customization(path_or_name):
     19    if not path_or_name.endswith(".json"):
     20        path_or_name += ".json"
     21    if not os.path.exists(path_or_name):
     22        # trying relative
     23        rpath = os.path.join(HERE, path_or_name)
     24        if not os.path.exists(rpath):
     25            return None
     26        path_or_name = rpath
     27    return path_or_name
     28 
     29 
     30 def get_customization(path_or_name):
     31    path = find_customization(path_or_name)
     32    if path is None:
     33        raise OSError("Can't find the customization file %r" % path_or_name)
     34    with open(path) as f:
     35        return json.loads(f.read())