Exemplo n.º 1
0
Arquivo: less.py Projeto: bhunter/hyde
    def text_resource_complete(self, resource, text):
        """
        Save the file to a temporary place and run less compiler.
        Read the generated file and return the text as output.
        Set the target path to have a css extension.
        """
        if not resource.source_file.kind == 'less':
            return

        supported = [
            "verbose",
            ("silent", "s"),
            ("compress", "x"),
            "O0",
            "O1",
            "O2"
        ]

        less = self.app
        source = File.make_temp(text)
        target = File.make_temp('')
        args = [unicode(less)]
        args.extend(self.process_args(supported))
        args.extend([unicode(source), unicode(target)])
        try:
            self.call_app(args)
        except subprocess.CalledProcessError:
             raise self.template.exception_class(
                    "Cannot process %s. Error occurred when "
                    "processing [%s]" % (self.app.name, resource.source_file))
        return target.read_all()
Exemplo n.º 2
0
    def text_resource_complete(self, resource, text):
        """
        Save the file to a temporary place and run less compiler.
        Read the generated file and return the text as output.
        Set the target path to have a css extension.
        """
        if not resource.source_file.kind == 'less':
            return
        if not (hasattr(self.site.config, 'less') and
            hasattr(self.site.config.less, 'app')):
            raise self.template.exception_class(
                            "Less css path not configured. "
                            "This plugin expects `less.app` to point "
                            "to the `lessc` executable.")

        less = File(self.site.config.less.app)
        if not File(less).exists:
            raise self.template.exception_class(
                    "Cannot find the less executable. The given path [%s] "
                                "is incorrect" % less)

        source = File.make_temp(text)
        target = File.make_temp('')
        try:
            subprocess.check_call([str(less), str(source), str(target)])
        except subprocess.CalledProcessError, error:
            self.logger.error(traceback.format_exc())
            self.logger.error(error.output)
            raise self.template.exception_class(
                    "Cannot process less css. Error occurred when "
                    "processing [%s]" % resource.source_file)
Exemplo n.º 3
0
    def text_resource_complete(self, resource, text):
        """
        Save the file to a temporary place and run less compiler.
        Read the generated file and return the text as output.
        Set the target path to have a css extension.
        """
        if not resource.source_file.kind == 'less' or not \
            self._should_parse_resource(resource):
            return

        supported = [
            "verbose", ("silent", "s"), ("compress", "x"), "O0", "O1", "O2",
            "include-path="
        ]

        less = self.app
        source = File.make_temp(text)
        target = File.make_temp('')
        args = [unicode(less)]
        args.extend(self.process_args(supported))
        args.extend([unicode(source), unicode(target)])
        try:
            self.call_app(args)
        except subprocess.CalledProcessError:
            raise self.template.exception_class(
                "Cannot process %s. Error occurred when "
                "processing [%s]" % (self.app.name, resource.source_file))
        return target.read_all()
Exemplo n.º 4
0
    def text_resource_complete(self, resource, text):
        """
        If the site is in development mode, just return.
        Otherwise, save the file to a temporary place
        and run the uglify app. Read the generated file
        and return the text as output.
        """

        try:
            mode = self.site.config.mode
        except AttributeError:
            mode = "production"

        if not resource.source_file.kind == 'js':
            return

        if mode.startswith('dev'):
            self.logger.debug("Skipping uglify in development mode.")
            return

        supported = [
            ("beautify", "b"),
            ("indent", "i"),
            ("quote-keys", "q"),
            ("mangle-toplevel", "mt"),
            ("no-mangle", "nm"),
            ("no-squeeze", "ns"),
            "no-seqs",
            "no-dead-code",
            ("no-copyright", "nc"),
            "overwrite",
            "verbose",
            "unsafe",
            "max-line-len",
            "reserved-names",
            "ascii"
        ]

        uglify = self.app
        source = File.make_temp(text)
        target = File.make_temp('')
        args = [unicode(uglify)]
        args.extend(self.process_args(supported))
        args.extend(["-o", unicode(target), unicode(source)])

        self.call_app(args)
        out = target.read_all()
        return out
Exemplo n.º 5
0
    def text_resource_complete(self, resource, text):
        """
        If the site is in development mode, just return.
        Otherwise, save the file to a temporary place
        and run the uglify app. Read the generated file
        and return the text as output.
        """

        try:
            mode = self.site.config.mode
        except AttributeError:
            mode = "production"

        if not resource.source_file.kind == 'js':
            return

        if mode.startswith('dev'):
            self.logger.debug("Skipping uglify in development mode.")
            return

        supported = [
            ("beautify", "b"),
            ("indent", "i"),
            ("quote-keys", "q"),
            ("mangle-toplevel", "mt"),
            ("no-mangle", "nm"),
            ("no-squeeze", "ns"),
            "no-seqs",
            "no-dead-code",
            ("no-copyright", "nc"),
            "overwrite",
            "verbose",
            "unsafe",
            "max-line-len",
            "reserved-names",
            "ascii"
        ]

        uglify = self.app
        source = File.make_temp(text)
        target = File.make_temp('')
        args = [str(uglify)]
        args.extend(self.process_args(supported))
        args.extend(["-o", str(target), str(source)])

        self.call_app(args)
        out = target.read_all()
        return out
Exemplo n.º 6
0
    def text_resource_complete(self, resource, text):
        """
        Save the file to a temporary place and run the Coffee
        compiler. Read the generated file and return the text as
        output.
        """

        if not resource.source_file.kind == 'coffee':
            return

        coffee = self.app
        source = File.make_temp(text)
        target = File.make_temp('')
        args = [unicode(coffee)]
        args.extend(["-c", "-p", unicode(source)])
        return self.call_app(args)
Exemplo n.º 7
0
def test_can_create_temp_file():
    text = "A for apple"
    f = File.make_temp(text)
    assert f.exists
    assert text == f.read_all()
    f.delete()
    assert not f.exists
Exemplo n.º 8
0
    def text_resource_complete(self, resource, text):
        """
        Save the file to a temporary place and run coffee compiler.
        Read the generated file and return the text as output.
        Set the target path to have a js extension.
        """
        if not resource.source_file.kind == 'coffee': #or not \
            #self._should_parse_resource(resource):
            return

        # altering this method a bit:
        # coffee compiler can't target a specific _file_, so we must capture stdout

        #supported = [
        #    "p",
        #    "c"
        #]

        coffee = self.app
        source = File.make_temp(text)
        args = [unicode(coffee)]
        args.extend(["-p","-c", unicode(source)])
        try:
            #self.call_app(args)
            p=subprocess.Popen(args, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
        except subprocess.CalledProcessError:
             raise self.template.exception_class(
                    "Cannot process %s. Error occurred when "
                    "processing [%s]" % (self.app.name, resource.source_file))
        return p.communicate()[0] #(stdout, stderr)
Exemplo n.º 9
0
def test_can_create_temp_file():
    text = "A for apple"
    f = File.make_temp(text)
    assert f.exists
    assert text == f.read_all()
    f.delete()
    assert not f.exists
Exemplo n.º 10
0
    def text_resource_complete(self, resource, text):
        """
        Save the file to a temporary place and run yuicompressor.
        Read the generated file and return the text as output.
        """

        try:
            mode = self.site.config.mode
        except AttributeError:
            mode = "production"

        if not resource.source_file.kind == 'css':
            return

        if mode.startswith('dev'):
            self.logger.debug("Skipping yuicompressor in development mode.")
            return

        yui = self.app

        source = File.make_temp(text)
        target = source

        args = [unicode(yui)]
        args.extend(["--type", "css"])
        args.extend(["-o", unicode(target), unicode(source)])

        try:
            self.call_app(args)
        except subprocess.CalledProcessError:
             raise self.template.exception_class(
                    "Cannot process %s. Error occurred when "
                    "processing [%s]" % (self.app.name, resource.source_file))

        return target.read_all()
Exemplo n.º 11
0
def test_time_functions():
    f1 = File(__file__)
    t1 = f1.last_modified
    f2 = File.make_temp("I am new")
    t2  = f2.last_modified
    assert t1 < t2
    assert f2.has_changed_since(t1)
    assert f1.older_than(f2)
Exemplo n.º 12
0
def test_time_functions():
    f1 = File(__file__)
    t1 = f1.last_modified
    f2 = File.make_temp("I am new")
    t2 = f2.last_modified
    assert t1 < t2
    assert f2.has_changed_since(t1)
    assert f1.older_than(f2)
Exemplo n.º 13
0
Arquivo: less.py Projeto: semk/hyde
 def text_resource_complete(self, resource, text):
     """
     Save the file to a temporary place and run less compiler.
     Read the generated file and return the text as output.
     Set the target path to have a css extension.
     """
     if not resource.source_file.kind == 'less':
         return
     less = self.app
     source = File.make_temp(text)
     target = File.make_temp('')
     try:
         self.call_app([str(less), str(source), str(target)])
     except subprocess.CalledProcessError:
          raise self.template.exception_class(
                 "Cannot process %s. Error occurred when "
                 "processing [%s]" % (self.app.name, resource.source_file))
     return target.read_all()
Exemplo n.º 14
0
    def text_resource_complete(self, resource, text):
        if not resource.source_file.name == 'rjs.conf':
            return

        rjs = self.app
        target = File.make_temp('')
        args = [unicode(rjs)]
        args.extend(['-o', unicode(resource), ("out=" + target.fully_expanded_path)])

        try:
            self.call_app(args)
        except subprocess.CalledProcessError:
             raise self.template.exception_class(
                    "Cannot process %s. Error occurred when "
                    "processing [%s]" % (self.app.name, resource.source_file))

        return target.read_all()
Exemplo n.º 15
0
    def begin_text_resource(self, resource, text):
        if not resource.meta.dust:
            return
        source = File.make_temp(text.strip())
        target = source
        dust = self.app

        args = [unicode(dust)]
        args.append("--name=" + resource.source_file.name_without_extension)
        args.append(unicode(source))
        args.append(unicode(target))
        try:
            self.call_app(args)
        except subprocess.CalledProcessError:
            raise self.template.exception_class(
                    "Cannot process %s. Error occurred when "
                    "processing [%s]" % (self.name, resource.source_file))
        return target.read_all()
Exemplo n.º 16
0
    def text_resource_complete(self, resource, text):
        """
        Save the file to a temporary place and run stylus compiler.
        Read the generated file and return the text as output.
        Set the target path to have a css extension.
        """
        if not resource.source_file.kind == 'styl':
            return
        stylus = self.app
        source = File.make_temp(text.strip())
        target = source
        supported = [("compress", "c"), ("include", "I")]

        args = [unicode(stylus)]
        args.extend(self.process_args(supported))
        args.append(unicode(source))
        try:
            self.call_app(args)
        except subprocess.CalledProcessError, e:
            raise self.template.exception_class(
                "Cannot process %s. Error occurred when "
                "processing [%s]" % (stylus.name, resource.source_file))
Exemplo n.º 17
0
    def text_resource_complete(self, resource, text):
        """
        Save the file to a temporary place and run stylus compiler.
        Read the generated file and return the text as output.
        Set the target path to have a css extension.
        """
        if not resource.source_file.kind == 'styl':
            return
        stylus = self.app
        source = File.make_temp(text)
        target = source
        supported = [("compress", "c"), ("include", "I")]

        args = [unicode(stylus)]
        args.extend(self.process_args(supported))
        args.append(unicode(source))
        try:
            self.call_app(args)
        except subprocess.CalledProcessError, e:
            raise self.template.exception_class(
                    "Cannot process %s. Error occurred when "
                    "processing [%s]" % (stylus.name, resource.source_file))
Exemplo n.º 18
0
    def binary_resource_complete(self, resource):
        """
        If the site is in development mode, just return.
        Otherwise, run jpegtran to compress the jpg file.
        """

        try:
            mode = self.site.config.mode
        except AttributeError:
            mode = "production"

        if not resource.source_file.kind == 'jpg':
            return

        if mode.startswith('dev'):
            self.logger.debug("Skipping jpegtran in development mode.")
            return

        supported = [
            "optimize",
            "progressive",
            "restart",
            "arithmetic",
            "perfect",
            "copy",
        ]
        source = File(self.site.config.deploy_root_path.child(
                resource.relative_deploy_path))
        target = File.make_temp('')
        jpegtran = self.app
        args = [unicode(jpegtran)]
        args.extend(self.process_args(supported))
        args.extend(["-outfile", unicode(target), unicode(source)])
        self.call_app(args)
        target.copy_to(source)
        target.delete()