Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
removing the old readFile function
Browse files Browse the repository at this point in the history
  • Loading branch information
Gra-tak committed Mar 10, 2018
1 parent 0a55c93 commit 4174c9e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 77 deletions.
2 changes: 1 addition & 1 deletion pythonScripts/convertCSV_TXT.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def main(args,unused=0):
else:
keepExtraLines=False
if not args.to_txt or os.path.exists(fileName):
nameToData.readFileNew(fileName,args, varsToValue)
nameToData.readFile(fileName,args, varsToValue)
else:
# print(fileName)
print("Generating new txt file from {} file. First column in table must be {!s} or addKey depending on file (the unique identifiers)".format(tableFileEnding, keyStrings))
Expand Down
4 changes: 2 additions & 2 deletions pythonScripts/copySubTag.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def main(args,unused=0):
# tagList=TagList(0)

oldEnd=len(sourceEntries.vals)
sourceEntries.readFileNew(fileName,args, varsToValue)
sourceEntries.readFile(fileName,args, varsToValue)
# sourceEntries.printAll()
for entry in sourceEntries[oldEnd:]:
try:
Expand All @@ -79,7 +79,7 @@ def main(args,unused=0):
fileName=args.fileNameTarget
targetEntries=TagList(0)
varsToValue=TagList(0)
targetEntries.readFileNew(fileName,args,varsToValue)
targetEntries.readFile(fileName,args,varsToValue)
missing=[]

keyStrings=["key","name","id"]
Expand Down
2 changes: 1 addition & 1 deletion pythonScripts/createAIVarsFromModifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def parse(argv):
def main(args):
varsToValue=TagList(0)
inputTagList=TagList(0)
inputTagList.readFileNew(args.inputfileName,args, varsToValue)
inputTagList.readFile(args.inputfileName,args, varsToValue)
outTagList=TagList(0)
outTagList.add("check_planet_modifiers", TagList(1))
# outTagTemplate=TagList(2)
Expand Down
2 changes: 1 addition & 1 deletion pythonScripts/createUpgradedBuildings.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def readAndConvert(args, allowRestart=1):
buildingNameToData=TagList(0)
args.preventLinePrint=[]
prevLen=len(buildingNameToData.vals)
buildingNameToData.readFileNew(buildingFileName,args, varsToValue,True)
buildingNameToData.readFile(buildingFileName,args, varsToValue,True)
if isHelperFileItList: #mark helper buildings
if thisFileIsAHelper:
for b in buildingNameToData[prevLen:]:
Expand Down
2 changes: 1 addition & 1 deletion pythonScripts/readAndWriteTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def main(args):
args.preventLinePrint=[]
varsToValue=TagList(0)
taglist=TagList(0)
taglist.readFileNew(args.inputfileName,args, varsToValue,True)
taglist.readFile(args.inputfileName,args, varsToValue,True)
# taglist.printAll()
with open(args.outputfileName,'w') as file:
taglist.writeAll(file,args)
Expand Down
79 changes: 8 additions & 71 deletions pythonScripts/stellarisTxtRead.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ def applyOnLowestLevel(self, func, argList=[],attributeList=[]):
i+=1
if i==len(self.vals):
break
def readFileNew(self, fileName, args, varsToValue,useNamedTagList=False):#,"@"]):

def readFile(self, fileName, args, varsToValue=0,useNamedTagList=False): #the varsToValue is mostly still in due to me being to lazy to remove it atm. Try to avoid using it as it will be removed at some point in the future.
splitSigns=[">=","<=","#"," ","\t","{","}","=",">","<"]
splitPattern="("
for sign in splitSigns:
Expand All @@ -361,11 +360,6 @@ def readFileNew(self, fileName, args, varsToValue,useNamedTagList=False):#,"@"])
if len(word)==0:
countEmpty+=1
continue
# #header variable
# elif word=="@":
# # writeToList=varsToValue
# objectList.append(varsToValue)
#bracket level increase
elif word=="{":
if not expectingVal:
raise ParseError("ERROR: Unexpected '{'")
Expand Down Expand Up @@ -402,8 +396,7 @@ def readFileNew(self, fileName, args, varsToValue,useNamedTagList=False):#,"@"])
elif expectingVal:
objectList[-1].vals[-1]+=word
expectingVal=False
# if objectList[-1]==varsToValue:
# objectList.pop

elif expectingNameAddition:
objectList[-1].names[-1]+=word
expectingNameAddition=False
Expand All @@ -415,68 +408,12 @@ def readFileNew(self, fileName, args, varsToValue,useNamedTagList=False):#,"@"])
print("Word: {}".format(word))
raise

for name,val in self.getAll():
if name and name[0]=="@":
if isinstance(name,TagList):
print("Invalid header variable")
varsToValue.add(name,val)


def readFile(self,fileName,args, varsToValue,keepEmptryLinesAndComments=False):#stores content of buildingFileName in self and varsToValue
bracketLevel=0
objectList=[] #objects currently open objectList[0] would be lowest bracket object (a building), etc
currentlyInHeader=True
with open(fileName,'r') as inputFile:
print("Start reading "+fileName)
lineIndex=0
for line in inputFile:
try:
lineIndex+=1
line=line.strip()
if len(line)>0 and (line[0]!="#" or bracketLevel>0) :
if line[0]=="@":
varsToValue.addString(line)
elif line[0]!="#" or bracketLevel>0:
if line[0]=="#":
objectList[-1].add("","",line)
continue
currentlyInHeader=False
bracketOpen=line.count("{")
bracketClose=line.count("}")
if bracketLevel==0:
if (bracketOpen!=1 or bracketClose!=0):
# print("Error in line {!s}:\n{}\nInvalid building start line".format(lineIndex,line))
# sys.exit(1)
# else:
self.addString(line)
if args.just_copy_and_check:
args.preventLinePrint.append(lineIndex)
# print(line)
else:
tagName=line.split("=")[0].strip()
objectList.append(NamedTagList(tagName))
self.add(tagName,objectList[-1])
else:
if bracketOpen>bracketClose:
newObject=TagList(bracketLevel+1)
objectList[-1].addArray([line.split("=")[0],newObject])
objectList.append(newObject)
elif bracketOpen==bracketClose:
objectList[-1].addString(line)
bracketDiff=bracketOpen-bracketClose
bracketLevel+=bracketDiff
# print(line)
if bracketLevel==0 and bracketDiff<0:
self.vals[-1].lineEnd=lineIndex
objectList=objectList[0:bracketLevel]
elif keepEmptryLinesAndComments:
if currentlyInHeader:
varsToValue.addString(line)
elif bracketLevel==0:
self.addString(line)
except:
print("Error in line {!s}: ".format(lineIndex)+line)
raise
if varsToValue:
for name,val in self.getAll():
if name and name[0]=="@":
if isinstance(name,TagList):
print("Invalid header variable")
varsToValue.add(name,val)
def addTags(self, tagList):
for name, entry in self.getAll():
if name and name!="namespace" and name[0]!="@" and entry!="":
Expand Down

0 comments on commit 4174c9e

Please sign in to comment.