Ejemplo n.º 1
0
    def run(self, *args, **kwargs):
        from django.conf import settings
        dist = kwargs.get("dist", False)
        buildpath = "dist" if dist else "build"
        less_dir = os.path.join(self.site.paths['static'], "less")
        css_dir = os.path.join(self.site.paths[buildpath], settings.STATIC_URL_REL, 'css')
        if not os.path.isdir(less_dir) or not os.listdir(less_dir):
            return

        main_file_less = self.config.get("main_file_less", "main.less")
        main_file_css = self.config.get("main_file_css", "main.css")
        sass = self.config.get(
            "command",
            "lessc {input} {output}"
        )

        cmd = sass.format(
            input=shell_escape(
                os.path.realpath(
                    os.path.join(less_dir, main_file_less)
                )
            ),
            output=shell_escape(
                os.path.realpath(
                    os.path.join(css_dir, main_file_css)
                )
            ),
            )

        os.chdir(less_dir)
        if os.name == "nt":
            run_subprocess(cmd)
        else:
            os.system(cmd)
Ejemplo n.º 2
0
    def postDist(self, *args, **kwargs):
        from django.conf import settings

        files = fileList(os.path.join(self.site.paths['dist'], settings.STATIC_URL_REL))

        def filter_png(f):
            return bool(re_optipng.search(f))

        def filter_jpg(f):
            return bool(re_jpegoptim.search(f))

        optipng = self.config.get(
            "command_png",
            "optipng {files}"
        )

        jpegoptim = self.config.get(
            "command_jpg",
            "jpegoptim -o -t --strip-all {file}"
        )

        pngs = map(lambda x: shell_escape(x), filter(filter_png, files))
        if pngs:
            command = optipng.format(files=" ".join(pngs))
            os.system(command)

        for f in filter(filter_jpg, files):
            command = jpegoptim.format(file=f)
            os.system(command)
Ejemplo n.º 3
0
    def run(self, *args, **kwargs):
        from django.conf import settings
        s_type = self.config.get("type", "sass")
        if s_type != "sass" and s_type != "scss":
            s_type = "sass"

        dist = kwargs.get("dist", False)
        buildpath = "dist" if dist else "build"
        sass_dir = os.path.join(self.site.paths['static'], s_type)
        css_dir = os.path.join(self.site.paths[buildpath], settings.STATIC_URL_REL, 'css')
        if not os.path.isdir(sass_dir) or not os.listdir(sass_dir):
            return

        if not os.path.exists(css_dir):
            os.makedirs(css_dir)

        main_file_sass = self.config.get("main_file_sass", "main.sass")
        if s_type == "scss":
            main_file_sass = self.config.get("main_file_scss", "main.scss")
        main_file_css = self.config.get("main_file_css", "main.css")
        sass = self.config.get(
            "command",
            "%s -t compressed {input} {output}" % s_type
        )

        cmd = sass.format(
            input=shell_escape(
                os.path.realpath(
                    os.path.join(sass_dir, main_file_sass)
                )
            ),
            output=shell_escape(
                os.path.realpath(
                    os.path.join(css_dir, main_file_css)
                )
            ),
        )

        os.chdir(sass_dir)
        if os.name == "nt":
            run_subprocess(cmd)
        else:
            os.system(cmd)
    def run(self, *args, **kwargs):
        from django.conf import settings
        dist = kwargs.get("dist", False)

        coffeepath = os.path.realpath(
            os.path.join(
                self.site.paths['static'], 'coffee'
            )
        )
        if not os.path.isdir(coffeepath) or not os.listdir(coffeepath):
            return

        def sort_by_buildorder(a, b):
            return 0
        try:
            build_order = self.config.get("build_order")
            if build_order:
                def sort_by_buildorder(a, b):
                    a = self._path_to_url(a, coffeepath)
                    b = self._path_to_url(b, coffeepath)

                    idx_a = 9999999
                    idx_b = 9999999
                    if a in build_order:
                        idx_a = build_order.index(a)

                    if b in build_order:
                        idx_b = build_order.index(b)

                    if idx_a == idx_b:
                        return 0

                    return cmp(idx_a, idx_b)
        except:
            pass

        files = fileList(coffeepath)
        files.sort(sort_by_buildorder)
        files = " ".join(map(lambda x: shell_escape(x), files))

        output_filename = self.config.get(
            "output_filename",
            "main.js"
        )

        temp_output_filename = ".tmp.main.js"

        coffee = self.config.get(
            "command",
            "coffee --join {output_filename} --compile --output {dir_js} {files}"
        )

        dir_js = os.path.abspath(
            os.path.join(
                self.site.paths["dist" if dist else "build"],
                settings.STATIC_URL_REL, "js"
            )
        )

        cmd = coffee.format(
            output_filename=temp_output_filename,
            dir_js=shell_escape(dir_js),
            files=files,
        )

        result = 0
        if os.name == "nt":
            run_subprocess(cmd)
            # TODO: take return code into account on windows
        else:
            print cmd
            result = os.system(cmd)

        if result == 0:
            shutil.move(
                os.path.abspath(os.path.join(dir_js, temp_output_filename)),
                os.path.abspath(os.path.join(dir_js, output_filename)),
            )
        else:
            try:
                os.remove(os.path.join(dir_js, temp_output_filename))
            except OSError:
                pass