Beispiel #1
0
    def set_escape_trailing_spaces_readonly(self, rp):
        """Determine if directory at rp permits filenames with trailing
		spaces or periods without writing."""
        def test_period(dir_rp, dirlist):
            """Return 1 if trailing spaces and periods should be escaped"""
            filename = dirlist[0]
            try:
                test_rp = dir_rp.append(filename)
            except OSError:
                return 0
            assert test_rp.lstat(), test_rp
            period = filename + '.'
            if period in dirlist: return 0

            period_rp = dir_rp.append(period)
            if period_rp.lstat(): return 1
            return 0

        dirlist = robust.listrp(rp)
        if len(dirlist):
            self.escape_trailing_spaces = test_period(rp, dirlist)
        else:
            log.Log(
                "Warning: could not determine if source directory at\n  " +
                rp.path + "\npermits trailing spaces or periods in "
                "filenames because we can't find any files.\n"
                "It will be treated as permitting such files.", 2)
            self.escape_trailing_spaces = 0
Beispiel #2
0
	def set_escape_trailing_spaces_readonly(self, rp):
		"""Determine if directory at rp permits filenames with trailing
		spaces or periods without writing."""

		def test_period(dir_rp, dirlist):
			"""Return 1 if trailing spaces and periods should be escaped"""
			filename = dirlist[0]
			try:
				test_rp = dir_rp.append(filename)
			except OSError:
				return 0
			assert test_rp.lstat(), test_rp
			period = filename + '.' 
			if period in dirlist: return 0 

			period_rp = dir_rp.append(period)
			if period_rp.lstat(): return 1
			return 0

		dirlist = robust.listrp(rp)
		if len(dirlist):
			self.escape_trailing_spaces = test_period(rp, dirlist)
		else:
			log.Log("Warning: could not determine if source directory at\n  "
					+ rp.path + "\npermits trailing spaces or periods in "
					"filenames because we can't find any files.\n"
					"It will be treated as permitting such files.", 2)
			self.escape_trailing_spaces = 0
		def find_letter(subdir):
			"""Find a (subdir_rp, dirlist) with a letter in it, or None

			Recurse down the directory, looking for any file that has
			a letter in it.  Return the pair (rp, [list of filenames])
			where the list is of the directory containing rp.

			"""
			l = robust.listrp(subdir)
			for filename in l:
				if filename != filename.swapcase():
					return (subdir, l, filename)
			for filename in l:
				dir_rp = subdir.append(filename)
				if dir_rp.isdir():
					subsearch = find_letter(dir_rp)
					if subsearch: return subsearch
			return None