MCPcopy
hub / github.com/django/django / find_files

Method find_files

django/core/management/commands/makemessages.py:530–583  ·  view source on GitHub ↗

Get all files in the given root. Also check that there is a matching locale dir for each file.

(self, root)

Source from the content-addressed store, hash-verified

528 os.unlink(pot_path)
529
530 def find_files(self, root):
531 """
532 Get all files in the given root. Also check that there is a matching
533 locale dir for each file.
534 """
535 all_files = []
536 ignored_roots = []
537 if self.settings_available:
538 ignored_roots = [
539 os.path.normpath(p)
540 for p in (settings.MEDIA_ROOT, settings.STATIC_ROOT)
541 if p
542 ]
543 for dirpath, dirnames, filenames in os.walk(
544 root, topdown=True, followlinks=self.symlinks
545 ):
546 for dirname in dirnames[:]:
547 if (
548 is_ignored_path(
549 os.path.normpath(os.path.join(dirpath, dirname)),
550 self.ignore_patterns,
551 )
552 or os.path.join(os.path.abspath(dirpath), dirname) in ignored_roots
553 ):
554 dirnames.remove(dirname)
555 if self.verbosity > 1:
556 self.stdout.write("ignoring directory %s" % dirname)
557 elif dirname == "locale":
558 dirnames.remove(dirname)
559 locale_dir = os.path.join(os.path.abspath(dirpath), dirname)
560 if locale_dir in self.locale_paths:
561 self.locale_paths.remove(locale_dir)
562 self.locale_paths.insert(0, locale_dir)
563 for filename in filenames:
564 file_path = os.path.normpath(os.path.join(dirpath, filename))
565 file_ext = os.path.splitext(filename)[1]
566 if file_ext not in self.extensions or is_ignored_path(
567 file_path, self.ignore_patterns
568 ):
569 if self.verbosity > 1:
570 self.stdout.write(
571 "ignoring file %s in %s" % (filename, dirpath)
572 )
573 else:
574 locale_dir = None
575 for path in self.locale_paths:
576 if os.path.abspath(dirpath).startswith(os.path.dirname(path)):
577 locale_dir = path
578 break
579 locale_dir = locale_dir or self.default_locale_path or NO_LOCALE_DIR
580 all_files.append(
581 self.translatable_file_class(dirpath, filename, locale_dir)
582 )
583 return sorted(all_files)
584
585 def process_files(self, file_list):
586 """

Callers 2

build_potfilesMethod · 0.95

Calls 7

is_ignored_pathFunction · 0.90
insertMethod · 0.80
splitextMethod · 0.80
joinMethod · 0.45
removeMethod · 0.45
writeMethod · 0.45
appendMethod · 0.45

Tested by 1