import/export cli. v0.0.2
This commit is contained in:
parent
52650a49d1
commit
855cbcc4ab
|
@ -28,8 +28,6 @@ RUN pip3 install -U pip && \
|
||||||
python3 setup.py install && \
|
python3 setup.py install && \
|
||||||
useradd --uid 1000 app
|
useradd --uid 1000 app
|
||||||
|
|
||||||
VOLUME /data/
|
|
||||||
|
|
||||||
ADD start /start
|
ADD start /start
|
||||||
|
|
||||||
ENTRYPOINT ["/start"]
|
ENTRYPOINT ["/start"]
|
||||||
|
|
|
@ -8,6 +8,9 @@ import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
APPNAME = "npcli"
|
APPNAME = "npcli"
|
||||||
CONFDIR = user_config_dir(APPNAME)
|
CONFDIR = user_config_dir(APPNAME)
|
||||||
CONFPATH = os.path.join(CONFDIR, "conf.json")
|
CONFPATH = os.path.join(CONFDIR, "conf.json")
|
||||||
|
@ -74,6 +77,9 @@ def main():
|
||||||
|
|
||||||
spr_dump = spr_action.add_parser("dump", help="dump the database")
|
spr_dump = spr_action.add_parser("dump", help="dump the database")
|
||||||
|
|
||||||
|
spr_import = spr_action.add_parser("import", help="import a database dump")
|
||||||
|
spr_import.add_argument("fname", help="db dump yaml file to import")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
r = requests.session()
|
r = requests.session()
|
||||||
|
|
||||||
|
@ -131,6 +137,21 @@ def main():
|
||||||
|
|
||||||
print(yaml.dump(dump, default_flow_style=False))
|
print(yaml.dump(dump, default_flow_style=False))
|
||||||
|
|
||||||
|
elif args.action == "import":
|
||||||
|
with open(args.fname) as f:
|
||||||
|
dump = yaml.load(f)
|
||||||
|
|
||||||
|
for clsname in dump["classes"]:
|
||||||
|
r.put(args.host.rstrip("/") + "/api/class/" + clsname).raise_for_status()
|
||||||
|
|
||||||
|
# just make the nodes first
|
||||||
|
for nodename, nodebody in dump["nodes"].items():
|
||||||
|
putnode(nodename, yaml.dump({"body": {}, "classes": {}, "parents": []})).raise_for_status()
|
||||||
|
|
||||||
|
# then fill out node bodies to avoid missing parent ordering issues
|
||||||
|
for nodename, nodebody in dump["nodes"].items():
|
||||||
|
putnode(nodename, yaml.dump(nodebody)).raise_for_status()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -206,7 +206,8 @@ class ClassesApi(object):
|
||||||
|
|
||||||
def PUT(self, cls):
|
def PUT(self, cls):
|
||||||
with self.nodes.db.transaction() as c:
|
with self.nodes.db.transaction() as c:
|
||||||
c.root.classes[cls] = NClass(cls)
|
if cls not in c.root.classes:
|
||||||
|
c.root.classes[cls] = NClass(cls)
|
||||||
|
|
||||||
def DELETE(self, cls):
|
def DELETE(self, cls):
|
||||||
with self.nodes.db.transaction() as c:
|
with self.nodes.db.transaction() as c:
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -4,7 +4,7 @@ from setuptools import setup
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
__version__ = "0.0.1"
|
__version__ = "0.0.2"
|
||||||
with open(os.path.join(os.path.dirname(__file__), "requirements.txt")) as f:
|
with open(os.path.join(os.path.dirname(__file__), "requirements.txt")) as f:
|
||||||
__requirements__ = [line.strip() for line in f.readlines()]
|
__requirements__ = [line.strip() for line in f.readlines()]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue