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 import sys, os, re, string, time, types
39
40
41 from mfxtools import *
42 from version import VERSION, VERSION_DATE, VERSION_TUPLE
43 from mfxutil import Pickler, Unpickler, UnpicklingError
44 from mfxutil import Struct, EnvError
45
46
47
48
49
50
51 PACKAGE = "PySol"
52 PACKAGE_URL = "http://www.oberhumer.com/pysol"
53
54
55 SUITS = ("Club", "Spade", "Heart", "Diamond")
56 COLORS = ("black", "red")
57
58
59 RANKS = ("Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King")
60 ACE = 0
61 JACK = 10
62 QUEEN = 11
63 KING = 12
64
65
66 ANY_SUIT = -1
67 ANY_COLOR = -1
68 ANY_RANK = -1
69 NO_SUIT = 999999
70 NO_COLOR = 999999
71 NO_RANK = 999999
72
73
74 NO_REDEAL = 0
75 UNLIMITED_REDEALS = -1
76 VARIABLE_REDEALS = -2
77
78 CARDSET = "cardset"
79
80 IMAGE_EXTENSIONS = (".gif", ".ppm",)
81 if 1 and os.name == "nt":
82
83 IMAGE_EXTENSIONS = (".png", ".gif", ".ppm", ".jpg",)
84 pass
85
86 try:
87 bundle
88 except:
89 bundle = 0
90
92 v = re.split(r"[^\d\.]", version_string)
93 if not v or not v[0]:
94 return (0,)
95 v = string.split(v[0], ".")
96 v = filter(lambda x: x != "", v)
97 if not v or not v[0]:
98 return (0,)
99 return tuple(map(int, v))
100
101
102
103
104
105
108 self.msg = msg
109 self.clock = time.time
110 if os.name == "nt":
111 self.clock = time.clock
112 self.start = self.clock()
114 self.start = self.clock()
116 return self.clock() - self.start
118 return "%-20s %6.3f seconds" % (self.msg, self.clock() - self.start)
119
120
121
122
123
124
126 - def __init__(self, argv0, filenames, path=[]):
127 self.dir = None
128 if type(filenames) is types.StringType:
129 filenames = (filenames,)
130 assert type(filenames) in (types.TupleType, types.ListType)
131
132 path = path[:]
133 head, tail = os.path.split(argv0)
134 if not head:
135 head = os.curdir
136 path.append(head)
137 path.append(os.path.join(head, "data"))
138 path.append(os.path.join(head, os.pardir, "data"))
139
140 if os.name == "posix":
141 pass
142 if os.name == "nt":
143 pass
144 if os.name == "mac":
145 pass
146
147 if 1 and os.name == "posix":
148 for v in (VERSION, ""):
149 for prefix in ("@prefix@", "/usr/local", "/usr"):
150 try:
151 if os.path.isdir(prefix):
152 path.append(os.path.join(prefix,"share/pysol",v))
153 path.append(os.path.join(prefix,"lib/pysol",v))
154 path.append(os.path.join(prefix,"share/games/pysol",v))
155 path.append(os.path.join(prefix,"lib/games/pysol",v))
156 path.append(os.path.join(prefix,"games/share/pysol",v))
157 path.append(os.path.join(prefix,"games/lib/pysol",v))
158 except EnvError:
159 pass
160
161 self.path = []
162 for p in path:
163 if not p: continue
164 try:
165 np = os.path.normpath(p)
166 if np and (not np in self.path) and os.path.isdir(np):
167 self.path.append(np)
168 except EnvError:
169 pass
170
171 for p in self.path:
172 n = 0
173 for filename in filenames:
174 try:
175 f = os.path.join(p, filename)
176 if os.path.isfile(f):
177 n = n + 1
178 else:
179 break
180 except EnvError:
181 pass
182 if n == len(filenames):
183 self.dir = p
184 break
185 else:
186 raise os.error, str(argv0) + ": DataLoader could not find " + str(filenames)
187
188
189
190 - def __findFile(self, func, filename, subdirs=None, do_raise=1):
191 if subdirs is None:
192 subdirs = ("",)
193 elif type(subdirs) is types.StringType:
194 subdirs = (subdirs,)
195 for dir in subdirs:
196 f = os.path.join(self.dir, dir, filename)
197 f = os.path.normpath(f)
198 if func(f):
199 return f
200 if do_raise:
201 raise os.error, "DataLoader could not find " + filename + " in " + self.dir + " " + str(subdirs)
202 return None
203
204 - def findFile(self, filename, subdirs=None):
206
207 - def findImage(self, filename, subdirs=None):
213
214 - def findIcon(self, filename=None, subdirs=None):
221
222 - def findDir(self, filename, subdirs=None):
224
225
226
227
228
229
230 cyclops = None
231