Ejemplo n.º 1
0
 def _traverse(self, directory, dirs_seen, ignore_file, callback):
     try:
         entries = os.listdir(directory)
     except (OSError):
         entries = None
     if entries:
         try:
             f = open(os.path.join(directory, '.snapopen_ignore'), 'r')
             lines = f.readlines()
             f.close()
             ignore_file = IgnoreFile(directory, lines, ignore_file)
         except (IOError):
             pass
         for entry in sorted(entries):
             if entry.startswith('.'):
                 # Ignore hidden files.
                 continue
             path = os.path.join(directory, entry)
             real_path = os.path.realpath(path)
             norm_path = os.path.normcase(os.path.normpath(path))
             if ignore_file and ignore_file.match(norm_path):
                 continue
             if os.path.isdir(norm_path):
                 if real_path in dirs_seen:
                     # Make sure we don't follow cyclic symlinks.
                     continue
                 else:
                     dirs_seen.add(real_path)
                     self._traverse(norm_path, dirs_seen, ignore_file,
                                    callback)
             else:
                 rel_path = relpath(norm_path, self.directory)
                 if not self.pattern or fnmatch.fnmatch(
                         rel_path.lower(), self.pattern):
                     callback(rel_path)
	def _traverse(self, directory, dirs_seen, ignore_file, callback):
		try:
			entries = os.listdir(directory)
		except (OSError):
			entries = None
		if entries:
			try:
				f = open(os.path.join(directory, '.snapopen_ignore'), 'r')
				lines = f.readlines()
				f.close()
				ignore_file = IgnoreFile(directory, lines, ignore_file)
			except (IOError):
				pass
			for entry in sorted(entries):
				if entry.startswith('.'):
					# Ignore hidden files.
					continue
				path      = os.path.join(directory, entry)
				real_path = os.path.realpath(path)
				norm_path = os.path.normcase(os.path.normpath(path))
				if ignore_file and ignore_file.match(norm_path):
					continue
				if os.path.isdir(norm_path):
					if real_path in dirs_seen:
						# Make sure we don't follow cyclic symlinks.
						continue
					else:
						dirs_seen.add(real_path)
						self._traverse(norm_path, dirs_seen, ignore_file, callback)
				else:
					rel_path = relpath(norm_path, self.directory)
					if not self.pattern or fnmatch.fnmatch(rel_path.lower(), self.pattern):
						callback(rel_path)
Ejemplo n.º 3
0
 def test_autodetection_of_dir_rules(self):
     tempdir = tempfile.mkdtemp()
     old_cwd = os.getcwd()
     try:
         os.makedirs(os.path.join(tempdir, "ruby", "rdoc"))
         os.chdir(tempdir)
         self.assert_(IgnoreFile("ruby", "rdoc").match("ruby/rdoc"))
         self.assert_(
             IgnoreFile("ruby", "rdoc").match("ruby/rdoc/index.html"))
         self.assert_(
             IgnoreFile("ruby",
                        "rdoc").match("ruby/rdoc/classes/index.html"))
         self.assert_(
             not IgnoreFile("ruby", "rdoc").match("foo/rdoc/index.html"))
     finally:
         shutil.rmtree(tempdir)
         os.chdir(old_cwd)
Ejemplo n.º 4
0
 def test_entry_for_directory_matches_subfiles_and_subdirectories(self):
     self.assert_(IgnoreFile(".", "folder/").match("folder"))
     self.assert_(IgnoreFile(".", "folder/").match("folder/file1.txt"))
     self.assert_(IgnoreFile(".", "folder/").match("folder/file2.txt"))
     self.assert_(
         IgnoreFile(".", "folder/").match("folder/subfolder/banana.jpg"))
     self.assert_(not IgnoreFile(".", "folder/").match("another_folder"))
     # TODO: the following is not implemented yet. Not very important
     # but would be nice to have.
     self.assert_(IgnoreFile(".", "folder/").match("foo/folder/banana.jpg"))
Ejemplo n.º 5
0
 def test_matches_only_files_and_directories_in_its_own_directory(self):
     self.assert_(not IgnoreFile("ruby/rdoc", "*.html").match("index.html"))
     self.assert_(
         IgnoreFile("ruby/rdoc", "*.html").match("ruby/rdoc/index.html"))
     self.assert_(
         IgnoreFile("ruby/rdoc",
                    "*.html").match("ruby/rdoc/classes/String.html"))
     self.assert_(
         IgnoreFile("ruby/rdoc", "/*.html").match("ruby/rdoc/index.html"))
     self.assert_(not IgnoreFile("ruby/rdoc", "/*.html").match(
         "ruby/rdoc/classes/String.html"))
     self.assert_(
         IgnoreFile("ruby", "/rdoc/").match("ruby/rdoc/index.html"))
     self.assert_(not IgnoreFile("ruby/rdoc", "/ruby/rdoc/").match(
         "ruby/rdoc/classes/index.html"))
Ejemplo n.º 6
0
 def test_pattern_with_slash(self):
     self.assert_(IgnoreFile(".", "/*.txt").match("foo.txt"))
     self.assert_(not IgnoreFile(".", "/*.txt").match("tmp/foo.txt"))
Ejemplo n.º 7
0
 def test_empty_ignore_file_matches_nothing(self):
     self.assert_(not IgnoreFile(".", "").match("foo.txt"))