diff --git a/diana.py b/diana.py old mode 100644 new mode 100755 --- a/diana.py +++ b/diana.py @@ -9,21 +9,22 @@ if len(sys.argv)>1: else: sys.exit("no input file specified") -movesPerDiagram=50 +movesPerDiagram=75 minMovesPerDiagram=10 t=sys.stdout c=28 padding=15 -highNumbers=False +highNumbers=True class Svg: content="" footer="" + extension="svg" padding=15 gridSize=28 - highNumbers=False + highNumbers=True def __init__(self): self.content=''' @@ -88,42 +89,45 @@ class Svg: class Tikz: content="" footer="" + extension="tex" - highNumbers=False + highNumbers=True def __init__(self): - self.content='''\\begin{tikzpicture} - \\draw[step=\\boardSquare,gray,very thin] (0,0) grid (18\\boardSquare,18\\boardSquare); - \\draw (0,0) rectangle (18\\boardSquare,18\\boardSquare);\n\n''' + self.content=r'''\begin{tikzpicture} + \draw[step=\boardSquare,gray,very thin] (0,0) grid (18\boardSquare,18\boardSquare); + \draw (0,0) rectangle (18\boardSquare,18\boardSquare); + + ''' # hvězdy for i in range(3): for j in range(3): - self.content+=' \\filldraw[fill=black] ({0}\\boardSquare,{1}\\boardSquare) circle[radius=0.04];\n'.format(6*i+3, 6*j+3) + self.content+=r''' \filldraw[fill=black] ({0}\boardSquare,{1}\boardSquare) circle[radius=0.04];'''.format(6*i+3, 6*j+3)+'\n' self.content+='\n' - self.footer='\\end{tikzpicture}\n' + self.footer=r'\end{tikzpicture}' '\n' def __str__(self): return self.content+self.footer def drawStone(self,x,y,color): fill="black" if color=="b" else "white" - self.content+=' \\filldraw[draw=black,fill={0}] ({1}\\boardSquare,{2}\\boardSquare) circle[radius=0.5\\boardSquare];\n'.format(fill,x,18-y) + self.content+=r' \filldraw[draw=black,fill={0}] ({1}\boardSquare,{2}\boardSquare) circle[radius=0.5\boardSquare];'.format(fill,x,18-y)+'\n' def drawMove(self,x,y,label,color): fill="black" if color=="b" else "white" labelColor="white" if color=="b" else "black" if (not self.highNumbers) and isinstance(label,int) and label%100!=0: label=label%100 # dost neobratná logika - self.content+=' \\filldraw[draw=black,fill={0}] ({1}\\boardSquare,{2}\\boardSquare) circle[radius=0.5\\boardSquare] node[color={3}]{{{4}}};\n'.format(fill,x,18-y,labelColor,label) + self.content+=r' \filldraw[draw=black,fill={0}] ({1}\boardSquare,{2}\boardSquare) circle[radius=0.5\boardSquare] node[color={3}]{{{4}}};'.format(fill,x,18-y,labelColor,label)+'\n' def getContent(self): return self.content+self.footer def processFile(fileName): - shortName="".join(fileName.split('/')[-1].split('.')[:-1]) + shortName="".join(re.split(r'[/\\]',fileName)[-1].split('.')[:-1]) game=go.Go() global t @@ -180,20 +184,24 @@ def processFile(fileName): moveNumber+=1 # dokonči a ulož diagram - t=open("out/{0}-{1}.tex".format(shortName,i+1),'w') # nový soubor + # TODO rozumně pracovat s adresáři + t=open(os.path.join(os.path.dirname(__file__),"out","{0}-{1}.{2}".format(shortName,i+1,diagram.extension)),'w') # nový soubor t.write(diagram.getContent()) t.close() - notes=open("out/{0}.txt".format(shortName),'w') + notes=open(os.path.join(os.path.dirname(__file__),"out","{0}.txt".format(shortName)),'w') notes.write(overlays) notes.close() print("processing:") for item in files: + # relativně vůči work directory nebo vůči skriptu? + # item=os.path.join(os.path.dirname(__file__),item) if os.path.isfile(item): - print("{0}... ".format("".join(item.split('/')[-1].split('.')[:-1])),end="") + print("{0}... ".format(item),end="") processFile(item) print("done") elif os.path.isdir(item): + files+=[os.path.join(item,child) for child in os.listdir(item)] print("contents of the '{0}' directory added to the queue".format(item)) else: print("the '{0}' path could not be resolved to either a file nor a directory".format(item))