Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/gtp.py
diff options
context:
space:
mode:
authorAndrés Ambrois <andresambrois@gmail.com>2008-09-26 07:00:30 (GMT)
committer Andrés Ambrois <andresambrois@gmail.com>2008-09-26 07:00:30 (GMT)
commite719d3579bb1539117b85eff6379eee0c7a77cd8 (patch)
treefd43f4b43ae55848145099920e972567a4419429 /gtp.py
parent56676b0f7e6b4b71e01c6e698b0707abeadd6b7a (diff)
Add GnuGo 3.6 to the bundle. Use system's GnuGo if installed.
Diffstat (limited to 'gtp.py')
-rw-r--r--gtp.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/gtp.py b/gtp.py
index a394cda..646c271 100644
--- a/gtp.py
+++ b/gtp.py
@@ -19,6 +19,7 @@
from subprocess import Popen, PIPE
import logging
+from sugar.activity.activity import get_bundle_path
from os.path import exists, join, abspath
from os import pathsep, environ
from string import split
@@ -30,6 +31,9 @@ def search_for_gnugo():
for path in paths:
if exists(join(path, 'gnugo')):
return abspath(join(path, 'gnugo'))
+ default_path = join(get_bundle_path(), 'gnugo', 'gnugo')
+ if exists(default_path):
+ return abspath(default_path)
return False
class gnugo:
@@ -37,16 +41,23 @@ class gnugo:
def __init__(self, boardsize=19, handicap=0, komi=5.5, level=3):
''' Start the gnugo subprocess '''
self.size = boardsize
- try:
- self.gnugo = Popen(['gnugo', '--mode', 'gtp', '--boardsize', str(boardsize),
- '--handicap', str(handicap), '--komi', str(komi), '--level', str(level) ],
- stdout=PIPE, stdin=PIPE)
- except:
- logger.error('Could not start gnugo subprocess')
+ self.path = search_for_gnugo()
+
+ if self.path:
+ logger.debug('Found gnugo at %s', self.path)
+ try:
+ self.gnugo = Popen([self.path, '--mode', 'gtp', '--boardsize', str(boardsize),
+ '--handicap', str(handicap), '--komi', str(komi), '--level', str(level) ],
+ stdout=PIPE, stdin=PIPE)
+ except OSError, data:
+ logger.error('Could not start gnugo subprocess: %s', data)
+ raise
+ else:
+ logger.debug('Successfuly loaded gnugo!')
+ self.stdin = self.gnugo.stdin
+ self.stdout = self.gnugo.stdout
else:
- logger.debug('Successfuly loaded gnugo!')
- self.stdin = self.gnugo.stdin
- self.stdout = self.gnugo.stdout
+ logger.error('Could not find gnugo')
def __del__(self):
logger.debug('Closing gnugo')