1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 10_installation.dpatch by Magnus Holmgren <magnus@kibibyte.se>
4
## All lines beginning with `## DP:' are a description of the patch.
5
## DP: Mostly adapt server to run as a daemon
9
--- pyscrabble-1.6.2.orig/pyscrabble/net/server.py
10
+++ pyscrabble-1.6.2/pyscrabble/net/server.py
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] )
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
26
-from distutils.command.install_lib import install_lib
27
-from distutils.command.install_scripts import install_scripts
29
APP_NAME = 'pyscrabble'
32
RESOURCE_PREFIX = 'resources'
34
CONFIG_DIR = get_app_data_dir()
35
-if not os.path.exists(CONFIG_DIR):
36
- CONFIG_DIR = os.path.join(RESOURCE_PREFIX, 'config')
38
-def getLocaleDirs(dir, domain):
41
- langs = os.listdir( dir )
43
- d = os.path.join(dir,lang,"LC_MESSAGES")
44
- path = os.path.join(d, '%s.mo' % domain)
45
- l.append( (d,[path]) )
49
-def getResourceDirs(dir, ensureLower=True, basePath = None, outdir=None):
51
- absolute = os.path.abspath(dir)
55
- base = os.path.dirname(absolute)
57
- base = os.path.dirname( os.path.abspath(base) )
59
- for root, dirs, files in os.walk(absolute):
60
- if ensureLower and not os.path.basename(root).islower(): continue
63
- d = root[len(base)+1:]
64
- if outdir is not None:
65
- d = os.path.join(outdir, d)
67
- f.append( os.path.join(root, file) )
68
- result.append( (d, f) )
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')
80
+ from __installed__ import SERVER_LOG_DIR, SERVER_DB_DIR, SERVER_CONFIG_DIR
82
+ SERVER_CONFIG_DIR = os.path.join(RESOURCE_PREFIX, 'config')
83
+ SERVER_DB_DIR = CONFIG_DIR
84
+ SERVER_LOG_DIR = CONFIG_DIR
86
def ensure_config_dir(dir):
92
-class InstallScripts(install_scripts):
94
- install_scripts handler to strip any possible ^M's from files so they will run properly on unix
98
- install_scripts.run(self)
99
- for file in self.get_outputs():
102
- def fix(self, path):
103
- f = open(path, "rb")
104
- data = f.read().replace("\r\n", "\n")
106
- f = open(path, "w")
111
-class InstallLib(install_lib):
113
- def generate_template(self):
114
- filename = os.path.join(self.build_dir, APP_NAME, '__installed__.py')
115
- self.mkpath(os.path.dirname(filename))
117
- install = self.distribution.get_command_obj('install')
118
- datadir = os.path.join(install.prefix, 'share', APP_NAME)
120
- fp = open(filename, 'w')
121
- fp.write('# Generated by setup.py do not modify\n')
122
- fp.write("RESOURCE_PREFIX = '%s'\n" % datadir)
128
- template = self.generate_template()
129
- return install_lib.install(self) + [template]
131
class Resource(object):
134
--- pyscrabble-1.6.2.orig/pyscrabble/db.py
135
+++ pyscrabble-1.6.2/pyscrabble/db.py
137
from pyscrabble import constants
138
-from pyscrabble import manager
139
from ZODB import FileStorage, DB as _DB
144
Initialize the connection to the DB
146
- r = manager.ResourceManager()
147
- path = r["config"][constants.DB_LOCATION]
149
+ from pyscrabble import dist
151
+ path = os.path.join(dist.SERVER_DB_DIR, constants.DB_LOCATION)
153
storage = FileStorage.FileStorage(path)
155
--- pyscrabble-1.6.2.orig/pyscrabble/manager.py
156
+++ pyscrabble-1.6.2/pyscrabble/manager.py
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 )
165
--- pyscrabble-1.6.2.orig/server_console.py
166
+++ pyscrabble-1.6.2/server_console.py
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],
178
+ filename=os.path.join(dist.SERVER_LOG_DIR, constants.LOG_FILE),
182
- config = resources["config"][constants.SERVER_CONSOLE_CONFIG]
183
+ config = resources["serverconfig"][constants.SERVER_CONSOLE_CONFIG]
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
193
-import pkg_resources
194
+#import pkg_resources
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
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])
209
- return (item[0].replace('resources/', 'share/pyscrabble/'), item[1])
211
+def getLocaleDirs(dir, domain):
214
+ langs = os.listdir( dir )
216
+ d = os.path.join(dir,lang,"LC_MESSAGES")
217
+ path = os.path.join(d, '%s.mo' % domain)
218
+ l.append( (d,[path]) )
222
+def getResourceDirs(dir, ensureLower=True, basePath = None, outdir=None):
224
+ absolute = os.path.abspath(dir)
228
+ base = os.path.dirname(absolute)
231
+ base = os.path.dirname( os.path.abspath(base) )
233
+ for root, dirs, files in os.walk(absolute):
234
+ if ensureLower and not os.path.basename(root).islower(): continue
237
+ d = root[len(base)+1:]
238
+ if outdir is not None:
239
+ d = os.path.join(outdir, d)
241
+ f.append( os.path.join(root, file) )
242
+ result.append( (d, f) )
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')
254
+class InstallScripts(install_scripts):
256
+ install_scripts handler to strip any possible ^Ms from files so they will run properly on unix
260
+ install_scripts.run(self)
261
+ for file in self.get_outputs():
264
+ def fix(self, path):
265
+ f = open(path, "rb")
266
+ data = f.read().replace("\r\n", "\n")
268
+ f = open(path, "w")
273
+class InstallLib(install_lib):
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))
279
+ install = self.distribution.get_command_obj('install')
280
+ datadir = os.path.join(install.prefix, 'share', 'games', dist.APP_NAME)
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)
293
+ template = self.generate_template()
294
+ return install_lib.install(self) + [template]
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])
303
+ return (item[0].replace('resources/', 'share/games/pyscrabble/'), item[1])
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)
311
+class Install(install):
312
+ user_options = install.user_options + [ ('logdir=', None, "log directory"),
313
+ ('dbdir=', None, "database directory"),
314
+ ('confdir=', None, "configuration directory") ]
316
+ def initialize_options(self):
319
+ self.confdir = None
320
+ install.initialize_options(self)
322
+ def finalize_options(self):
324
+ install.finalize_options(self)
327
'name': 'pyscrabble',
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']
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')
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}
351
\ No newline at end of file