def dah_doctor(self): """ That's the doctor, it detect wrong stuff but can never heal you. Pretty big function indeed : 1/ Will do a call to undiff, then initialize the preprocessing stuff. 2/ Then, initialize each reader with the appropriate config 3/ Then, parse each lua file searching for function and content """ from readers import fleet from readers import ship from readers import outfit from readers import unidiff from readers.preprocessing import tech udata = unidiff(datpath=self.config['datpath'], verbose=self.config['verbose']) # This will do some preprocessing check in the xml files print('Preprocess valitation :') otech = tech(unidiffobj=udata, **self.config) # TODO: must be called when needed fleetdata = fleet(datpath=self.config['datpath'], verbose=self.config['verbose']) shipdata = ship(datpath=self.config['datpath'], verbose=self.config['verbose'], tech=otech, fleetobj=fleetdata) outfitdata = outfit(datpath=self.config['datpath'], verbose=self.config['verbose'], tech=otech) rawstr = r""" (?P<func> pilot\.add\(| pilot\.addRaw\(| player\.addShip\(| addOutfit\(| diff\.apply\(| scom\.addPilot\()\s* (?P<hackery>pilots,| )\s*"(?P<content>[^"]+)""" search_cobj = re.compile(rawstr, re.VERBOSE | re.UNICODE) entry = dict() errors = list() # XXX This variable will stock all the lua files. This could lead to a # massive memory consumption. line = dict() print("Blind check now ...") for file in self.luaScripts: if self.config['verbose']: print("Processing file {0}...".format(file), end=' ') if len(errors) > 0: for error in errors: print(error, file=sys.stderr) errors = list() try: line[file] = open(file, 'rU').read() haserror = False for match in search_cobj.finditer(line[file]): lineno, offset = lineNumber(line[file], match.start()) info = dict(lineno=lineno, offset=offset, func=match.group('func')[:-1], content=match.group('content'), file=file) if info['func'] == 'pilot.add': if not fleetdata.find(info['content']): haserror = True if info['func'] == 'scom.addPilot': if not fleetdata.find(info['content']): haserror = True if info['func'] == 'pilot.addRaw': if not shipdata.find(info['content']): haserror = True if info['func'] == 'addOutfit': if not outfitdata.find(info['content']): haserror = True if info['func'] == 'player.addShip': if not shipdata.find(info['content']): haserror = True if info['func'] == 'diff.apply': if not udata.find(info['content']): haserror = True if haserror: errors.append(self._errorstring % info) haserror = False except IOError as error: print("I/O error: {0}".format(error), file=sys.stderr) except: raise if self.config['verbose']: print("DONE") print('Verifying ...') unused_data = dict() # makes sure that only category with unused stuff get listed tocheck = ((fleetdata, 'fleet'), (udata, 'unidiff'), (shipdata, 'ship'), (outfitdata, 'outfit')) for obj, key in tocheck: tmp = obj.get_unused() if len(tmp) > 0: unused_data.update({key: tmp}) del (tmp) if len(unused_data) > 0: # Create the regex mcobj = dict() for (category, data) in unused_data.items(): regex = r""" (?P<{0}>%s) """.format(category) rname = '' uniqList = list() for name in data: name = name.replace(' ', "\s") rname = rname + name + '|' if name not in uniqList: uniqList.append(name) regex = regex % rname[:-1] mcobj.update( {category: re.compile(regex, re.VERBOSE | re.UNICODE)}) # For each file, run each regex # If an item is found, that item is set to the unknown status for (file, content) in line.items(): for (category, cobj) in mcobj.items(): for match in cobj.finditer(content): groups = match.groupdict() for (obj, key) in tocheck: if key == category: obj.set_unknown(groups[category]) outfitdata.showMissingTech() shipdata.showMissingTech() if self.config['show_unused']: # XXX there is no real needs to use these two because of # ''showMissingTech`` called earlier, unless something is tagged as # 'UNKNOWN' outfitdata.show_unused() shipdata.show_unused() fleetdata.show_unused() udata.show_unused()
def dah_doctor(self): """ That's the doctor, it detect wrong stuff but can never heal you. Pretty big function indeed : 1/ Will do a call to undiff, then initialize the preprocessing stuff. 2/ Then, initialize each reader with the appropriate config 3/ Then, parse each lua file searching for function and content """ from readers import fleet from readers import ship from readers import outfit from readers import unidiff from readers.preprocessing import tech udata = unidiff(datpath=self.config['datpath'], verbose=self.config['verbose']) # This will do some preprocessing check in the xml files print('Preprocess valitation :') otech = tech(unidiffobj=udata,**self.config) # TODO: must be called when needed fleetdata = fleet(datpath=self.config['datpath'], verbose=self.config['verbose']) shipdata = ship(datpath=self.config['datpath'], verbose=self.config['verbose'], tech=otech, fleetobj=fleetdata) outfitdata = outfit(datpath=self.config['datpath'], verbose=self.config['verbose'], tech=otech) rawstr = r""" (?P<func> pilot\.add\(| pilot\.addRaw\(| player\.addShip\(| addOutfit\(| diff\.apply\(| scom\.addPilot\()\s* (?P<hackery>pilots,| )\s*"(?P<content>[^"]+)""" search_cobj = re.compile(rawstr, re.VERBOSE| re.UNICODE) entry = dict() errors = list() # XXX This variable will stock all the lua files. This could lead to a # massive memory consumption. line = dict() print("Blind check now ...") for file in self.luaScripts: if self.config['verbose']: print("Processing file {0}...".format(file), end=' ') if len(errors) > 0: for error in errors: print(error, file=sys.stderr) errors = list() try: line[file] = open(file, 'rU').read() haserror=False for match in search_cobj.finditer(line[file]): lineno, offset = lineNumber(line[file], match.start()) info = dict( lineno=lineno, offset=offset, func=match.group('func')[:-1], content= match.group('content'), file=file ) if info['func'] == 'pilot.add': if not fleetdata.find(info['content']): haserror=True if info['func'] == 'scom.addPilot': if not fleetdata.find(info['content']): haserror=True if info['func'] == 'pilot.addRaw': if not shipdata.find(info['content']): haserror=True if info['func'] == 'addOutfit': if not outfitdata.find(info['content']): haserror=True if info['func'] == 'player.addShip': if not shipdata.find(info['content']): haserror=True if info['func'] == 'diff.apply': if not udata.find(info['content']): haserror=True if haserror: errors.append(self._errorstring % info) haserror=False except IOError as error: print("I/O error: {0}".format(error), file=sys.stderr) except: raise if self.config['verbose']: print("DONE") print('Verifying ...') unused_data = dict() # makes sure that only category with unused stuff get listed tocheck = ((fleetdata, 'fleet'), (udata,'unidiff'), (shipdata, 'ship'), (outfitdata, 'outfit')) for obj, key in tocheck: tmp = obj.get_unused() if len(tmp) > 0: unused_data.update({key: tmp}) del(tmp) if len(unused_data) > 0: # Create the regex mcobj = dict() for (category, data) in unused_data.items(): regex = r""" (?P<{0}>%s) """.format(category) rname = '' uniqList = list() for name in data: name = name.replace(' ', "\s") rname = rname + name + '|' if name not in uniqList: uniqList.append(name) regex = regex % rname[:-1] mcobj.update({category: re.compile(regex, re.VERBOSE| re.UNICODE)}) # For each file, run each regex # If an item is found, that item is set to the unknown status for (file, content) in line.items(): for (category, cobj) in mcobj.items(): for match in cobj.finditer(content): groups = match.groupdict() for (obj, key) in tocheck: if key == category: obj.set_unknown(groups[category]) outfitdata.showMissingTech() shipdata.showMissingTech() if self.config['show_unused']: # XXX there is no real needs to use these two because of # ''showMissingTech`` called earlier, unless something is tagged as # 'UNKNOWN' outfitdata.show_unused() shipdata.show_unused() fleetdata.show_unused() udata.show_unused()