2
# db_import.py -- batch import of multiple sgf files into relational database
4
# by Jon Kinsey <Jon_Kinsey@hotmail.com>, 2004
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of version 2 of the GNU General Public License as
8
# published by the Free Software Foundation.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
# $Id: db_import.py,v 1.1 2004/11/08 12:24:41 Superfly_Jon Exp $
22
db_import.py -- batch import of multiple sgf files into relational database
24
by Jon Kinsey <Jon_Kinsey@hotmail.com>, 2004
30
"Look for gnubg import files in dir"
32
files = os.listdir(dir)
34
print " ** Directory not found **"
40
# Check each file in dir
42
# Check it's a file (not a directory)
43
if os.path.isfile(dir + file):
45
# Check has supported extension
48
ext = file[dot + 1 : ].lower()
57
print " ** No files in directory **"
59
print " ** No sgf files found in directory **"
62
def ImportFile(prompt, file, dir):
63
"Run commands to import stats into gnubg"
64
print prompt + " Importing " + file
65
gnubg.command('load match "' + dir + file + '"')
66
gnubg.command('relational add match')
70
while len(confirm) == 0 or (confirm[0] != 'y' and confirm[0] != 'n'):
71
confirm = raw_input(prompt + " (y/n): ").lower()
75
dir = raw_input(prompt)
77
# Make sure dir ends in a slash
78
if (dir[-1] != '\\' and dir[-1] != '/'):
83
"Import stats for all sgf files in a directory"
87
# Get directory with original files in
88
dir = GetDir("Directory containing files to import (enter-exit): ")
93
inFiles = GetFiles(dir)
95
# Display files that will be analyzed
99
print "\n", len(inFiles), "files found\n"
101
# Check user wants to continue
102
if GetYN("Continue") == 'n':
105
# Get stats for each file
109
prompt = "(%d/%d)" % (num, len(inFiles))
110
ImportFile(prompt, file, dir)
112
print "\n** Finished **"
115
# Run batchimport on load
119
except Exception, (e):