Beispiel #1
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 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()
Beispiel #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' 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()
Beispiel #3
0
def test_etag_unicode_same():
    f1 = File.make_temp(u"\x80\x81")
    etag1 = f1.etag
    f2 = File(f1.path)
    etag2 = f2.etag
    assert etag1 == etag2
    f3 = File.make_temp(u"\x80\x81")
    etag3 = f3.etag
    assert etag1 == etag3
Beispiel #4
0
def test_etag_same():
    f1 = File.make_temp("I am new")
    etag1 = f1.etag
    f2 = File(f1.path)
    etag2 = f2.etag
    assert etag1 == etag2
    f3 = File.make_temp("I am new")
    etag3 = f3.etag
    assert etag1 == etag3
Beispiel #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 = [
            "source-map",
            "source-map-root",
            "source-map-url",
            "in-source-map",
            "screw-ie8",
            "expr",
            ("prefix", "p"),
            ("beautify", "b"),
            ("mangle", "m"),
            ("reserved", "r"),
            ("compress", "c"),
            ("define", "d"),
            ("enclose", "e"),
            "comments",
            "stats",
            "wrap",
            "lint",
            "verbose"
        ]

        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
Beispiel #6
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
    def text_resource_complete(self, resource, text):
        """
        Save the file to a temporary place
        and run the Coffee app. 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)
Beispiel #8
0
    def binary_resource_complete(self, resource):
        """
        Run jpegtran to compress the jpg file.
        """

        if not resource.source_file.kind == 'jpg':
            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()
Beispiel #9
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()
Beispiel #10
0
    def text_resource_complete(self, resource, text):
        """
        If the site is in development mode, just return.
        Otherwise, run optipng to compress the png file.
        """

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

        source = File.make_temp(text)
        (source_root,
         source_ext) = os.path.splitext(unicode(resource.source_file))

        png_in_source = source_root + u'.png'
        if os.path.exists(png_in_source):
            return text

        target = self.site.config.deploy_root_path.child(
            resource.relative_deploy_path)
        (root, ext) = os.path.splitext(target)
        target = root + u'.png'

        d = os.path.dirname(target)
        if not os.path.exists(d):
            os.makedirs(d)
        args = [u'inkscape']
        args.extend(['-z'])
        args.extend(['-f', unicode(source)])
        args.extend(['-w', '850'])
        args.extend(['-h', '170'])
        args.extend(['-e', unicode(target)])
        print args
        self.call_app(args)
        return text
Beispiel #11
0
    def text_resource_complete(self, resource, text):
        """
        If the site is in development mode, just return.
        Otherwise, run optipng to compress the png file.
        """

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

        source = File.make_temp(text)
        (source_root, source_ext) = os.path.splitext(unicode(resource.source_file))

        png_in_source = source_root + u'.png'
        if os.path.exists(png_in_source):
            return text

        target = self.site.config.deploy_root_path.child(
                                resource.relative_deploy_path)
        (root, ext) = os.path.splitext(target)
        target = root + u'.png'

        d = os.path.dirname(target)
        if not os.path.exists(d):
            os.makedirs(d)
        args = [u'inkscape']
        args.extend(['-z'])
        args.extend(['-f', unicode(source)])
        args.extend(['-w', '850'])
        args.extend(['-h', '170'])
        args.extend(['-e', unicode(target)])
        print args
        self.call_app(args)
        return text
Beispiel #12
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
Beispiel #13
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)
Beispiel #14
0
def test_etag_different():
    f1 = File.make_temp("I am new")
    etag1 = f1.etag
    with open(f1.path, "a") as fout:
        fout.write(" ")
    etag2 = f1.etag
    assert etag1 != etag2
    f1.write("I am New ")
    etag3 = f1.etag
    assert etag3 != etag1
    assert etag3 != etag2
Beispiel #15
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 = [
            "source-map", "source-map-root",
            "source-map-url", "in-source-map", "screw-ie8", "expr",
            ("prefix", "p"), ("beautify", "b"), ("mangle", "m"),
            ("reserved", "r"), ("compress", "c"), ("define", "d"),
            ("enclose", "e"), "comments", "stats", "wrap", "lint", "verbose"
        ]

        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
Beispiel #16
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)
        args = [unicode(coffee)]
        args.extend(["-c", "-p", unicode(source)])
        return self.call_app(args)
Beispiel #17
0
Datei: js.py Projekt: jperry/hyde
    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()
Beispiel #18
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 = [str(rjs)]
        args.extend(
            ['-o', str(resource), ("out=" + target.fully_expanded_path)])

        try:
            self.call_app(args)
        except subprocess.CalledProcessError:
            HydeException.reraise(
                "Cannot process %s. Error occurred when "
                "processing [%s]" % (self.app.name, resource.source_file),
                sys.exc_info())

        return target.read_all()
Beispiel #19
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))
Beispiel #20
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:
            raise self.template.exception_class(
                "Cannot process %s. Error occurred when "
                "processing [%s]" % (stylus.name, resource.source_file))
        return target.read_all()
Beispiel #21
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()