5 def print_error(*args):
7 args = [str(item) for item in args]
8 sys.stderr.write(" ".join(args) + "\n")
12 if "HOME" in os.environ:
13 return os.path.join(os.environ["HOME"], ".electrum")
14 elif "LOCALAPPDATA" in os.environ:
15 return os.path.join(os.environ["LOCALAPPDATA"], "Electrum")
16 elif "APPDATA" in os.environ:
17 return os.path.join(os.environ["APPDATA"], "Electrum")
19 raise BaseException("No home directory found in environment variables.")
22 """Find the path to the application data directory; add an electrum folder and return path."""
23 if platform.system() == "Windows":
24 return os.path.join(os.environ["APPDATA"], "Electrum")
25 elif platform.system() == "Linux":
26 return os.path.join(sys.prefix, "share", "electrum")
27 elif (platform.system() == "Darwin" or
28 platform.system() == "DragonFly"):
29 return "/Library/Application Support/Electrum"
31 raise Exception("Unknown system")
33 def get_resource_path(*args):
34 return os.path.join(".", *args)
37 """Return path to the data folder."""
39 prefix_path = os.path.dirname(sys.argv[0])
40 local_data = os.path.join(prefix_path, "data")
43 def load_theme_name(theme_path):
45 with open(os.path.join(theme_path, "name.cfg")) as name_cfg_file:
46 return name_cfg_file.read().rstrip("\n").strip()
50 def theme_dirs_from_prefix(prefix):
51 if not os.path.exists(prefix):
54 for potential_theme in os.listdir(prefix):
55 theme_full_path = os.path.join(prefix, potential_theme)
56 theme_css = os.path.join(theme_full_path, "style.css")
57 if not os.path.exists(theme_css):
59 theme_name = load_theme_name(theme_full_path)
60 if theme_name is None:
62 theme_paths[theme_name] = prefix, potential_theme
65 def load_theme_paths():
67 prefixes = (local_data_dir(), appdata_dir())
68 for prefix in prefixes:
69 theme_paths.update(theme_dirs_from_prefix(prefix))