Ejemplo n.º 1
0
    def readQuestions(self, fileName, force=False, autoDelete=True, optional=False, encoding="utf-8"):
        """
        Reads the given configuration file with questions and deletes the file afterwards (by default).
        Returns True when the file was found and processed.
        """

        configFile = findConfig(fileName)
        if configFile is None:
            if optional:
                return False
            else:
                raise UserError("Could not find configuration file (questions): %s" % configFile)

        data = loadConfig(configFile, encoding=encoding)
        for entry in data:
            question = entry["question"]
            name = entry["name"]

            accept = getKey(entry, "accept", None)
            required = getKey(entry, "required", True)
            default = getKey(entry, "default", None)
            force = getKey(entry, "force", False)

            self.ask(question, name, accept=accept, required=required, default=default, force=force)

        if autoDelete:
            File.rm(configFile)

        return True
Ejemplo n.º 2
0
    def executeScript(self,
                      fileName,
                      autoDelete=True,
                      optional=False,
                      encoding="utf-8"):
        """
        Executes the given script for configuration proposes and deletes the file afterwards (by default).

        Returns True when the file was found and processed.

        """

        if not os.path.exists(fileName):
            if optional:
                return False
            else:
                raise UserError("Could not find configuration script: %s" %
                                fileName)

        env = {"config": self, "file": File}

        code = open(fileName, "r", encoding=encoding).read()
        exec(compile(code, os.path.abspath(fileName), "exec"), globals(), env)

        if autoDelete:
            File.rm(fileName)

        return True
Ejemplo n.º 3
0
    def executeScript(self, fileName, autoDelete=True, optional=False, encoding="utf-8"):
        """
        Executes the given script for configuration proposes and deletes the file afterwards (by default).

        Returns True when the file was found and processed.

        """

        if not os.path.exists(fileName):
            if optional:
                return False
            else:
                raise UserError("Could not find configuration script: %s" % fileName)

        env = {
            "config" : self,
            "file" : File
        }

        code = open(fileName, "r", encoding=encoding).read()
        exec(compile(code, os.path.abspath(fileName), "exec"), globals(), env)

        if autoDelete:
            File.rm(fileName)

        return True
Ejemplo n.º 4
0
    def readQuestions(self,
                      fileName,
                      force=False,
                      autoDelete=True,
                      optional=False,
                      encoding="utf-8"):
        """
        Reads the given configuration file with questions and deletes the file afterwards (by default).

        Returns True when the file was found and processed.

        """

        configFile = findConfig(fileName)
        if configFile is None:
            if optional:
                return False
            else:
                raise UserError(
                    "Could not find configuration file (questions): %s" %
                    configFile)

        data = loadConfig(configFile, encoding=encoding)
        for entry in data:
            question = entry["question"]
            name = entry["name"]

            accept = getKey(entry, "accept", None)
            required = getKey(entry, "required", True)
            default = getKey(entry, "default", None)
            force = getKey(entry, "force", False)

            self.ask(question,
                     name,
                     accept=accept,
                     required=required,
                     default=default,
                     force=force)

        if autoDelete:
            File.rm(configFile)

        return True