Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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