Browse Source

Added a "write file" model transformation

Yentl Van Tendeloo 7 years ago
parent
commit
ababc0f53d
2 changed files with 18 additions and 2 deletions
  1. 14 0
      kernel/rules/write_files.alc
  2. 4 2
      services/files/main.py

+ 14 - 0
kernel/rules/write_files.alc

@@ -0,0 +1,14 @@
+include "files.alh"
+include "primitives.alh"
+include "modelling.alh"
+include "object_operations.alh"
+
+Boolean function main(model : Element):
+	Element files
+	files = allInstances(model, "Files/File")
+
+	while (set_len(files) > 0):
+		file = set_pop(files)
+		write_file(read_attribute(model, file, "name"), read_attribute(model, file, "content"))
+
+	return True!

+ 4 - 2
services/files/main.py

@@ -13,8 +13,10 @@ def file_service(port):
     filename = service_get(port)
     content = service_get(port)
     try:
-        with open(filename, 'w') as f:
-            f.write(content)
+        #with open(filename, 'w') as f:
+        #    f.write(content)
+        print("WOULD WRITE TO FILE " + str(filename))
+        print("CONTENT: " + str(content))
         service_set(port, "Success")
     except:
         service_set(port, "Failure: " + traceback.format_exc())