# Path: processing/docker_utils.py
#     HAVE_DOCKER = True
#     HAVE_DOCKER = False
# def temp_volume(target):


import re
import os
import json
from fame.core.module import ProcessingModule
from fame.common.exceptions import ModuleInitializationError
from ..docker_utils import HAVE_DOCKER, docker_client, temp_volume
            raise ModuleInitializationError(self, "Missing dependency: docker")

        return True

    def run_xlmd(self, target):

        args = "-n --file '/data/{}' --export-json /data/output/results.json".format(target)

        # start the right docker
        return docker_client.containers.run(
            "fame/xlmdeobfuscator",
            args,
            volumes={self.outdir: {"bind": "/data", "mode": "rw"}},
            stderr=True,
            remove=True,
        )

    def each(self, target):
        self.results = {"macros": ""}

        self.outdir = temp_volume(target)
        results_dir = os.path.join(self.outdir, "output")

        self.run_xlmd(os.path.basename(target))

        regex_url = r"\w+:(\/\/)[^\s\"]+"
        reg = re.compile(regex_url)
        with open(os.path.join(results_dir, "results.json")) as results_json:
            data = json.load(results_json)
            for record in data["records"]:

# Path: processing/docker_utils.py
#     HAVE_DOCKER = True
#     HAVE_DOCKER = False
# def temp_volume(target):


# Path: processing/xlmdeobfuscator/xlm_deobfuscator.py
import re
import os
import json
from fame.core.module import ProcessingModule
from fame.common.exceptions import ModuleInitializationError
from ..docker_utils import HAVE_DOCKER, docker_client, temp_volume

            raise ModuleInitializationError(self, "Missing dependency: docker")

        return True

    def run_xlmd(self, target):

        args = "-n --file '/data/{}' --export-json /data/output/results.json".format(target)

        # start the right docker
        return docker_client.containers.run(
            "fame/xlmdeobfuscator",
            args,
            volumes={self.outdir: {"bind": "/data", "mode": "rw"}},
            stderr=True,
            remove=True,
        )

    def each(self, target):
        self.results = {"macros": ""}

        self.outdir = temp_volume(target)
        results_dir = os.path.join(self.outdir, "output")

        self.run_xlmd(os.path.basename(target))

        regex_url = r"\w+:(\/\/)[^\s\"]+"
        reg = re.compile(regex_url)
        with open(os.path.join(results_dir, "results.json")) as results_json:
            data = json.load(results_json)
            for record in data["records"]:

                self.results["macros"] = self.results["macros"] + "\n" + record["formula"]