Example #1
0
    def __init__(self, conf):
        """
        Initialize a bundle and it's BundleFiles based on a conf dict
        """
        self.name = conf[0]

        conf_dict = conf[1]

        # Basic settings and defaults
        self.bundle_type = conf_dict['type']
        self.files_url_root = conf_dict.get('files_url_root', settings.MEDIA_URL)
        self.files_root = conf_dict.get('files_root', settings.MEDIA_ROOT)
        self.uglify_command = conf_dict.get('uglify_command')
        self.source_map_file_root = conf_dict.get('source_map_file_root')
        self.source_map_url_root = conf_dict.get('source_map_url_root')
        self.source_map_files_url_root = conf_dict.get('source_map_files_url_root') or self.files_url_root
        self.media = conf_dict.get('media')
        self.bundle_url_root = conf_dict.get('bundle_url_root') or self.files_url_root
        self.bundle_file_root = conf_dict.get('bundle_file_root') or self.files_root
        self.bundle_filename = conf_dict.get('bundle_filename') or self.name
        self.precompile_in_debug = False if bundles_settings.GLOBAL_PRECOMPILE_DISABLE else conf_dict.get('precompile_in_debug', False)
        self.fixed_bundle_url = conf_dict.get('bundle_url')
        self.fixed_bundle_file_path = conf_dict.get('bundle_file_path')

        # Build the list of BundleFiles
        self.files = []
        self._bundle_files = {}

        for fileconf in list(conf_dict['files']):
            path, extra = fileconf, None
            # Each file definition can be a string or tuple containing the path and the conf dict
            if isinstance(fileconf, (tuple, list)):
                path = fileconf[0]
                extra = fileconf[1]

            # Expand *s in filenames
            try:
                for filename in expand_file_names(path, self.files_root):
                    bundle_file = BundleFile(filename, self.files_root, self.files_url_root, self.media, self.bundle_type, self.precompile_in_debug, extra=extra)
                    self.files.append(bundle_file)
                    self._bundle_files[bundle_file.file_path] = bundle_file
            except OSError:
                raise ImproperlyConfigured("Bundle %s - could not find file(s): %s" % (self.name, path))

        # Get the processors or use the default list
        if 'processors' in conf_dict:
            self.processors = processor_library.get_processors(conf_dict['processors'])
        else:
            self.processors = processor_library.get_default_postprocessors_for(self.bundle_type)
Example #2
0
    def __init__(self, conf):
        """
        Initialize a bundle and it's BundleFiles based on a conf dict
        """
        self.name = conf[0]

        conf_dict = conf[1]

        # Basic settings and defaults
        self.bundle_type = conf_dict['type']
        self.files_url_root = conf_dict.get('files_url_root', settings.MEDIA_URL)
        self.files_root = conf_dict.get('files_root', settings.MEDIA_ROOT)
        self.uglify_command = conf_dict.get('uglify_command')
        self.source_map_file_root = conf_dict.get('source_map_file_root')
        self.source_map_url_root = conf_dict.get('source_map_url_root')
        self.source_map_files_url_root = conf_dict.get('source_map_files_url_root') or self.files_url_root
        self.media = conf_dict.get('media')
        self.bundle_url_root = conf_dict.get('bundle_url_root') or self.files_url_root
        self.bundle_file_root = conf_dict.get('bundle_file_root') or self.files_root
        self.bundle_filename = conf_dict.get('bundle_filename') or self.name
        self.create_debug = conf_dict.get('debug', False)

        # Build the list of BundleFiles
        self.files = []
        self._bundle_files = {}

        for fileconf in list(conf_dict['files']):
            path, extra = fileconf, None
            # Each file definition can be a string or tuple containing the path and the conf dict
            if isinstance(fileconf, (tuple, list)):
                path = fileconf[0]
                extra = fileconf[1]

            # Expand *s in filenames
            try:
                for filename in expand_file_names(path, self.files_root):
                    bundle_file = BundleFile(filename, self.files_root, self.files_url_root, self.media, self.bundle_type, extra=extra)
                    self.files.append(bundle_file)
                    self._bundle_files[bundle_file.file_path] = bundle_file
            except OSError:
                raise ImproperlyConfigured("Bundle %s - could not find file(s): %s" % (self.name, path))

        # Get the processors or use the default list
        if 'processors' in conf_dict:
            self.processors = processor_library.get_processors(conf_dict['processors'])
        else:
            self.processors = processor_library.get_default_postprocessors_for(self.bundle_type)
    def handle(self, *args, **options):
        self.stdout.write("Bundling...\n")
        dev_mode = bool(options.get('dev'))

        _bundle_versions = {}
        set_bundle_versions(_bundle_versions)

        for bundle in get_bundles():
            self.stdout.write("Writing bundle: %s\n" % bundle.name)

            if bundle.uglify_command:
                hash_version = make_uglify_bundle(bundle, fixed_version='_' if dev_mode else None)
            else:
                hash_version = make_bundle(bundle, fixed_version='_' if dev_mode else None)

            # Build bundle versions as we're going along in case they're used in templated bundles
            _bundle_versions[bundle.name] = hash_version

            if bundle.create_debug:
                if bundle.uglify_command:
                    _bundle_versions['debug:' + bundle.name] = make_uglify_bundle(bundle, debug=True)
                else:
                    _bundle_versions['debug:' + bundle.name] = make_bundle(bundle, debug=True)

            self.stdout.write("\t%s\n" % bundle.get_version())

        version_info = '\n'.join(['    "%s": "%s",' % version for version in _bundle_versions.iteritems()])

        with open(bundles_settings.BUNDLES_VERSION_FILE, 'wb') as bundles_versions:
            bundles_versions.write("""\
#!/usr/bin/env python

BUNDLES_VERSIONS = {
%s
}
""" % version_info)

        for single_file_input, single_file_output in bundles_settings.BUNDLES_SINGLE_FILES:
            self.stdout.write("Writing: %s\n" % single_file_output)
            file_type = os.path.splitext(single_file_input)[1][1:]
            processors = processor_library.get_default_preprocessors_for(file_type) + processor_library.get_default_postprocessors_for(file_type)

            with open(single_file_output, 'wb') as output_file:
                for chunk in processor_pipeline(processors, FileChunkGenerator(open(single_file_input, 'rb'))):
                    output_file.write(chunk)

        self.stdout.write("Done.\n")
Example #4
0
    def handle(self, *args, **options):
        self.stdout.write("Bundling...\n")
        dev_mode = bool(options.get('dev'))

        _bundle_versions = {}
        set_bundle_versions(_bundle_versions)

        if options.get('parallel'):
            self.stdout.write("Writing bundles in parallel\n")
            pool = Pool()
            results = pool.map(do_make_bundle, [
                (bundle, '_' if dev_mode else None)
                for bundle in get_bundles()
            ])
            pool.close()
            pool.join()

            for bundle_name, hash_version in results:
                _bundle_versions[bundle_name] = hash_version
        else:
            for bundle in get_bundles():
                self.stdout.write("Writing bundle: %s\n" % bundle.name)

                _, hash_version = do_make_bundle((bundle, '_' if dev_mode else None))
                # Build bundle versions as we're going along in case they're used in templated bundles
                _bundle_versions[bundle.name] = hash_version

                self.stdout.write("\t%s\n" % bundle.get_version())

        version_info = '\n'.join(['    "%s": "%s",' % version for version in _bundle_versions.iteritems()])

        with open(bundles_settings.BUNDLES_VERSION_FILE, 'wb') as bundles_versions:
            bundles_versions.write("""\
#!/usr/bin/env python

BUNDLES_VERSIONS = {
%s
}
""" % version_info)

        for single_file_input, single_file_output in bundles_settings.BUNDLES_SINGLE_FILES:
            self.stdout.write("Writing: %s\n" % single_file_output)
            file_type = os.path.splitext(single_file_input)[1][1:]
            processors = processor_library.get_default_preprocessors_for(file_type) + processor_library.get_default_postprocessors_for(file_type)

            with open(single_file_output, 'wb') as output_file:
                for chunk in processor_pipeline(processors, FileChunkGenerator(open(single_file_input, 'rb'))):
                    output_file.write(chunk)

        self.stdout.write("Done.\n")