Example #1
0
    def execute(self, namespace):
        """Execute the command."""
        name = namespace.name.lower()
        path = namespace.path
        if not os.path.exists(path):
            raise ValueError("the directory {} does not exist".format(
                    repr(path)))

        if not os.access(path, os.W_OK):
            raise ValueError("the path {} is not writable".format(
                    repr(path)))

        directory = path + os.sep + name
        if os.path.exists(directory):
            raise InteruptCommand("the directory {} already exists".format(
                    repr(directory)))

        os.makedirs(directory)
        default_dirs = (
            "bundles",
            "config",
            "layout",
            "plugins",
            "static",
        )

        for dirname in default_dirs:
            os.makedirs(directory + os.sep + dirname)

        # Create the default configuration files
        to_copy = (
            "config",
            "layout",
            "static",
        )

        for dirname in to_copy:
            source = os.path.join(self.server.source_directory, "static",
                    dirname)
            destination = os.path.join(directory, dirname)
            copydir(source, destination)

        print("done")
Example #2
0
    def execute(self, namespace):
        """Execute the command."""
        # First, check that the bundle as a valid name
        name = namespace.name.lower()
        path = namespace.path
        directory = path + os.sep + "bundles" + os.sep + name
        if os.path.exists(directory):
            raise InteruptCommand("the directory {} already exists".format(
                    repr(directory)))

        os.makedirs(directory)
        print("Bundle {} created".format(repr(name)))

        # Create a default bundle
        if len(self.server.bundles) == 0 or namespace.default:
            origin = os.path.join(self.server.source_directory, "static",
                    "bundles", "welcome")
            copydir(origin, directory, bundle=name)
            print("A default configuration was set.")