Ejemplo n.º 1
0
 def precompile(self, content, **kwargs):
     type = None
     compiler = None
     elem = kwargs['elem']
     kind = kwargs['kind']
     if kind == "file":
         type = os.path.splitext(kwargs['filename'])[1][1:]
         for pc in self.precompilers:
             if pc.get('extension', None) == type:
                 compiler = pc
                 break
     elif kind == "hunk":
         type = self.parser.elem_attribs(elem).get('type', None)
         slash = type.rindex('/')
         if slash >= 0:
             type = type[slash + 1:]
         for pc in self.precompilers:
             if pc.get('type', None) == type:
                 compiler = pc
                 break
     if not compiler:
         return content
     
     source_file = tempfile.NamedTemporaryFile(mode='w+b', suffix='.' + compiler['extension'])
     dest_file_name = source_file.name[:-len(compiler['extension'])] + compiler['dest_extension']
     dest_dir_name = os.path.split(dest_file_name)[0]
     command = compiler['command'].format(source=source_file.name, dest=dest_file_name, dest_dir=dest_dir_name)
     source_file.write(content)
     source_file.flush()
     try:
         p = Popen(cmd_split(command), stdout=PIPE, stdin=PIPE, stderr=PIPE)
         output, err = p.communicate(self.content)
     except IOError, e:
         raise PrecompilerError(e)
Ejemplo n.º 2
0
 def output(self, **kwargs):
     infile = None
     outfile = None
     try:
         if "{infile}" in self.command:
             if not self.filename:
                 infile = tempfile.NamedTemporaryFile(mode='w')
                 infile.write(self.content)
                 infile.flush()
                 self.options["infile"] = infile.name
             else:
                 self.options["infile"] = self.filename
         if "{outfile}" in self.command:
             ext = ".%s" % self.type and self.type or ""
             outfile = tempfile.NamedTemporaryFile(mode='w', suffix=ext)
             self.options["outfile"] = outfile.name
         cmd = stringformat.FormattableString(self.command).format(**self.options)
         proc = subprocess.Popen(cmd_split(cmd),
             stdout=self.stdout, stdin=self.stdin, stderr=self.stderr)
         if infile is not None or self.filename is not None:
             filtered, err = proc.communicate()
         else:
             filtered, err = proc.communicate(self.content)
     except (IOError, OSError), e:
         raise FilterError('Unable to apply %s (%r): %s' % (
             self.__class__.__name__, self.command, e))
Ejemplo n.º 3
0
 def output(self, **kwargs):
     infile = None
     outfile = None
     try:
         if "{infile}" in self.command:
             infile = tempfile.NamedTemporaryFile(mode='w')
             infile.write(self.content)
             infile.flush()
             self.options["infile"] = self.filename or infile.name
         if "{outfile}" in self.command:
             ext = ".%s" % self.type and self.type or ""
             outfile = tempfile.NamedTemporaryFile(mode='rw', suffix=ext)
             self.options["outfile"] = outfile.name
         command = stringformat.FormattableString(self.command)
         proc = subprocess.Popen(cmd_split(command.format(**self.options)),
                                 stdout=self.stdout,
                                 stdin=self.stdin,
                                 stderr=self.stderr)
         if infile is not None:
             filtered, err = proc.communicate()
         else:
             filtered, err = proc.communicate(self.content)
     except (IOError, OSError), e:
         raise FilterError('Unable to apply %s (%r): %s' %
                           (self.__class__.__name__, self.command, e))
Ejemplo n.º 4
0
    def output(self, **kwargs):
        arguments = settings.CLOSURE_COMPILER_ARGUMENTS

        command = '%s %s' % (settings.CLOSURE_COMPILER_BINARY, arguments)

        try:
            p = Popen(cmd_split(command), stdout=PIPE, stdin=PIPE, stderr=PIPE)
            filtered, err = p.communicate(self.content)

        except IOError, e:
            raise FilterError(e)
Ejemplo n.º 5
0
    def output(self, **kwargs):
        arguments = ''
        if self.type == 'js':
            arguments = settings.YUI_JS_ARGUMENTS
        if self.type == 'css':
            arguments = settings.YUI_CSS_ARGUMENTS

        command = '%s --type=%s %s' % (settings.YUI_BINARY, self.type, arguments)

        if self.verbose:
            command += ' --verbose'

        try:
            p = Popen(cmd_split(command), stdin=PIPE, stdout=PIPE, stderr=PIPE)
            filtered, err = p.communicate(self.content)
        except IOError, e:
            raise FilterError(e)
Ejemplo n.º 6
0
    def output(self, **kwargs):
        arguments = ''
        if self.type == 'js':
            arguments = settings.COMPRESS_YUI_JS_ARGUMENTS
        elif self.type == 'css':
            arguments = settings.COMPRESS_YUI_CSS_ARGUMENTS

        command = '%s --type=%s %s' % (settings.COMPRESS_YUI_BINARY, self.type, arguments)

        if self.verbose:
            command += ' --verbose'

        try:
            p = Popen(cmd_split(command), stdin=PIPE, stdout=PIPE, stderr=PIPE)
            filtered, err = p.communicate(self.content)
        except IOError, e:
            raise FilterError(e)