Changeset - c95fa8ab1067
[Not reviewed]
default
1 4 2
Laman - 3 years ago 2022-03-04 22:55:14

changed imports
6 files changed with 20 insertions and 14 deletions:
0 comments (0 inline, 0 general)
.hgignore
Show inline comments
 
^\.
 
__pycache__/
 
^in/
 
^out/
 
\.pyc$
 
^build/
 
^dist/
 
.egg-info/
src/diana/__main__.py
Show inline comments
 
new file 100644
 
from .diana import main
 

	
 
if __name__ == "__main__":
 
	main()
src/diana/diana.py
Show inline comments
 
import os
 
import re
 

	
 
import config as cfg
 
import go
 
from go import BLACK,WHITE,EMPTY
 
from sgfParser import ParserError
 
from sgfParser.collection import Collection
 
from drawer.svg import Svg
 
from drawer.tikz import Tikz
 
from . import config as cfg
 
from . import go
 
from .go import BLACK,WHITE,EMPTY
 
from .sgfParser import ParserError
 
from .sgfParser.collection import Collection
 
from .drawer.svg import Svg
 
from .drawer.tikz import Tikz
 

	
 

	
 
def collectMoves(root):
 
	node=root
 
	while len(node.children)>0:
 
		b=node.getProp("B")
 
		w=node.getProp("W")
 
		if b is not None: yield ("b",b)
 
		elif w is not None: yield ("w",w)
 
		# else: yield None # !! not really robust
 

	
 
		node=node.children[0]
 
@@ -107,25 +107,25 @@ W: {PW} {WR}
 
		if not self._game.move(BLACK if color=='b' else WHITE, c,r):
 
			# !! we do not honor http://red-bean.com/sgf/ff5/m_vs_ax.htm at the moment
 
			msg="illegal move: {0} at {1},{2}".format(self._game.moveCount+1,c,r)
 
			if cfg.keepBroken:
 
				print(msg)
 
			else:
 
				msg+=". aborted"
 
				print(msg)
 
				return False
 
		return True
 

	
 

	
 
if __name__=="__main__":
 
def main():
 
	cfg.parseArgs()
 
	print("processing:")
 
	files=cfg.inputFiles[:]
 

	
 
	for item in files:
 
		if os.path.isfile(item):
 
			try:
 
				f=SourceFile(item)
 
				f.process()
 
			except ParserError as e:
 
				print("Couldn't parse {0}, following error occured: {1}".format(item,e))
 
		elif os.path.isdir(item):
src/diana/sgfParser/collection.py
Show inline comments
 
from .node import Node
 
from . import skipWhitespace, ParserError
 
from gameRecord import GameRecord
 
from .gameRecord import GameRecord
 

	
 

	
 
class Collection:
 
	def __init__(self,s):
 
		self.gameTrees=[]
 
		i=skipWhitespace(s,0)
 
		if i>=len(s): return
 
		elif not GameTree.fits(s,i):
 
			raise ParserError("expected a GameTree starting with '('",s,i)
 
		while GameTree.fits(s,i):
 
			i,x=GameTree.create(s,i)
 
			self.gameTrees.append(x)
src/diana/sgfParser/gameRecord.py
Show inline comments
 
file renamed from src/diana/gameRecord.py to src/diana/sgfParser/gameRecord.py
 
from sgfParser.node import Node
 
from .node import Node
 

	
 

	
 
## Wrapper around a Node tree.
 
class GameRecord:
 
	def __init__(self,root=None):
 
		self.root=root or Node()
 
		self._gameInfoNode=next(root.listGINodes())
 

	
 
	def export(self):
 
		return self.root.export()
 

	
 
	def set(self,name,value):
src/diana/tests/testSgfParser.py
Show inline comments
 
from itertools import chain
 
from datetime import date
 
import unittest
 
from unittest import TestCase
 
import os
 

	
 
from sgfParser import strRowCol
 
from sgfParser.collection import Collection
 
from sgfParser.property import Property,DateProperty,DateException
 
from sgfParser.propValues import text,compose
 
from diana.sgfParser import strRowCol
 
from diana.sgfParser.collection import Collection
 
from diana.sgfParser.property import Property,DateProperty,DateException
 
from diana.sgfParser.propValues import text,compose
 

	
 

	
 
dataDir=os.path.join(os.path.dirname(__file__), "data")
 

	
 

	
 
class TestUtils(TestCase):
 
	def testTextPos(self):
 
		s="abc\ndef\rgh\r\nij\n\rklmn"
 
		rc=[
 
			[1,2,3,4],
 
			[1,2,3,4],
 
			[1,2,3,4],
0 comments (0 inline, 0 general)