Пример #1
0
def repair_names(directory):
	for path, dirs, files in os.walk(directory):
		for subdir in dirs:
			subpath = os.path.join(path,subdir)
			for entry in os.listdir(subpath):
				lower_entry = entry.lower()
				if lower_entry != entry:
					print 'renaming',subpath,entry,'->',lower_entry
					os.rename(
						os.path.join(path,subdir,entry),
						os.path.join(path,subdir,lower_entry))
		for filename in files:
			if filename.lower() == 'pony.ini':
				filepath = os.path.join(path,filename)
				print 'repairing',filepath
				buf = []
				for row in parse_file(filepath):
					if type(row) is Row and row.values:
						type_name = row.values[0].lower()
						if type_name == 'behavior':
							row.values[6] = row.values[6].lower()
							row.values[7] = row.values[7].lower()
						elif type_name == 'effect':
							row.values[3] = row.values[3].lower()
							row.values[4] = row.values[4].lower()
						elif type_name == 'speak' and len(row.values) > 3:
							audio = row.values[3]
							if isinstance(audio,list):
								row.values[3] = [filename.lower() for filename in audio]
							else:
								row.values[3] = audio.lower()
					buf.append(unicode(row))
				s = u'\n'.join(buf)
				with open(filepath,'wb') as f:
					f.write(s.encode('utf-8'))
Пример #2
0
	def validate(self):
		ok = True
		for row in parse_file(self.filepath,False):
			if not self.validate_row(row):
				ok = False

		if not self.name:
			self.log("name is not defined")
			ok = False

		if not self.categories:
			self.log("categories are not defined")
			ok = False

		for behavior in self.behaviors:
			linked = behavior.linked
			if linked and linked not in self.behaviors_by_name:
				self.log_behavior(behavior,"linked behavior does not exist:",linked)
				ok = False

			speakstart = behavior.speakstart
			if speakstart and speakstart not in self.speeches:
				self.log_behavior(behavior,"start speak line does not exist:",speakstart)
				ok = False

			speakend = behavior.speakend
			if speakend and speakend not in self.speeches:
				self.log_behavior(behavior,"start speak line does not exist:",speakend)
				ok = False

		for effect in self.effects:
			if effect.behavior not in self.behaviors_by_name:
				self.log_effect(effect,"behavior does not exist:",effect.behavior)
				ok = False

		filenames = os.listdir(self.dirpath)
		filenames.sort()
		for filename in filenames:
			if filename not in self.files:
				if self.remove_not_referenced:
					filepath = os.path.join(self.dirpath,filename)
					if os.path.isdir(filepath):
						shutil.rmtree(filepath)
						self.log("removed not referenced directory:",filename)
					else:
						os.remove(filepath)
						self.log("removed not referenced file:",filename)
				else:
					self.log("not referenced file:",filename)
				ok = False

		return ok
Пример #3
0
def repair_names(path):
    entries = os.listdir(path)

    for entry in entries:
        lower_entry = entry.lower()
        entry_path = os.path.join(path, entry)
        if lower_entry != entry:
            print 'renaming', path, entry, '->', lower_entry
            lower_path = os.path.join(path, lower_entry)
            os.rename(entry_path, lower_path)
            entry = lower_entry
            entry_path = lower_path

        if os.path.isdir(entry_path):
            repair_names(entry_path)
        elif lower_entry == 'pony.ini':
            print 'repairing', entry_path
            m = SPECIAL.match(
                os.path.basename(os.path.dirname(os.path.abspath(entry_path))))
            suffix = m and m.group(1)
            if suffix:
                suffix = " " + suffix.title()
            buf = []
            for row in parse_file(entry_path):
                if type(row) is Row and row.values:
                    type_name = row.values[0].lower()
                    if type_name == 'behavior':
                        row.values[6] = row.values[6].lower()
                        row.values[7] = row.values[7].lower()
                    elif type_name == 'effect':
                        row.values[3] = row.values[3].lower()
                        row.values[4] = row.values[4].lower()
                    elif type_name == 'speak' and len(row.values) > 3:
                        audio = row.values[3]
                        if isinstance(audio, list):
                            row.values[3] = [
                                filename.lower() for filename in audio
                            ]
                        else:
                            row.values[3] = audio.lower()
                    elif suffix and type_name == 'name':
                        name = row.values[1]
                        if not name.endswith(suffix):
                            row.values[1] = name + suffix
                            print 'renamed pony', name, '->', row.values[1]
                buf.append(unicode(row))
            s = u'\n'.join(buf)
            with open(entry_path, 'wb') as f:
                f.write(s.encode('utf-8'))
Пример #4
0
def repair_names(path):
    entries = os.listdir(path)

    for entry in entries:
        lower_entry = entry.lower()
        entry_path = os.path.join(path, entry)
        if lower_entry != entry:
            print "renaming", path, entry, "->", lower_entry
            lower_path = os.path.join(path, lower_entry)
            os.rename(entry_path, lower_path)
            entry = lower_entry
            entry_path = lower_path

        if os.path.isdir(entry_path):
            repair_names(entry_path)
        elif lower_entry == "pony.ini":
            print "repairing", entry_path
            m = SPECIAL.match(os.path.basename(os.path.dirname(os.path.abspath(entry_path))))
            suffix = m and m.group(1)
            if suffix:
                suffix = " " + suffix.title()
            buf = []
            for row in parse_file(entry_path):
                if type(row) is Row and row.values:
                    type_name = row.values[0].lower()
                    if type_name == "behavior":
                        row.values[6] = row.values[6].lower()
                        row.values[7] = row.values[7].lower()
                    elif type_name == "effect":
                        row.values[3] = row.values[3].lower()
                        row.values[4] = row.values[4].lower()
                    elif type_name == "speak" and len(row.values) > 3:
                        audio = row.values[3]
                        if isinstance(audio, list):
                            row.values[3] = [filename.lower() for filename in audio]
                        else:
                            row.values[3] = audio.lower()
                    elif suffix and type_name == "name":
                        name = row.values[1]
                        if not name.endswith(suffix):
                            row.values[1] = name + suffix
                            print "renamed pony", name, "->", row.values[1]
                buf.append(unicode(row))
            s = u"\n".join(buf)
            with open(entry_path, "wb") as f:
                f.write(s.encode("utf-8"))
Пример #5
0
	def validate(self):
		if not os.path.exists(self.filepath):
			self.log("file does not exist")
			return False
			
		if not os.path.isfile(self.filepath):
			self.log("path is not a file")
			return False

		ok = True
		for row in parse_file(self.filepath,False):
			if not self.validate_row(row):
				ok = False

		if not self.name:
			self.log("name is not defined")
			ok = False

		if not self.categories:
			self.log("categories are not defined")
			ok = False

		for behavior in self.behaviors:
			linked = behavior.linked
			if linked and linked not in self.behaviors_by_name:
				self.log_behavior(behavior,"linked behavior does not exist:",linked)
				ok = False

			speakstart = behavior.speakstart
			if speakstart and speakstart not in self.speeches:
				self.log_behavior(behavior,"start speak line does not exist:",speakstart)
				ok = False

			speakend = behavior.speakend
			if speakend and speakend not in self.speeches:
				self.log_behavior(behavior,"start speak line does not exist:",speakend)
				ok = False

		for effect in self.effects:
			if effect.behavior not in self.behaviors_by_name:
				self.log_effect(effect,"behavior does not exist:",effect.behavior)
				ok = False

		illegal_refs = self.grouprefs.difference(self.groups)
		if illegal_refs:
			self.log("referenced behavior groups where not declared:",list(illegal_refs))
			ok = False

		filenames = os.listdir(self.dirpath)
		filenames.sort()
		for filename in filenames:
			if filename not in self.files:
				if self.remove_not_referenced:
					filepath = os.path.join(self.dirpath,filename)
					if os.path.isdir(filepath):
						shutil.rmtree(filepath)
						self.log("removed not referenced directory:",filename)
					else:
						os.remove(filepath)
						self.log("removed not referenced file:",filename)
				else:
					self.log("not referenced file:",filename)
				ok = False

		return ok