28a3ffd8d9ff57b1c76a49238b84faa48c0d4bcb
[electrum-nvc.git] / lib / util.py
1 import os
2 import platform
3 import sys
4
5 def print_error(*args):
6     # Stringify args
7     args = [str(item) for item in args]
8     sys.stderr.write(" ".join(args) + "\n")
9     sys.stderr.flush()
10
11 def user_dir():
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")
18     else:
19       raise BaseException("No home directory found in environment variables.")
20
21 def appdata_dir():
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"
30     else:
31         raise Exception("Unknown system")
32
33 def get_resource_path(*args):
34     return os.path.join(".", *args)
35
36 def local_data_dir():
37     """Return path to the data folder."""
38     assert sys.argv
39     prefix_path = os.path.dirname(sys.argv[0])
40     local_data = os.path.join(prefix_path, "data")
41     return local_data
42