File: batch_win.py

package info (click to toggle)
gnubg 0.90-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 30,800 kB
  • ctags: 8,224
  • sloc: ansic: 92,884; xml: 13,338; sh: 9,675; makefile: 425; python: 392; yacc: 295; sql: 237; lex: 220; php: 102; cs: 81; awk: 25; sed: 16
file content (57 lines) | stat: -rw-r--r-- 2,128 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#
# batch_win.py -- batch import and analysis of multiple files using gnubg
#
# by Oystein Johansen <oystein@gnubg.org>, 2004
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 3 or later of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# $Id: batch_win.py,v 1.2 2007/07/02 12:50:13 ace Exp $

# This file is inspired of the batch.py file of Jon Kinsey. The code
# contains MS-Windows specific code and will therefore only work on MS-Windows
# together with GNU Backgammon and Python.

import win32ui, win32con

# file extensions, names and gnubg import commands

extensions = ['mat', 'pos', 'sgg', 'tmg', 'txt']
extTypes = ['.mat', '.pos', 'Games grid', 'True money game', 'Snowie text']
extCmds = ['mat', 'pos', 'sgg', 'tmg', 'snowietxt']

def BatchAnalyze(filelist):
    for file in filelist:
        dot = file.rfind('.')
        if dot != -1:
            ext = file[dot + 1 : ].lower()
            if ext in extensions:
                AnalyzeFile(file, extensions.index(ext))
                
def GetFiles():
    import win32ui, win32con
    filedialog = win32ui.CreateFileDialog(1,"", "", win32con.OFN_ALLOWMULTISELECT | win32con.OFN_HIDEREADONLY)
    filedialog.SetOFNTitle("Select files to analyse")
    filedialog.DoModal()
    
    return filedialog.GetPathNames()

def AnalyzeFile( file, type):
    "Run commands to analyze file in gnubg"
    gnubg.command('import ' + extCmds[type] + ' "' + file + '"')
    gnubg.command('analyze match')
    file = file[:-len(extensions[type])] + "sgf"
    gnubg.command('save match "' + file + '"')

files = GetFiles()
BatchAnalyze(files)