コード例 #1
0
 def input(self, filename=None, **kwargs):
     media_root = os.path.normcase(os.path.abspath(settings.MEDIA_ROOT))
     if filename is not None:
         filename = os.path.normcase(os.path.abspath(filename))
     if not filename or not filename.startswith(media_root):
         return self.content
     self.media_path = filename[len(media_root):].replace(os.sep, '/')
     self.media_path = self.media_path.lstrip('/')
     self.media_url = settings.MEDIA_URL.rstrip('/')
     try:
         mtime = get_mtime(filename)
         self.mtime = get_hexdigest(str(int(mtime)))[:12]
     except OSError:
         self.mtime = None
     self.has_http = False
     if self.media_url.startswith('http://') or self.media_url.startswith(
             'https://'):
         self.has_http = True
         parts = self.media_url.split('/')
         self.media_url = '/'.join(parts[2:])
         self.protocol = '%s/' % '/'.join(parts[:2])
     self.directory_name = '/'.join(
         [self.media_url, os.path.dirname(self.media_path)])
     output = URL_PATTERN.sub(self.url_converter, self.content)
     return output
コード例 #2
0
ファイル: mtime_cache.py プロジェクト: gitter-badger/rooibos
    def handle_noargs(self, **options):
        ignore_patterns = options['ignore_patterns']
        if options['use_default_ignore_patterns']:
            ignore_patterns += ['CVS', '.*', '*~']
            options['ignore_patterns'] = ignore_patterns
        self.ignore_patterns = ignore_patterns

        if (options['add'] and options['clean']) or (not options['add']
                                                     and not options['clean']):
            raise CommandError('Please specify either "--add" or "--clean"')

        if not settings.MTIME_DELAY:
            raise CommandError(
                'mtime caching is currently disabled. Please '
                'set the COMPRESS_MTIME_DELAY setting to a number of seconds.')

        files_to_add = set()
        keys_to_delete = set()

        for root, dirs, files in walk(settings.MEDIA_ROOT,
                                      followlinks=options['follow_links']):
            for dir_ in dirs:
                if self.is_ignored(dir_):
                    dirs.remove(dir_)
            for filename in files:
                common = "".join(root.split(settings.MEDIA_ROOT))
                if common.startswith(os.sep):
                    common = common[len(os.sep):]
                if self.is_ignored(os.path.join(common, filename)):
                    continue
                filename = os.path.join(root, filename)
                keys_to_delete.add(get_mtime_cachekey(filename))
                if options['add']:
                    files_to_add.add(filename)

        if keys_to_delete:
            cache.delete_many(list(keys_to_delete))
            print "Deleted mtimes of %d files from the cache." % len(
                keys_to_delete)

        if files_to_add:
            for filename in files_to_add:
                get_mtime(filename)
            print "Added mtimes of %d files to cache." % len(files_to_add)
コード例 #3
0
    def handle_noargs(self, **options):
        ignore_patterns = options["ignore_patterns"]
        if options["use_default_ignore_patterns"]:
            ignore_patterns += ["CVS", ".*", "*~"]
            options["ignore_patterns"] = ignore_patterns
        self.ignore_patterns = ignore_patterns

        if (options["add"] and options["clean"]) or (not options["add"] and not options["clean"]):
            raise CommandError('Please specify either "--add" or "--clean"')

        if not settings.MTIME_DELAY:
            raise CommandError(
                "mtime caching is currently disabled. Please "
                "set the COMPRESS_MTIME_DELAY setting to a number of seconds."
            )

        files_to_add = set()
        keys_to_delete = set()

        for root, dirs, files in os.walk(settings.MEDIA_ROOT, followlinks=options["follow_links"]):
            for dir_ in dirs:
                if self.is_ignored(dir_):
                    dirs.remove(dir_)
            for filename in files:
                common = "".join(root.split(settings.MEDIA_ROOT))
                if common.startswith(os.sep):
                    common = common[len(os.sep) :]
                if self.is_ignored(os.path.join(common, filename)):
                    continue
                filename = os.path.join(root, filename)
                keys_to_delete.add(get_mtime_cachekey(filename))
                if options["add"]:
                    files_to_add.add(filename)

        if keys_to_delete:
            cache.delete_many(list(keys_to_delete))
            print "Deleted mtimes of %d files from the cache." % len(keys_to_delete)

        if files_to_add:
            for filename in files_to_add:
                get_mtime(filename)
            print "Added mtimes of %d files to cache." % len(files_to_add)
コード例 #4
0
ファイル: css_default.py プロジェクト: Blanko2/vic-mdid
 def input(self, filename=None, **kwargs):
     media_root = os.path.normcase(os.path.abspath(settings.MEDIA_ROOT))
     if filename is not None:
         filename = os.path.normcase(os.path.abspath(filename))
     if not filename or not filename.startswith(media_root):
         return self.content
     self.media_path = filename[len(media_root):].replace(os.sep, '/')
     self.media_path = self.media_path.lstrip('/')
     self.media_url = settings.MEDIA_URL.rstrip('/')
     try:
         mtime = get_mtime(filename)
         self.mtime = get_hexdigest(str(int(mtime)))[:12]
     except OSError:
         self.mtime = None
     self.has_http = False
     if self.media_url.startswith('http://') or self.media_url.startswith('https://'):
         self.has_http = True
         parts = self.media_url.split('/')
         self.media_url = '/'.join(parts[2:])
         self.protocol = '%s/' % '/'.join(parts[:2])
     self.directory_name = '/'.join([self.media_url, os.path.dirname(self.media_path)])
     output = URL_PATTERN.sub(self.url_converter, self.content)
     return output
コード例 #5
0
ファイル: base.py プロジェクト: gitter-badger/rooibos
 def mtimes(self):
     return [
         get_mtime(h[1]) for h in self.split_contents() if h[0] == 'file'
     ]
コード例 #6
0
ファイル: base.py プロジェクト: heynemann/django_compressor
 def mtimes(self):
     return [get_mtime(h[1]) for h in self.split_contents() if h[0] == 'file']
コード例 #7
0
ファイル: tests.py プロジェクト: heynemann/django_compressor
 def get_hashed_mtime(self, filename, length=12):
     filename = os.path.realpath(filename)
     mtime = str(int(get_mtime(filename)))
     return get_hexdigest(mtime)[:length]