Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 39 lines (30 sloc) 807 Bytes
#!/usr/bin/python3
import os.path
import sys
import yaml
PKGNAME = "config-example"
MSG_FILE = os.path.join(os.environ["SNAP_APP_DATA_PATH"], "message")
def get_config():
config = {
"config": {
PKGNAME: {},
}
}
if not os.path.exists(MSG_FILE):
return config
with open(MSG_FILE) as fp:
msg = fp.read()
config["config"]["config-example"]["msg"] = msg
return config
def set_config():
config = yaml.load(sys.stdin)
if not config:
return
msg = config.get("config", {}).get(PKGNAME, {}).get("msg", "")
if msg:
with open(MSG_FILE, "w") as fp:
fp.write(msg)
if __name__ == "__main__":
set_config()
config = get_config()
yaml.dump(config, stream=sys.stdout, default_flow_style=False)