示例#1
0
    def build(self, force=False, no_filters=False):
        """Build this bundle, meaning create the file given by the
        ``output`` attribute, applying the configured filters etc.

        A ``FileHunk`` will be returned.

        TODO: Support locking. When called from inside a template tag,
        this should lock, so that multiple requests don't all start
        to build. When called from the command line, there is no need
        to lock.
        """

        if not self.output:
            raise BuildError('No output target found for %s' % self)

        # Determine if we really need to build, or if the output file
        # already exists and nothing has changed.
        if force:
            update_needed = True
        elif not path.exists(abspath(self.output)):
            if not settings.ASSETS_AUTO_CREATE:
                raise BuildError(('\'%s\' needs to be created, but '
                                  'ASSETS_AUTO_CREATE is disabled') % self)
            else:
                update_needed = True
        else:
            source_paths = [abspath(p) for p in self.get_files()]
            update_needed = get_updater()(abspath(self.output), source_paths)

        if not update_needed:
            # We can simply return the existing output file
            return FileHunk(self.output)

        hunk = self._build(self.output, force, no_filters)
        
        # If the output directory does not exist, create it
        output_directory = path.dirname(abspath(self.output))
        if not path.exists(output_directory):
            try:
                 makedirs(output_directory)
            except OSError, e:
                if e.errno != errno.EEXISTS:
                    raise
示例#2
0
        def check_for_changes():
            changed_bundles = []
            for bundle in bundles:
                for filename in bundle.get_files():
                    filename = abspath(filename)
                    stat = os.stat(filename)
                    mtime = stat.st_mtime
                    if _win:
                        mtime -= stat.st_ctime

                    if _mtimes.get(filename, mtime) != mtime:
                        changed_bundles.append(bundle)
                        _mtimes[filename] = mtime
                        break
                    _mtimes[filename] = mtime
            return changed_bundles
示例#3
0
        def check_for_changes():
            changed_bundles = []
            for bundle in bundles:
                for filename in bundle.get_files():
                    filename = abspath(filename)
                    stat = os.stat(filename)
                    mtime = stat.st_mtime
                    if _win:
                        mtime -= stat.st_ctime

                    if _mtimes.get(filename, mtime) != mtime:
                        changed_bundles.append(bundle)
                        _mtimes[filename] = mtime
                        break
                    _mtimes[filename] = mtime
            return changed_bundles
示例#4
0
 def CMD_clean(self, options, bundles):
     """ Delete generated assets.
     """
     
     try:
         if options.get('verbosity') >= 1:
                 print "Cleaning generated assets..."
                 
         for bundle in bundles:
             file_path = abspath(bundle.output)
             if os.path.exists(file_path):
                 os.unlink(file_path)
                 
                 if options.get('verbosity') >= 1:
                     print "Deleted asset: %s" % bundle.output
     except KeyboardInterrupt:
         pass
示例#5
0
 def CMD_clean(self, options, bundles):
     """ Delete generated assets.
     """
     
     try:
         if options.get('verbosity') >= 1:
                 print "Cleaning generated assets..."
                 
         for bundle in bundles:
             file_path = abspath(bundle.output)
             if os.path.exists(file_path):
                 os.unlink(file_path)
                 
                 if options.get('verbosity') >= 1:
                     print "Deleted asset: %s" % bundle.output
     except KeyboardInterrupt:
         pass