Beispiel #1
0
    def applyDirs(self):
        ops = [Shell.makeDirectory(self.envPath, 0o750)]
        for dir in self.struct['dirs']:
            sourceDir = os.path.join(self.specPath, dir)
            destDir = os.path.join(self.envPath, dir)
            mode = os.stat(sourceDir).st_mode & 0o777
            logger.debug("Creating directory '%s' mode: %s" % (dir, mode))
            ops.append(
                Shell.makeDirectory(destDir).bind(defer(Shell.chmod,
                                                        mode=mode)))

        return Try.sequence(ops)
Beispiel #2
0
    def makeEnv(self):

        name = self.randString()

        ppath = os.path.join(self.projectsBasePath, name)
        specpath = os.path.join(ppath, SPECDIR)

        op = Shell.makeDirectory(ppath) \
            .then(defer(Shell.makeDirectory, specpath))

        self.assertIsInstance(op, OK)

        dirs = [
            'conf',
            os.path.join('conf', 'web'),
            os.path.join('conf', 'cron'),
            os.path.join('conf', 'logrotate')
        ]
        ops = [
            Try.attempt(Shell.makeDirectory, os.path.join(specpath, x))
            for x in dirs
        ]

        self.assertIsInstance(Try.sequence(ops), OK)

        tpl1 = "{{SUBENV_ENVPATH}}\n{{SUBENV_BASEPATH}}"
        tpl2 = 'This is a template with no vars.'

        customVar = self.randString()

        envTpl = 'name="%(name)s"\ncustom="%(custom)s"'

        filedata = {}
        filedata[ENVFILE] = envTpl % {'name': name, 'custom': customVar}
        filedata["tpl1.jinja"] = tpl1
        filedata[os.path.join("conf", "tpl2.jinja")] = tpl2

        ops = []
        for file, data in filedata.items():
            ops.append(
                Try.attempt(writeToFile, os.path.join(specpath, file),
                            data.encode()))

        self.assertIsInstance(Try.sequence(ops), OK)

        return {
            'name': name,
            'custom': customVar,
            'path': ppath,
            'files': filedata,
            'dirs': dirs
        }