|
|
@@ -0,0 +1,62 @@
|
|
|
+import json
|
|
|
+
|
|
|
+from .decode import decode
|
|
|
+from .package import package
|
|
|
+from .command import command
|
|
|
+from .command import encoded_command
|
|
|
+from .file import file
|
|
|
+from .file import encoded_file
|
|
|
+from .package import package
|
|
|
+from .package import package_builder
|
|
|
+from .exceptions import broken_package
|
|
|
+
|
|
|
+class package_import(decode):
|
|
|
+ def __init__(self, content: str) -> None:
|
|
|
+ self.__content = content
|
|
|
+
|
|
|
+ @property
|
|
|
+ def __json_string(self) -> str:
|
|
|
+ return self._decode_str(self.__content)
|
|
|
+
|
|
|
+ @property
|
|
|
+ def __flat_content(self) -> dict:
|
|
|
+ return json.loads(self.__json_string)
|
|
|
+
|
|
|
+ def __process_commands(self, commands: list) -> list:
|
|
|
+ result = list()
|
|
|
+
|
|
|
+ for count in commands:
|
|
|
+ result.push(encoded_command(count).decode())
|
|
|
+
|
|
|
+ return result
|
|
|
+
|
|
|
+ def __process_files(self, files: list) -> list:
|
|
|
+ result = list()
|
|
|
+
|
|
|
+ for count in files:
|
|
|
+ encoded_path = count["path"]
|
|
|
+ encoded_content = count["content"]
|
|
|
+ encoded_count = encoded_file(encoded_path, encoded_content)
|
|
|
+
|
|
|
+ result.push(encoded_count.decode())
|
|
|
+
|
|
|
+ return result
|
|
|
+
|
|
|
+ def unpack(self) -> package:
|
|
|
+ try:
|
|
|
+ content = self.__flat_content
|
|
|
+ commands = self.__process_commands(content["commands"])
|
|
|
+ files = self.__process_files(content["files"])
|
|
|
+
|
|
|
+ builder = package_builder()
|
|
|
+
|
|
|
+ for count in commands:
|
|
|
+ builder.add_command(count)
|
|
|
+
|
|
|
+ for count in files:
|
|
|
+ builder.add_file(count)
|
|
|
+
|
|
|
+ return builder.pack()
|
|
|
+
|
|
|
+ except Exception as error:
|
|
|
+ raise broken_package(error)
|