Rev 27 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | magnus | 1 | #! /bin/sh /usr/share/dpatch/dpatch-run |
2 | ## 10_installation.dpatch by Magnus Holmgren <magnus@kibibyte.se> |
||
3 | ## |
||
4 | ## All lines beginning with `## DP:' are a description of the patch. |
||
5 | ## DP: Mostly adapt server to run as a daemon |
||
6 | |||
7 | @DPATCH@ |
||
8 | |||
9 | --- pyscrabble-1.6.2.orig/pyscrabble/net/server.py |
||
10 | +++ pyscrabble-1.6.2/pyscrabble/net/server.py |
||
11 | @@ -46,7 +46,7 @@ |
||
12 | self.db = db.DB() |
||
13 | self.maxUsersLoggedIn = 0 |
||
14 | self.startDate = util.Time(seconds=time.time(), dispDate=True) |
||
15 | - self.rankings = rank.Rankings( resources["config"][constants.RANK_CONFIG] ) |
||
16 | + self.rankings = rank.Rankings( resources["serverconfig"][constants.RANK_CONFIG] ) |
||
17 | |||
18 | dir = resources["resources"][constants.DICT_DIR].path |
||
19 | for lang in os.listdir( dir ): |
||
20 | --- pyscrabble-1.6.2.orig/pyscrabble/dist.py |
||
21 | +++ pyscrabble-1.6.2/pyscrabble/dist.py |
||
22 | @@ -1,8 +1,6 @@ |
||
23 | import glob |
||
24 | import os |
||
25 | import sys |
||
26 | -from distutils.command.install_lib import install_lib |
||
27 | -from distutils.command.install_scripts import install_scripts |
||
28 | |||
29 | APP_NAME = 'pyscrabble' |
||
30 | |||
31 | @@ -31,50 +29,13 @@ |
||
32 | RESOURCE_PREFIX = 'resources' |
||
33 | |||
34 | CONFIG_DIR = get_app_data_dir() |
||
35 | -if not os.path.exists(CONFIG_DIR): |
||
36 | - CONFIG_DIR = os.path.join(RESOURCE_PREFIX, 'config') |
||
37 | |||
38 | -def getLocaleDirs(dir, domain): |
||
39 | - l = [] |
||
40 | - |
||
41 | - langs = os.listdir( dir ) |
||
42 | - for lang in langs: |
||
43 | - d = os.path.join(dir,lang,"LC_MESSAGES") |
||
44 | - path = os.path.join(d, '%s.mo' % domain) |
||
45 | - l.append( (d,[path]) ) |
||
46 | - |
||
47 | - return l |
||
48 | - |
||
49 | -def getResourceDirs(dir, ensureLower=True, basePath = None, outdir=None): |
||
50 | - result = [] |
||
51 | - absolute = os.path.abspath(dir) |
||
52 | - |
||
53 | - base = basePath |
||
54 | - if base is None: |
||
55 | - base = os.path.dirname(absolute) |
||
56 | - else: |
||
57 | - base = os.path.dirname( os.path.abspath(base) ) |
||
58 | - |
||
59 | - for root, dirs, files in os.walk(absolute): |
||
60 | - if ensureLower and not os.path.basename(root).islower(): continue |
||
61 | - if len(files) > 0: |
||
62 | - f = [] |
||
63 | - d = root[len(base)+1:] |
||
64 | - if outdir is not None: |
||
65 | - d = os.path.join(outdir, d) |
||
66 | - for file in files: |
||
67 | - f.append( os.path.join(root, file) ) |
||
68 | - result.append( (d, f) ) |
||
69 | - return result |
||
70 | - |
||
71 | -def getDataFiles(): |
||
72 | - return getLocaleDirs('resources/locale',APP_NAME) + \ |
||
73 | - [('resources/images', glob.glob('resources/images/*.*')), \ |
||
74 | - ('resources/sounds', glob.glob('resources/sounds/*.*')), \ |
||
75 | - ('config', glob.glob('resources/config/*.cfg')), \ |
||
76 | - ('resources/web', glob.glob('resources/web/*.*'))] + \ |
||
77 | - getResourceDirs('resources/dict', True, 'resources') + \ |
||
78 | - getResourceDirs('resources/letters', True, 'resources') |
||
79 | +try: |
||
80 | + from __installed__ import SERVER_LOG_DIR, SERVER_DB_DIR, SERVER_CONFIG_DIR |
||
81 | +except ImportError: |
||
82 | + SERVER_CONFIG_DIR = os.path.join(RESOURCE_PREFIX, 'config') |
||
83 | + SERVER_DB_DIR = CONFIG_DIR |
||
84 | + SERVER_LOG_DIR = CONFIG_DIR |
||
85 | |||
86 | def ensure_config_dir(dir): |
||
87 | ''' |
||
88 | @@ -86,45 +47,6 @@ |
||
89 | os.makedirs(dir) |
||
90 | |||
91 | |||
92 | -class InstallScripts(install_scripts): |
||
93 | - ''' |
||
94 | - install_scripts handler to strip any possible ^M's from files so they will run properly on unix |
||
95 | - ''' |
||
96 | - |
||
97 | - def run(self): |
||
98 | - install_scripts.run(self) |
||
99 | - for file in self.get_outputs(): |
||
100 | - self.fix(file) |
||
101 | - |
||
102 | - def fix(self, path): |
||
103 | - f = open(path, "rb") |
||
104 | - data = f.read().replace("\r\n", "\n") |
||
105 | - f.close() |
||
106 | - f = open(path, "w") |
||
107 | - f.write(data) |
||
108 | - f.close() |
||
109 | - |
||
110 | - |
||
111 | -class InstallLib(install_lib): |
||
112 | - |
||
113 | - def generate_template(self): |
||
114 | - filename = os.path.join(self.build_dir, APP_NAME, '__installed__.py') |
||
115 | - self.mkpath(os.path.dirname(filename)) |
||
116 | - |
||
117 | - install = self.distribution.get_command_obj('install') |
||
118 | - datadir = os.path.join(install.prefix, 'share', APP_NAME) |
||
119 | - |
||
120 | - fp = open(filename, 'w') |
||
121 | - fp.write('# Generated by setup.py do not modify\n') |
||
122 | - fp.write("RESOURCE_PREFIX = '%s'\n" % datadir) |
||
123 | - fp.close() |
||
124 | - |
||
125 | - return filename |
||
126 | - |
||
127 | - def install(self): |
||
128 | - template = self.generate_template() |
||
129 | - return install_lib.install(self) + [template] |
||
130 | - |
||
131 | class Resource(object): |
||
132 | ''' |
||
133 | Filesystem resource |
||
134 | --- pyscrabble-1.6.2.orig/pyscrabble/db.py |
||
135 | +++ pyscrabble-1.6.2/pyscrabble/db.py |
||
136 | @@ -1,5 +1,4 @@ |
||
137 | from pyscrabble import constants |
||
138 | -from pyscrabble import manager |
||
139 | from ZODB import FileStorage, DB as _DB |
||
140 | import transaction |
||
141 | |||
142 | @@ -12,8 +11,10 @@ |
||
143 | ''' |
||
144 | Initialize the connection to the DB |
||
145 | ''' |
||
146 | - r = manager.ResourceManager() |
||
147 | - path = r["config"][constants.DB_LOCATION] |
||
148 | + import os |
||
149 | + from pyscrabble import dist |
||
150 | + |
||
151 | + path = os.path.join(dist.SERVER_DB_DIR, constants.DB_LOCATION) |
||
152 | |||
153 | storage = FileStorage.FileStorage(path) |
||
154 | db = _DB(storage) |
||
155 | --- pyscrabble-1.6.2.orig/pyscrabble/manager.py |
||
156 | +++ pyscrabble-1.6.2/pyscrabble/manager.py |
||
157 | @@ -36,6 +36,7 @@ |
||
158 | ''' |
||
159 | self.loaded = True |
||
160 | |||
161 | + self["serverconfig"] = dist.Resource( dist.SERVER_CONFIG_DIR ) |
||
162 | self["config"] = dist.Resource( dist.CONFIG_DIR ) |
||
163 | self["resources"] = dist.Resource( dist.RESOURCE_PREFIX ) |
||
164 | |||
165 | --- pyscrabble-1.6.2.orig/server_console.py |
||
166 | +++ pyscrabble-1.6.2/server_console.py |
||
167 | @@ -76,15 +76,15 @@ |
||
168 | ''' |
||
169 | Configure the server |
||
170 | ''' |
||
171 | - dist.ensure_config_dir(dist.CONFIG_DIR) |
||
172 | + dist.ensure_config_dir(dist.SERVER_CONFIG_DIR) |
||
173 | resources = manager.ResourceManager() |
||
174 | logging.basicConfig(level=logging.DEBUG, |
||
175 | format='%(asctime)s %(name)s %(levelname)s %(message)s', |
||
176 | - filename=resources["config"][constants.LOG_FILE], |
||
177 | - filemode='w') |
||
178 | + filename=os.path.join(dist.SERVER_LOG_DIR, constants.LOG_FILE), |
||
179 | + filemode='a') |
||
180 | |||
181 | |||
182 | - config = resources["config"][constants.SERVER_CONSOLE_CONFIG] |
||
183 | + config = resources["serverconfig"][constants.SERVER_CONSOLE_CONFIG] |
||
184 | |||
185 | if not os.path.exists(config): |
||
186 | raise IOError, "%s must exist in %s" % (constants.SERVER_CONSOLE_CONFIG, resources["config"].path) |
||
187 | --- pyscrabble-1.6.2.orig/setup.py |
||
188 | +++ pyscrabble-1.6.2/setup.py |
||
189 | @@ -7,20 +7,130 @@ |
||
190 | HAS_PY2EXE = False |
||
191 | import glob |
||
192 | import os |
||
193 | -import pkg_resources |
||
194 | +#import pkg_resources |
||
195 | import sys |
||
196 | +from distutils.command.install_lib import install_lib |
||
197 | +from distutils.command.install_scripts import install_scripts |
||
198 | +from distutils.command.install_data import install_data |
||
199 | +from distutils.command.install import install |
||
200 | from pyscrabble.constants import VERSION |
||
201 | from pyscrabble import util |
||
202 | from pyscrabble import dist |
||
203 | |||
204 | -def fix_path(item): |
||
205 | - if type(item) in (list, tuple): |
||
206 | - if 'config' in item[0]: |
||
207 | - return (item[0].replace('config', dist.get_app_data_dir()), item[1]) |
||
208 | - else: |
||
209 | - return (item[0].replace('resources/', 'share/pyscrabble/'), item[1]) |
||
210 | + |
||
211 | +def getLocaleDirs(dir, domain): |
||
212 | + l = [] |
||
213 | + |
||
214 | + langs = os.listdir( dir ) |
||
215 | + for lang in langs: |
||
216 | + d = os.path.join(dir,lang,"LC_MESSAGES") |
||
217 | + path = os.path.join(d, '%s.mo' % domain) |
||
218 | + l.append( (d,[path]) ) |
||
219 | + |
||
220 | + return l |
||
221 | + |
||
222 | +def getResourceDirs(dir, ensureLower=True, basePath = None, outdir=None): |
||
223 | + result = [] |
||
224 | + absolute = os.path.abspath(dir) |
||
225 | + |
||
226 | + base = basePath |
||
227 | + if base is None: |
||
228 | + base = os.path.dirname(absolute) |
||
229 | else: |
||
230 | - return item |
||
231 | + base = os.path.dirname( os.path.abspath(base) ) |
||
232 | + |
||
233 | + for root, dirs, files in os.walk(absolute): |
||
234 | + if ensureLower and not os.path.basename(root).islower(): continue |
||
235 | + if len(files) > 0: |
||
236 | + f = [] |
||
237 | + d = root[len(base)+1:] |
||
238 | + if outdir is not None: |
||
239 | + d = os.path.join(outdir, d) |
||
240 | + for file in files: |
||
241 | + f.append( os.path.join(root, file) ) |
||
242 | + result.append( (d, f) ) |
||
243 | + return result |
||
244 | + |
||
245 | +def getDataFiles(): |
||
246 | + return getLocaleDirs('resources/locale',dist.APP_NAME) + \ |
||
247 | + [('resources/images', glob.glob('resources/images/*.*')), \ |
||
248 | + ('resources/sounds', glob.glob('resources/sounds/*.*')), \ |
||
249 | + ('config', glob.glob('resources/config/*.cfg')), \ |
||
250 | + ('resources/web', glob.glob('resources/web/*.*'))] + \ |
||
251 | + getResourceDirs('resources/dict', True, 'resources') + \ |
||
252 | + getResourceDirs('resources/letters', True, 'resources') |
||
253 | + |
||
254 | +class InstallScripts(install_scripts): |
||
255 | + ''' |
||
256 | + install_scripts handler to strip any possible ^Ms from files so they will run properly on unix |
||
257 | + ''' |
||
258 | + |
||
259 | + def run(self): |
||
260 | + install_scripts.run(self) |
||
261 | + for file in self.get_outputs(): |
||
262 | + self.fix(file) |
||
263 | + |
||
264 | + def fix(self, path): |
||
265 | + f = open(path, "rb") |
||
266 | + data = f.read().replace("\r\n", "\n") |
||
267 | + f.close() |
||
268 | + f = open(path, "w") |
||
269 | + f.write(data) |
||
270 | + f.close() |
||
271 | + |
||
272 | + |
||
273 | +class InstallLib(install_lib): |
||
274 | + |
||
275 | + def generate_template(self): |
||
276 | + filename = os.path.join(self.build_dir, dist.APP_NAME, '__installed__.py') |
||
277 | + self.mkpath(os.path.dirname(filename)) |
||
278 | + |
||
279 | + install = self.distribution.get_command_obj('install') |
||
280 | + datadir = os.path.join(install.prefix, 'share', 'games', dist.APP_NAME) |
||
281 | + |
||
282 | + fp = open(filename, 'w') |
||
283 | + fp.write('# Generated by setup.py do not modify\n') |
||
284 | + fp.write("RESOURCE_PREFIX = %r\n" % datadir) |
||
285 | + fp.write("SERVER_CONFIG_DIR = %r\n" % install.confdir) |
||
286 | + fp.write("SERVER_DB_DIR = %r\n" % install.dbdir) |
||
287 | + fp.write("SERVER_LOG_DIR = %r\n" % install.logdir) |
||
288 | + fp.close() |
||
289 | + |
||
290 | + return filename |
||
291 | + |
||
292 | + def install(self): |
||
293 | + template = self.generate_template() |
||
294 | + return install_lib.install(self) + [template] |
||
295 | + |
||
296 | +class InstallData(install_data): |
||
297 | + def fix_path(self, item): |
||
298 | + install = self.distribution.get_command_obj('install') |
||
299 | + if type(item) in (list, tuple): |
||
300 | + if 'config' in item[0]: |
||
301 | + return (item[0].replace('config', install.confdir), item[1]) |
||
302 | + else: |
||
303 | + return (item[0].replace('resources/', 'share/games/pyscrabble/'), item[1]) |
||
304 | + else: |
||
305 | + return item |
||
306 | + |
||
307 | + def finalize_options(self): |
||
308 | + self.data_files = [ self.fix_path(f) for f in self.data_files ] |
||
309 | + install_data.finalize_options(self) |
||
310 | + |
||
311 | +class Install(install): |
||
312 | + user_options = install.user_options + [ ('logdir=', None, "log directory"), |
||
313 | + ('dbdir=', None, "database directory"), |
||
314 | + ('confdir=', None, "configuration directory") ] |
||
315 | + |
||
316 | + def initialize_options(self): |
||
317 | + self.logdir = None |
||
318 | + self.dbdir = None |
||
319 | + self.confdir = None |
||
320 | + install.initialize_options(self) |
||
321 | + |
||
322 | + def finalize_options(self): |
||
323 | + print self.logdir |
||
324 | + install.finalize_options(self) |
||
325 | |||
326 | kwargs = { |
||
327 | 'name': 'pyscrabble', |
||
328 | @@ -28,7 +138,7 @@ |
||
329 | 'author': 'Kevin Conaway', |
||
330 | 'author_email': 'kevin.a.conaway@gmail.com', |
||
331 | 'url': 'http://pyscrabble.sourceforge.net', |
||
332 | - 'data_files': dist.getDataFiles(), |
||
333 | + 'data_files': getDataFiles(), |
||
334 | 'packages': ['pyscrabble', 'pyscrabble.command', 'pyscrabble.game', 'pyscrabble.gui', 'pyscrabble.net'] |
||
335 | } |
||
336 | |||
337 | @@ -77,10 +187,10 @@ |
||
338 | kwargs['data_files'] += [('.', ['CHANGELOG.txt'])] |
||
339 | kwargs['data_files'] += [('.', ['LICENSE.txt'])] |
||
340 | #for egg in eggpacks: |
||
341 | - # kwargs['data_files'] += dist.getResourceDirs(egg.location, ensureLower=False, basePath=None, outdir='extra') |
||
342 | + # kwargs['data_files'] += getResourceDirs(egg.location, ensureLower=False, basePath=None, outdir='extra') |
||
343 | else: |
||
344 | kwargs['scripts'] = ['pyscrabble-main.py', 'server_console.py', 'db_upgrade.py'] |
||
345 | - kwargs['data_files'] = [fix_path(x) for x in kwargs['data_files']] |
||
346 | - kwargs['cmdclass'] = {'install_lib': dist.InstallLib, 'install_scripts' : dist.InstallScripts} |
||
347 | + # kwargs['data_files'] = [fix_path(x) for x in kwargs['data_files']] |
||
348 | + kwargs['cmdclass'] = {'install': Install, 'install_lib': InstallLib, 'install_scripts' : InstallScripts, 'install_data': InstallData} |
||
349 | |||
350 | -setup(**kwargs) |
||
351 | \ No newline at end of file |
||
352 | +setup(**kwargs) |