Exemplo n.º 1
0
class HttpCommander:
    def __init__(self, *args, **kwargs):
        self.env = HttpEnvironment(**kwargs)
        self.exe = Http(self.env)

    def configure(self):
        self._create_home_dir()
        self._create_conf_file()

    def run(self, **kwargs):
        return self.exe.run(stdout=sp.PIPE, stderr=sp.STDOUT, **kwargs)

    def _create_home_dir(self):
        if not os.path.exists(self.env["home_dir"]):
            os.makedirs(self.env["home_dir"])

        if "symlink" not in self.env:
            os.makedirs(os.path.join(self.env["home_dir"], "www"))
        else:
            os.symlink(self.env["symlink"], os.path.join(self.env["home_dir"], "www"))

    def _create_conf_file(self):
        loader = FileLoader("/")
        template = loader.load_template(self.env.abs_conf_tmpl())
        nc_conf = template.render(self.env)
        with open(self.env.abs_conf_file(), "w") as fd:
            fd.write(nc_conf)

    def _destroy(self):
        shutil.rmtree(self.env["home_dir"])

    def __str__(self):
        return type(self).__name__
Exemplo n.º 2
0
 def __init__(self, *args, **kwargs):
     self.env = HttpEnvironment(**kwargs)
     self.exe = Http(self.env)