mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-04-21 03:02:09 +00:00
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
import sys
|
|
import rtyaml
|
|
import collections
|
|
import os.path
|
|
|
|
def load_environment():
|
|
# Load settings from a KEY=VALUE file.
|
|
import collections
|
|
env = collections.OrderedDict()
|
|
for line in open("/etc/mailinabox.conf"): env.setdefault(*line.strip().split("=", 1))
|
|
return env
|
|
|
|
def write_settings(config, env):
|
|
fn = os.path.join(env['STORAGE_ROOT'], 'settings.yaml')
|
|
with open(fn, "w") as f:
|
|
f.write(rtyaml.dump(config))
|
|
|
|
def load_settings(env):
|
|
fn = os.path.join(env['STORAGE_ROOT'], 'settings.yaml')
|
|
try:
|
|
config = rtyaml.load(open(fn, "r"))
|
|
if not isinstance(config, dict): raise ValueError() # caught below
|
|
return config
|
|
except:
|
|
return { }
|
|
|
|
env = load_environment()
|
|
|
|
if(sys.argv[2]):
|
|
|
|
if( sys.argv[1] == "check" ):
|
|
yaml = rtyaml.load(open( os.path.join(env['STORAGE_ROOT'], 'settings.yaml') ))
|
|
|
|
if( yaml.get("mailinabox-agreement", True) ):
|
|
print("true")
|
|
else:
|
|
print("false")
|
|
|
|
|
|
elif( sys.argv[1] == "set" ):
|
|
config = load_settings(env)
|
|
|
|
config["mailinabox-agreement"] = True
|
|
write_settings( config, env )
|
|
print("true") |