本文整理匯總了Python中django.contrib.staticfiles.finders.get_finders方法的典型用法代碼示例。如果您正苦於以下問題:Python finders.get_finders方法的具體用法?Python finders.get_finders怎麽用?Python finders.get_finders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.contrib.staticfiles.finders
的用法示例。
在下文中一共展示了finders.get_finders方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: check_finders
# 需要導入模塊: from django.contrib.staticfiles import finders [as 別名]
# 或者: from django.contrib.staticfiles.finders import get_finders [as 別名]
def check_finders(app_configs=None, **kwargs):
"""Check all registered staticfiles finders."""
errors = []
for finder in get_finders():
try:
finder_errors = finder.check()
except NotImplementedError:
pass
else:
errors.extend(finder_errors)
return errors
示例2: find_all_files
# 需要導入模塊: from django.contrib.staticfiles import finders [as 別名]
# 或者: from django.contrib.staticfiles.finders import get_finders [as 別名]
def find_all_files(glob):
"""
Finds all files in the django finders for a given glob,
returns the file path, if available, and the django storage object.
storage objects must implement the File storage API:
https://docs.djangoproject.com/en/dev/ref/files/storage/
"""
for finder in finders.get_finders():
for path, storage in finder.list([]):
if fnmatch.fnmatchcase(os.path.join(getattr(storage, 'prefix', '')
or '', path),
glob):
yield path, storage
示例3: find_files
# 需要導入模塊: from django.contrib.staticfiles import finders [as 別名]
# 或者: from django.contrib.staticfiles.finders import get_finders [as 別名]
def find_files():
# copied from django.contrib.staticfiles.management.commands.collectstatic
found_files = OrderedDict()
for finder in get_finders():
for path, storage in finder.list([]):
path = path.replace('\\', '/')
if path not in found_files:
found_files[path] = (storage, path)
return found_files
示例4: test_override_staticfiles_finders
# 需要導入模塊: from django.contrib.staticfiles import finders [as 別名]
# 或者: from django.contrib.staticfiles.finders import get_finders [as 別名]
def test_override_staticfiles_finders(self):
"""
Overriding the STATICFILES_FINDERS setting should be reflected in
the return value of django.contrib.staticfiles.finders.get_finders.
"""
current = get_finders()
self.assertGreater(len(list(current)), 1)
finders = ['django.contrib.staticfiles.finders.FileSystemFinder']
with self.settings(STATICFILES_FINDERS=finders):
self.assertEqual(len(list(get_finders())), len(finders))
示例5: collect
# 需要導入模塊: from django.contrib.staticfiles import finders [as 別名]
# 或者: from django.contrib.staticfiles.finders import get_finders [as 別名]
def collect(self):
"""
Perform the bulk of the work of collectstatic.
Split off from handle() to facilitate testing.
"""
if self.symlink and 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 = OrderedDict()
for finder in 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
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)
for original_path, processed_path, processed in processor:
if isinstance(processed, Exception):
self.stderr.write("Post-processing '%s' failed!" % original_path)
# Add a blank line before the traceback, otherwise it's
# too easy to miss the relevant part of the error message.
self.stderr.write("")
raise processed
if processed:
self.log("Post-processed '%s' as '%s'" %
(original_path, processed_path), level=1)
self.post_processed_files.append(original_path)
else:
self.log("Skipped post-processing '%s'" % original_path)
return {
'modified': self.copied_files + self.symlinked_files,
'unmodified': self.unmodified_files,
'post_processed': self.post_processed_files,
}
示例6: collect
# 需要導入模塊: from django.contrib.staticfiles import finders [as 別名]
# 或者: from django.contrib.staticfiles.finders import get_finders [as 別名]
def collect(self):
"""
Perform the bulk of the work of collectstatic.
Split off from handle() to facilitate testing.
"""
if self.symlink and 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 = OrderedDict()
for finder in 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
if prefixed_path not in found_files:
found_files[prefixed_path] = (storage, path)
handler(path, prefixed_path, storage)
else:
self.log(
"Found another file with the destination path '%s'. It "
"will be ignored since only the first encountered file "
"is collected. If this is not what you want, make sure "
"every static file has a unique path." % prefixed_path,
level=1,
)
# Storage backends may define a post_process() method.
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 isinstance(processed, Exception):
self.stderr.write("Post-processing '%s' failed!" % original_path)
# Add a blank line before the traceback, otherwise it's
# too easy to miss the relevant part of the error message.
self.stderr.write("")
raise processed
if processed:
self.log("Post-processed '%s' as '%s'" %
(original_path, processed_path), level=2)
self.post_processed_files.append(original_path)
else:
self.log("Skipped post-processing '%s'" % original_path)
return {
'modified': self.copied_files + self.symlinked_files,
'unmodified': self.unmodified_files,
'post_processed': self.post_processed_files,
}
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:63,代碼來源:collectstatic.py
示例7: collect
# 需要導入模塊: from django.contrib.staticfiles import finders [as 別名]
# 或者: from django.contrib.staticfiles.finders import get_finders [as 別名]
def collect(self):
"""
Load and save ``PageColorScheme`` for every ``PageTheme``
.. code-block:: bash
static/themes/bootswatch/united/variables.scss
static/themes/bootswatch/united/styles.scss
"""
self.ignore_patterns = [
'*.png', '*.jpg', '*.js', '*.gif', '*.ttf', '*.md', '*.rst',
'*.svg']
page_themes = PageTheme.objects.all()
for finder in get_finders():
for path, storage in finder.list(self.ignore_patterns):
for t in page_themes:
static_path = 'themes/{0}'.format(t.name.split('/')[-1])
if static_path in path:
try:
page_theme = PageTheme.objects.get(id=t.id)
except PageTheme.DoesNotExist:
raise Exception(
"Run sync_themes before this command")
except Exception as e:
self.stdout.write(
"Cannot load {} into database original error: {}".format(t, e))
# find and load skins
skins_path = os.path.join(
storage.path('/'.join(path.split('/')[0:-1])))
for dirpath, skins, filenames in os.walk(skins_path):
for skin in [s for s in skins if s not in ['fonts']]:
for skin_dirpath, skins, filenames in os.walk(os.path.join(dirpath, skin)):
skin, created = PageColorScheme.objects.get_or_create(
theme=page_theme, label=skin, name=skin.title())
for f in filenames:
if 'styles' in f:
with codecs.open(os.path.join(skin_dirpath, f)) as style_file:
skin.styles = style_file.read()
elif 'variables' in f:
with codecs.open(os.path.join(skin_dirpath, f)) as variables_file:
skin.variables = variables_file.read()
skin.save()
self.skins_updated += 1
self.page_themes_updated += len(page_themes)