summaryrefslogtreecommitdiff
path: root/database/prefab.py
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-07-07 11:51:32 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:47:25 +0200
commit01de0faa57b784f7f6badfb19b8b09c4a070c775 (patch)
tree5bac377026c96468b7450e435eaa786bf2ad360f /database/prefab.py
parent890cd3f7028bfccd77b0d04670f7bc07293ed383 (diff)
Rename mongodb to database
Diffstat (limited to 'database/prefab.py')
-rwxr-xr-xdatabase/prefab.py112
1 files changed, 112 insertions, 0 deletions
diff --git a/database/prefab.py b/database/prefab.py
new file mode 100755
index 00000000..124f45e3
--- /dev/null
+++ b/database/prefab.py
@@ -0,0 +1,112 @@
+#!/Users/jacobburley/thesis-src/opendc/mongodb/opendc_testing/bin/python3
+#Change shebang to /usr/bin/python3 before using with docker
+# encoding: utf-8
+"""
+prefab
+
+CLI frontend for viewing, modifying and creating prefabs in OpenDC.
+
+"""
+import sys
+import prefabs
+
+def usage():
+ print("Usage: prefab add <prefab>: imports a prefab from JSON")
+ print(" list: lists all (public) prefabs")
+ print(" export <prefab> [json|yaml]: exports the specified prefab to the specified filetype (with JSON used by default)")
+ print(" clone <prefab> [new prefab name]: clones the specified prefab, giving the new prefab a name if specified")
+ print(" remove <prefab>: removes the specified prefab from the database")
+
+def interactive(): #interactive CLI mode: recommended
+ print("OpenDC Prefab CLI")
+ running = True
+ while(exit):
+ print(">", end=" ")
+ try:
+ command = input()
+ command = command.split()
+ except EOFError as e:
+ print("exit")
+ print("bye!")
+ exit()
+ except KeyboardInterrupt as KI:
+ print("\nbye!")
+ exit()
+ if(len(command) >= 1):
+ if(command[0] == "exit"):
+ print("bye!")
+ exit()
+ elif(command[0] == "list"): # decrypt
+ prefabs.list()
+ elif(command[0] == "help"): # decrypt
+ usage()
+ elif(command[0] == "add"):
+ if(len(command) == 3):
+ prefabs.add(command[1], command[2])
+ else:
+ prefabs.add(command[1], None)
+ elif(command[0] == "clone"):
+ if(len(command) == 3):
+ prefabs.clone(command[1], command[2])
+ else:
+ prefabs.clone(command[1], None)
+ elif(command[0] == "export"):
+ #print(sys.argv[2])
+ prefabs.export(command[1], "json")
+ elif(command[0] == "remove"):
+ print("WARNING: Doing so will permanently remove the specified prefab. \nThis action CANNOT be undone. Please type the name of the prefab to confirm deletion.")
+ confirm = input()
+ if confirm == command[1]:
+ prefabs.remove(command[1])
+ print(f'Prefab {command[1]} has been removed.')
+ else:
+ print("Confirmation failed. The prefab has not been removed.")
+ else:
+ print("prefabs: try 'help' for more information\n")
+ else:
+ print("prefabs: try 'help' for more information\n")
+
+
+def main():
+ if(len(sys.argv) >= 2):
+ if(sys.argv[1] == "list"): # decrypt
+ prefabs.list()
+ exit()
+ #elif(sys.argv[1] == "-e"): # encrypt
+ # encrypt(sys.argv[2], sys.argv[3], sys.argv[4])
+ #elif(sys.argv[1] == "-v"): # verify
+ # verify(sys.argv[2], sys.argv[3], sys.argv[4])
+ elif(sys.argv[1] == "help"): # decrypt
+ usage()
+ exit()
+ elif(sys.argv[1] == "add"):
+ if(sys.argv[3]):
+ prefabs.add(sys.argv[2], sys.argv[3])
+ else:
+ prefabs.add(sys.argv[2])
+ exit()
+ elif(sys.argv[1] == "export"):
+ #print(sys.argv[2])
+ prefabs.export(sys.argv[2], "json")
+ exit()
+ elif(sys.argv[1] == "remove"):
+ print("WARNING: Doing so will permanently remove the specified prefab. \nThis action CANNOT be undone. Please type the name of the prefab to confirm deletion.")
+ confirm = input()
+ if confirm == sys.argv[2]:
+ prefabs.remove(sys.argv[2])
+ print(f'Prefab {sys.argv[2]} has been removed.')
+ else:
+ print("Confirmation failed. The prefab has not been removed.")
+ exit()
+ else:
+ print("prefabs: try 'prefabs help' for more information\n")
+ elif(len(sys.argv) == 1):
+ interactive()
+
+ else:
+ # print "Incorrect number of arguments!\n"
+ print("prefabs: try 'prefabs help' for more information\n")
+
+
+if __name__ == "__main__":
+ main() \ No newline at end of file