Example #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)
Example #2
0
    def main(self):

        name = self.getInputName()

        forced = self.options.force
        if forced and not Shell.printConfirm("You are about to force halt engine \"%s\"." % name):
            self.exitOK("User cancelled.")

        self.core.loadEngine(name) \
            .bind(Engine.loadConfigFile) \
            .bind(defer(Engine.stop, force=forced)) \
            .catch(self.exitError)
Example #3
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
        }
Example #4
0
    def run(self, args, envName=None):
        if not envName:
            envSpec = self._getCurrentEnv()
            if not envSpec:
                return Fail(InvalidEnvError("No env is currently active."))
            envName = envSpec.name

        cmd = subprocess.list2cmdline(args)

        return OK(envName) \
            .bind(self._loadEnvSpec) \
            .map(lambda x: x.envPath) \
            .bind(lambda p: Shell.call(cmd, cwd=p, shell=True))
Example #5
0
 def tearDown(self):
     pass
     if self.basePath:
         Shell.nukeDirectory(self.basePath).catch(tests.TestBase.raiser)
     if self.subenvBasePath:
         Shell.nukeDirectory(self.subenvBasePath).catch(
             tests.TestBase.raiser)
     if self.projectsBasePath:
         Shell.nukeDirectory(self.projectsBasePath).catch(
             tests.TestBase.raiser)
Example #6
0
    def applyFiles(self):
        ops = []
        for file in self.struct['files']:
            fname, ext = os.path.splitext(file)
            source = os.path.join(self.specPath, file)
            dest = os.path.join(self.envPath, file)

            if fname == ENVFILE:
                continue
            elif ext == '.jinja':
                logger.debug("Rendering '%s' to %s" % (file, dest))
                dest = os.path.splitext(dest)[0]
                ops.append(self.renderFile(file, dest, self.vars))
            else:
                logger.debug("Copying '%s' to %s" % (file, dest))
                ops.append(
                    Shell.copyFile(os.path.join(self.specPath, file),
                                   os.path.join(self.envPath, file)))

        return Try.sequence(ops)
Example #7
0
 def applyCommand(self, cmd):
     logger.info("Running environment command: %s" % cmd)
     return Shell.call(cmd, cwd=self.envPath, shell=True)
Example #8
0
 def clearEnv(self):
     if os.path.isfile(self.config.configFile):
         return Shell.rmFile(self.config.configFile)
     return OK(None)
Example #9
0
 def delete(self, name):
     envPath = os.path.normpath(os.path.join(self.envsPath, name))
     if not os.path.isdir(envPath):
         return Fail(InvalidOptionError("Environment '%s' does not exist."))
     return Shell.nukeDirectory(envPath)
Example #10
0
 def editEngineConfig(self, engine):
     cmd = os.environ.get('EDITOR', 'vi') + ' ' + \
         engine.config.getConfigFile()
     return Shell.call(cmd).map(lambda x: engine)
Example #11
0
 def ask(self, msg):
     return Shell.printConfirm(msg, assumeYes=self.core.getAssumeYes())