Exemple #1
0
    def input(self, **kwargs):
        options = dict(self.options)
        if self.infile is None:
            if "{infile}" in self.command:
                if self.filename is None:
                    self.infile = tempfile.NamedTemporaryFile(mode="w")
                    self.infile.write(self.content)
                    self.infile.flush()
                    os.fsync(self.infile)
                    options["infile"] = self.infile.name
                else:
                    self.infile = open(self.filename)
                    options["infile"] = self.filename

        if "{outfile}" in self.command and not "outfile" in options:
            ext = ".%s" % self.type and self.type or ""
            self.outfile = tempfile.NamedTemporaryFile(mode="r+", suffix=ext)
            options["outfile"] = self.outfile.name
        try:
            command = fstr(self.command).format(**options)
            proc = subprocess.Popen(
                command, shell=True, cwd=self.cwd, stdout=self.stdout, stdin=self.stdin, stderr=self.stderr
            )
            if self.infile is None:
                filtered, err = proc.communicate(self.content)
            else:
                filtered, err = proc.communicate()
        except (IOError, OSError), e:
            raise FilterError("Unable to apply %s (%r): %s" % (self.__class__.__name__, self.command, e))
Exemple #2
0
    def output(self, **kwargs):
        options = dict(self.options)
        options['outfile'] = kwargs['outfile']

        infiles = []
        for infile in kwargs['content_meta']:
            # type, full_filename, relative_filename
            infiles.append(infile[2])

        options['infiles'] = ' '.join(f for f in infiles)

        options['mapfile'] = kwargs['outfile'].replace('.js', '.map.js')

        options['mapurl'] = '{}{}'.format(
            settings.STATIC_URL, options['mapfile'])

        options['maproot'] = settings.STATIC_URL

        self.cwd = kwargs['root_location']

        try:
            command = fstr(self.command).format(**options)

            proc = subprocess.Popen(
                command, shell=True, cwd=self.cwd, stdout=self.stdout,
                stdin=self.stdin, stderr=self.stderr)
            err = proc.communicate()
        except (IOError, OSError), e:
            raise FilterError('Unable to apply %s (%r): %s' %
                              (self.__class__.__name__, self.command, e))
Exemple #3
0
    def input(self, **kwargs):
        options = dict(self.options)
        if self.infile is None:
            if "{infile}" in self.command:
                if self.filename is None:
                    self.infile = tempfile.NamedTemporaryFile(mode="w")
                    self.infile.write(self.content)
                    self.infile.flush()
                    os.fsync(self.infile)
                    options["infile"] = self.infile.name
                else:
                    self.infile = open(self.filename)
                    options["infile"] = self.filename

        if "{outfile}" in self.command and not "outfile" in options:
            ext = ".%s" % self.type and self.type or ""
            self.outfile = tempfile.NamedTemporaryFile(mode='r+', suffix=ext)
            options["outfile"] = self.outfile.name
        try:
            command = fstr(self.command).format(**options)
            proc = subprocess.Popen(command,
                                    shell=True,
                                    cwd=self.cwd,
                                    stdout=self.stdout,
                                    stdin=self.stdin,
                                    stderr=self.stderr)
            if self.infile is None:
                filtered, err = proc.communicate(self.content)
            else:
                filtered, err = proc.communicate()
        except (IOError, OSError), e:
            raise FilterError('Unable to apply %s (%r): %s' %
                              (self.__class__.__name__, self.command, e))
Exemple #4
0
    def output(self, **kwargs):
        options = dict(self.options)
        options['outfile'] = kwargs['outfile']

        infiles = []
        for infile in kwargs['content_meta']:
            # type, full_filename, relative_filename
            # In debug mode we use the full path so that in development we see changes without having to call
            # collectstatic. This breaks the sourcemaps. In production, we want  sourcemaps to work so we
            # use relative path which will take files from `staticfiles` automatically.
            if settings.DEBUG:
                infiles.append(infile[1])
            else:
                infiles.append(infile[2])

        options['uglifyjs'] = os.path.join(settings.BASE_DIR, 'node_modules',
                                           'uglify-js', 'bin', 'uglifyjs')

        options['infiles'] = ' '.join(f for f in infiles)

        options['mapfile'] = kwargs['outfile'].replace('.js', '.map.js')

        options['mapurl'] = '{}{}'.format(settings.STATIC_URL,
                                          options['mapfile'])

        options['maproot'] = settings.STATIC_URL

        self.cwd = kwargs['root_location']

        try:
            command = fstr(self.command).format(**options)

            proc = subprocess.Popen(command,
                                    shell=True,
                                    cwd=self.cwd,
                                    stdout=self.stdout,
                                    stdin=self.stdin,
                                    stderr=self.stderr)
            err = proc.communicate()
        except (IOError, OSError) as e:
            raise FilterError('Unable to apply %s (%r): %s' %
                              (self.__class__.__name__, self.command, e))
        else:
            # If the process doesn't return a 0 success code, throw an error
            if proc.wait() != 0:
                if not err:
                    err = ('Unable to apply %s (%s)' %
                           (self.__class__.__name__, self.command))
                raise FilterError(err)
            if self.verbose:
                self.logger.debug(err)
Exemple #5
0
    def output(self, **kwargs):
        options = dict(self.options)
        options['outfile'] = kwargs['outfile']

        infiles = []
        for infile in kwargs['content_meta']:
            # type, full_filename, relative_filename
            # In debug mode we use the full path so that in development we see changes without having to call
            # collectstatic. This breaks the sourcemaps. In production, we want  sourcemaps to work so we
            # use relative path which will take files from `staticfiles` automatically.
            if settings.DEBUG:
                infiles.append(infile[1])
            else:
                infiles.append(infile[2])

        options['infiles'] = ' '.join(f for f in infiles)

        options['mapfile'] = kwargs['outfile'].replace('.js', '.map.js')

        options['mapurl'] = '{}{}'.format(
            settings.STATIC_URL, options['mapfile']
        )

        options['maproot'] = settings.STATIC_URL

        self.cwd = kwargs['root_location']

        try:
            command = fstr(self.command).format(**options)

            proc = subprocess.Popen(
                command, shell=True, cwd=self.cwd, stdout=self.stdout,
                stdin=self.stdin, stderr=self.stderr)
            err = proc.communicate()
        except (IOError, OSError) as e:
            raise FilterError('Unable to apply %s (%r): %s' %
                              (self.__class__.__name__, self.command, e))
        else:
            # If the process doesn't return a 0 success code, throw an error
            if proc.wait() != 0:
                if not err:
                    err = ('Unable to apply %s (%s)' %
                           (self.__class__.__name__, self.command))
                raise FilterError(err)
            if self.verbose:
                self.logger.debug(err)