Beispiel #1
0
 def listdir(self, path):
     for finder in finders.get_finders():
         for storage in finder.storages.values():
             try:
                 return storage.listdir(path)
             except OSError:
                 pass
Beispiel #2
0
 def listdir(self, path):
     for finder in finders.get_finders():
         for storage in finder.storages.values():
             try:
                 return storage.listdir(path)
             except OSError:
                 pass
Beispiel #3
0
 def find_storage(self, name):
     for finder in finders.get_finders():
         for path, storage in finder.list([]):
             prefix = getattr(storage, "prefix", None)
             matched_path = self.match_location(name, path, prefix)
             if matched_path:
                 return matched_path, storage
     raise ValueError("The file '%s' could not be found with %r." % (name, self))
Beispiel #4
0
 def find_storage(self, name):
     for finder in finders.get_finders():
         for path, storage in finder.list([]):
             if path == name:
                 return storage
             if os.path.splitext(path)[0] == os.path.splitext(name)[0]:
                 return storage
     raise ValueError("The file '%s' could not be found with %r." % (name, self))
Beispiel #5
0
 def find_storage(self, name):
     for finder in finders.get_finders():
         for path, storage in finder.list([]):
             if path == name:
                 return storage
             if os.path.splitext(path)[0] == os.path.splitext(name)[0]:
                 return storage
     return None
Beispiel #6
0
 def find_storage(self, name):
     for finder in finders.get_finders():
         for path, storage in finder.list([]):
             prefix = getattr(storage, 'prefix', None)
             matched_path = self.match_location(name, path, prefix)
             if matched_path:
                 return matched_path, storage
     raise ValueError("The file '%s' could not be found with %r." % (name, self))
Beispiel #7
0
    def collect(self):
        """
        Perform the bulk of the work of collectstatic.

        Split off from handle_noargs() to facilitate testing.
        """
        if self.symlink:
            if sys.platform == 'win32':
                raise CommandError("Symlinking is not supported by this "
                                   "platform (%s)." % sys.platform)
            if not self.local:
                raise CommandError("Can't symlink to a remote destination.")

        if self.clear:
            self.clear_dir('')

        if self.symlink:
            handler = self.link_file
        else:
            handler = self.copy_file

        found_files = SortedDict()
        for finder in finders.get_finders():
            for path, storage in finder.list(self.ignore_patterns):
                # Prefix the relative path if the source storage contains it
                if getattr(storage, 'prefix', None):
                    prefixed_path = os.path.join(storage.prefix, path)
                else:
                    prefixed_path = path
                # Process only not already processed files.
                if prefixed_path not in found_files:
                    found_files[prefixed_path] = (storage, path)
                    handler(path, prefixed_path, storage)

        # Here we check if the storage backend has a post_process
        # method and pass it the list of modified files.
        if self.post_process and hasattr(self.storage, 'post_process'):
            processor = self.storage.post_process(found_files,
                dry_run=self.dry_run, fail_silently=self.fail_silently)
            for original_path, processed_path, processed in processor:
                if processed:
                    self.log(u"Post-processed '%s' as '%s'" %
                             (original_path, processed_path), level=1)
                    self.post_processed_files.append(original_path)
                else:
                    self.log(u"Skipped post-processing '%s'" % original_path)

        return {
            'modified': self.copied_files + self.symlinked_files,
            'unmodified': self.unmodified_files,
            'post_processed': self.post_processed_files,
        }
    def collect(self):
        """
        Perform the bulk of the work of collectstatic.

        Split off from handle_noargs() to facilitate testing.
        """
        if self.symlink:
            if sys.platform == 'win32':
                raise CommandError("Symlinking is not supported by this "
                                   "platform (%s)." % sys.platform)
            if not self.local:
                raise CommandError("Can't symlink to a remote destination.")

        if self.clear:
            self.clear_dir('')

        if self.symlink:
            handler = self.link_file
        else:
            handler = self.copy_file

        found_files = SortedDict()
        for finder in finders.get_finders():
            for path, storage in finder.list(self.ignore_patterns):
                # Prefix the relative path if the source storage contains it
                if getattr(storage, 'prefix', None):
                    prefixed_path = os.path.join(storage.prefix, path)
                else:
                    prefixed_path = path
                found_files[prefixed_path] = (storage, path)
                handler(path, prefixed_path, storage)

        # Here we check if the storage backend has a post_process
        # method and pass it the list of modified files.
        if self.post_process and hasattr(self.storage, 'post_process'):
            processor = self.storage.post_process(found_files,
                                                  dry_run=self.dry_run)
            for original_path, processed_path, processed in processor:
                if processed:
                    self.log(u"Post-processed '%s' as '%s" %
                             (original_path, processed_path),
                             level=1)
                    self.post_processed_files.append(original_path)
                else:
                    self.log(u"Skipped post-processing '%s'" % original_path)

        return {
            'modified': self.copied_files + self.symlinked_files,
            'unmodified': self.unmodified_files,
            'post_processed': self.post_processed_files,
        }
Beispiel #9
0
    def handle_noargs(self, **options):
        symlink = options['link']
        ignore_patterns = options['ignore_patterns']
        if options['use_default_ignore_patterns']:
            ignore_patterns += ['CVS', '.*', '*~']
        ignore_patterns = list(set(ignore_patterns))
        self.verbosity = int(options.get('verbosity', 1))

        if symlink:
            if sys.platform == 'win32':
                raise CommandError("Symlinking is not supported by this "
                                   "platform (%s)." % sys.platform)
            if not self.local:
                raise CommandError("Can't symlink to a remote destination.")

        # Warn before doing anything more.
        if options.get('interactive'):
            confirm = raw_input("""
You have requested to collect static files at the destination
location as specified in your settings file ('%s').

This will overwrite existing files.
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: """ % settings.STATIC_ROOT)
            if confirm != 'yes':
                raise CommandError("Collecting static files cancelled.")

        for finder in finders.get_finders():
            for path, storage in finder.list(ignore_patterns):
                # Prefix the relative path if the source storage contains it
                if getattr(storage, 'prefix', None):
                    prefixed_path = os.path.join(storage.prefix, path)
                else:
                    prefixed_path = path
                
                if symlink:
                    self.link_file(path, prefixed_path, storage, **options)
                else:
                    self.copy_file(path, prefixed_path, storage, **options)

        actual_count = len(self.copied_files) + len(self.symlinked_files)
        unmodified_count = len(self.unmodified_files)
        if self.verbosity >= 1:
            self.stdout.write("\n%s static file%s %s to '%s'%s.\n"
                              % (actual_count, actual_count != 1 and 's' or '',
                                 symlink and 'symlinked' or 'copied',
                                 settings.STATIC_ROOT,
                                 unmodified_count and ' (%s unmodified)'
                                 % unmodified_count or ''))
Beispiel #10
0
 def __init__(self):
     self.packager = Packager()
     self.packages = self.collect_packages()
     self.finders = get_finders()
     self.package_files = self.get_package_files()
Beispiel #11
0
 def _save(self, name, content):
     for finder in finders.get_finders():
         for path, storage in finder.list([]):
             if os.path.dirname(name) in path:
                 return storage._save(name, content)
Beispiel #12
0
    def handle_noargs(self, **options):
        self.clear = options['clear']
        self.dry_run = options['dry_run']
        ignore_patterns = options['ignore_patterns']
        if options['use_default_ignore_patterns']:
            ignore_patterns += ['CVS', '.*', '*~']
        self.ignore_patterns = list(set(ignore_patterns))
        self.interactive = options['interactive']
        self.symlink = options['link']
        self.verbosity = int(options.get('verbosity', 1))
        self.post_process = options['post_process']

        if self.symlink:
            if sys.platform == 'win32':
                raise CommandError("Symlinking is not supported by this "
                                   "platform (%s)." % sys.platform)
            if not self.local:
                raise CommandError("Can't symlink to a remote destination.")

        # Warn before doing anything more.
        if (isinstance(self.storage, FileSystemStorage)
                and self.storage.location):
            destination_path = self.storage.location
            destination_display = ':\n\n    %s' % destination_path
        else:
            destination_path = None
            destination_display = '.'

        if self.clear:
            clear_display = 'This will DELETE EXISTING FILES!'
        else:
            clear_display = 'This will overwrite existing files!'

        if self.interactive:
            confirm = raw_input(u"""
You have requested to collect static files at the destination
location as specified in your settings%s

%s
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: """ %
                                (destination_display, clear_display))
            if confirm != 'yes':
                raise CommandError("Collecting static files cancelled.")

        if self.clear:
            self.clear_dir('')

        handler = {
            True: self.link_file,
            False: self.copy_file,
        }[self.symlink]

        found_files = []
        for finder in finders.get_finders():
            for path, storage in finder.list(self.ignore_patterns):
                # Prefix the relative path if the source storage contains it
                if getattr(storage, 'prefix', None):
                    prefixed_path = os.path.join(storage.prefix, path)
                else:
                    prefixed_path = path
                found_files.append(prefixed_path)
                handler(path, prefixed_path, storage)

        # Here we check if the storage backend has a post_process
        # method and pass it the list of modified files.
        if self.post_process and hasattr(self.storage, 'post_process'):
            post_processed = self.storage.post_process(found_files, **options)
            for path in post_processed:
                self.log(u"Post-processed '%s'" % path, level=1)
        else:
            post_processed = []

        modified_files = self.copied_files + self.symlinked_files
        actual_count = len(modified_files)
        unmodified_count = len(self.unmodified_files)

        if self.verbosity >= 1:
            template = ("\n%(actual_count)s %(identifier)s %(action)s"
                        "%(destination)s%(unmodified)s.\n")
            summary = template % {
                'actual_count':
                actual_count,
                'identifier':
                'static file' + (actual_count > 1 and 's' or ''),
                'action':
                self.symlink and 'symlinked' or 'copied',
                'destination':
                (destination_path and " to '%s'" % destination_path or ''),
                'unmodified':
                (self.unmodified_files and ', %s unmodified' % unmodified_count
                 or ''),
            }
            self.stdout.write(smart_str(summary))
Beispiel #13
0
    def handle_noargs(self, **options):
        self.clear = options['clear']
        self.dry_run = options['dry_run']
        ignore_patterns = options['ignore_patterns']
        if options['use_default_ignore_patterns']:
            ignore_patterns += ['CVS', '.*', '*~']
        self.ignore_patterns = list(set(ignore_patterns))
        self.interactive = options['interactive']
        self.symlink = options['link']
        self.verbosity = int(options.get('verbosity', 1))
        self.post_process = options['post_process']

        if self.symlink:
            if sys.platform == 'win32':
                raise CommandError("Symlinking is not supported by this "
                                   "platform (%s)." % sys.platform)
            if not self.local:
                raise CommandError("Can't symlink to a remote destination.")

        # Warn before doing anything more.
        if (isinstance(self.storage, FileSystemStorage) and
                self.storage.location):
            destination_path = self.storage.location
            destination_display = ':\n\n    %s' % destination_path
        else:
            destination_path = None
            destination_display = '.'

        if self.clear:
            clear_display = 'This will DELETE EXISTING FILES!'
        else:
            clear_display = 'This will overwrite existing files!'

        if self.interactive:
            confirm = raw_input(u"""
You have requested to collect static files at the destination
location as specified in your settings%s

%s
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: """
% (destination_display, clear_display))
            if confirm != 'yes':
                raise CommandError("Collecting static files cancelled.")

        if self.clear:
            self.clear_dir('')

        handler = {
            True: self.link_file,
            False: self.copy_file,
        }[self.symlink]

        found_files = []
        for finder in finders.get_finders():
            for path, storage in finder.list(self.ignore_patterns):
                # Prefix the relative path if the source storage contains it
                if getattr(storage, 'prefix', None):
                    prefixed_path = os.path.join(storage.prefix, path)
                else:
                    prefixed_path = path
                found_files.append(prefixed_path)
                handler(path, prefixed_path, storage)

        # Here we check if the storage backend has a post_process
        # method and pass it the list of modified files.
        if self.post_process and hasattr(self.storage, 'post_process'):
            post_processed = self.storage.post_process(found_files, **options)
            for path in post_processed:
                self.log(u"Post-processed '%s'" % path, level=1)
        else:
            post_processed = []

        modified_files = self.copied_files + self.symlinked_files
        actual_count = len(modified_files)
        unmodified_count = len(self.unmodified_files)

        if self.verbosity >= 1:
            template = ("\n%(actual_count)s %(identifier)s %(action)s"
                        "%(destination)s%(unmodified)s.\n")
            summary = template % {
                'actual_count': actual_count,
                'identifier': 'static file' + (actual_count > 1 and 's' or ''),
                'action': self.symlink and 'symlinked' or 'copied',
                'destination': (destination_path and " to '%s'"
                                % destination_path or ''),
                'unmodified': (self.unmodified_files and ', %s unmodified'
                               % unmodified_count or ''),
            }
            self.stdout.write(smart_str(summary))