Subversion Repositories

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

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

Author: Magnus Holmgren <holmgren@debian.org>
Description: Mostly adapt server to run as a daemon

--- pyscrabble-1.6.2.orig/pyscrabble/net/server.py
+++ pyscrabble-1.6.2/pyscrabble/net/server.py
@@ -46,7 +46,7 @@
         self.db = db.DB()
         self.maxUsersLoggedIn = 0
         self.startDate = util.Time(seconds=time.time(), dispDate=True)
-        self.rankings = rank.Rankings( resources["config"][constants.RANK_CONFIG] )
+        self.rankings = rank.Rankings( resources["serverconfig"][constants.RANK_CONFIG] )
         
         dir = resources["resources"][constants.DICT_DIR].path
         for lang in os.listdir( dir ):
--- pyscrabble-1.6.2.orig/pyscrabble/dist.py
+++ pyscrabble-1.6.2/pyscrabble/dist.py
@@ -1,8 +1,6 @@
 import glob
 import os
 import sys
-from distutils.command.install_lib import install_lib
-from distutils.command.install_scripts import install_scripts
 
 APP_NAME = 'pyscrabble'
 
@@ -31,50 +29,13 @@
     RESOURCE_PREFIX = 'resources'
 
 CONFIG_DIR = get_app_data_dir()
-if not os.path.exists(CONFIG_DIR):
-    CONFIG_DIR = os.path.join(RESOURCE_PREFIX, 'config')
 
-def getLocaleDirs(dir, domain):
-    l = []
-    
-    langs = os.listdir( dir )
-    for lang in langs:
-        d = os.path.join(dir,lang,"LC_MESSAGES")
-        path = os.path.join(d, '%s.mo' % domain)
-        l.append( (d,[path]) )
-    
-    return l
-
-def getResourceDirs(dir, ensureLower=True, basePath = None, outdir=None):
-    result = []
-    absolute = os.path.abspath(dir)
-    
-    base = basePath
-    if base is None:
-        base = os.path.dirname(absolute)
-    else:
-        base = os.path.dirname( os.path.abspath(base) )
-    
-    for root, dirs, files in os.walk(absolute):
-        if ensureLower and not os.path.basename(root).islower(): continue
-        if len(files) > 0:
-            f = []
-            d = root[len(base)+1:]
-            if outdir is not None:
-                d = os.path.join(outdir, d)
-            for file in files:
-                f.append( os.path.join(root, file) )
-            result.append( (d, f) )
-    return result
-
-def getDataFiles():
-    return getLocaleDirs('resources/locale',APP_NAME) + \
-           [('resources/images', glob.glob('resources/images/*.*')), \
-            ('resources/sounds', glob.glob('resources/sounds/*.*')), \
-            ('config', glob.glob('resources/config/*.cfg')), \
-            ('resources/web', glob.glob('resources/web/*.*'))] + \
-           getResourceDirs('resources/dict', True, 'resources') + \
-           getResourceDirs('resources/letters', True, 'resources')
+try:
+    from __installed__ import SERVER_LOG_DIR, SERVER_DB_DIR, SERVER_CONFIG_DIR
+except ImportError:
+    SERVER_CONFIG_DIR = os.path.join(RESOURCE_PREFIX, 'config')
+    SERVER_DB_DIR = CONFIG_DIR
+    SERVER_LOG_DIR = CONFIG_DIR
 
 def ensure_config_dir(dir):
     '''
@@ -86,45 +47,6 @@
         os.makedirs(dir)
 
 
-class InstallScripts(install_scripts):
-    '''
-    install_scripts handler to strip any possible ^M's from files so they will run properly on unix
-    '''
-    
-    def run(self):
-        install_scripts.run(self)
-        for file in self.get_outputs():
-            self.fix(file)
-    
-    def fix(self, path):
-        f = open(path, "rb")
-        data = f.read().replace("\r\n", "\n")
-        f.close()
-        f = open(path, "w")
-        f.write(data)
-        f.close()
-    
-
-class InstallLib(install_lib):
-    
-    def generate_template(self):
-        filename = os.path.join(self.build_dir, APP_NAME, '__installed__.py')
-        self.mkpath(os.path.dirname(filename))
-        
-        install = self.distribution.get_command_obj('install')
-        datadir = os.path.join(install.prefix, 'share', APP_NAME)
-        
-        fp = open(filename, 'w')
-        fp.write('# Generated by setup.py do not modify\n')
-        fp.write("RESOURCE_PREFIX = '%s'\n" % datadir)
-        fp.close()
-
-        return filename
-    
-    def install(self):
-        template = self.generate_template()
-        return install_lib.install(self) + [template]
-
 class Resource(object):
     '''
     Filesystem resource
--- pyscrabble-1.6.2.orig/pyscrabble/db.py
+++ pyscrabble-1.6.2/pyscrabble/db.py
@@ -1,5 +1,4 @@
 from pyscrabble import constants
-from pyscrabble import manager
 from ZODB import FileStorage, DB as _DB
 import transaction
 
@@ -12,8 +11,10 @@
         '''
         Initialize the connection to the DB
         '''
-        r = manager.ResourceManager()
-        path = r["config"][constants.DB_LOCATION]
+        import os
+        from pyscrabble import dist
+
+        path = os.path.join(dist.SERVER_DB_DIR, constants.DB_LOCATION)
         
         storage = FileStorage.FileStorage(path)    
         db = _DB(storage)
--- pyscrabble-1.6.2.orig/pyscrabble/manager.py
+++ pyscrabble-1.6.2/pyscrabble/manager.py
@@ -36,6 +36,7 @@
         '''
         self.loaded = True
         
+        self["serverconfig"] = dist.Resource( dist.SERVER_CONFIG_DIR )
         self["config"] = dist.Resource( dist.CONFIG_DIR )
         self["resources"] = dist.Resource( dist.RESOURCE_PREFIX )
     
--- pyscrabble-1.6.2.orig/server_console.py
+++ pyscrabble-1.6.2/server_console.py
@@ -76,15 +76,15 @@
         '''
         Configure the server
         '''
-        dist.ensure_config_dir(dist.CONFIG_DIR)
+        dist.ensure_config_dir(dist.SERVER_CONFIG_DIR)
         resources = manager.ResourceManager()
         logging.basicConfig(level=logging.DEBUG,
                     format='%(asctime)s %(name)s %(levelname)s %(message)s',
-                    filename=resources["config"][constants.LOG_FILE],
-                    filemode='w')
+                    filename=os.path.join(dist.SERVER_LOG_DIR, constants.LOG_FILE),
+                    filemode='a')
         
         
-        config = resources["config"][constants.SERVER_CONSOLE_CONFIG]
+        config = resources["serverconfig"][constants.SERVER_CONSOLE_CONFIG]
         
         if not os.path.exists(config):
             raise IOError, "%s must exist in %s" % (constants.SERVER_CONSOLE_CONFIG, resources["config"].path)
--- pyscrabble-1.6.2.orig/setup.py
+++ pyscrabble-1.6.2/setup.py
@@ -7,20 +7,130 @@
     HAS_PY2EXE = False
 import glob
 import os
-import pkg_resources
+#import pkg_resources
 import sys
+from distutils.command.install_lib import install_lib
+from distutils.command.install_scripts import install_scripts
+from distutils.command.install_data import install_data
+from distutils.command.install import install
 from pyscrabble.constants import VERSION
 from pyscrabble import util
 from pyscrabble import dist
 
-def fix_path(item):
-    if type(item) in (list, tuple):
-        if 'config' in item[0]:
-            return (item[0].replace('config', dist.get_app_data_dir()), item[1])
-        else:
-            return (item[0].replace('resources/', 'share/pyscrabble/'), item[1])
+    
+def getLocaleDirs(dir, domain):
+    l = []
+    
+    langs = os.listdir( dir )
+    for lang in langs:
+        d = os.path.join(dir,lang,"LC_MESSAGES")
+        path = os.path.join(d, '%s.mo' % domain)
+        l.append( (d,[path]) )
+    
+    return l
+
+def getResourceDirs(dir, ensureLower=True, basePath = None, outdir=None):
+    result = []
+    absolute = os.path.abspath(dir)
+    
+    base = basePath
+    if base is None:
+        base = os.path.dirname(absolute)
     else:
-        return item
+        base = os.path.dirname( os.path.abspath(base) )
+    
+    for root, dirs, files in os.walk(absolute):
+        if ensureLower and not os.path.basename(root).islower(): continue
+        if len(files) > 0:
+            f = []
+            d = root[len(base)+1:]
+            if outdir is not None:
+                d = os.path.join(outdir, d)
+            for file in files:
+                f.append( os.path.join(root, file) )
+            result.append( (d, f) )
+    return result
+
+def getDataFiles():
+    return getLocaleDirs('resources/locale',dist.APP_NAME) + \
+           [('resources/images', glob.glob('resources/images/*.*')), \
+            ('resources/sounds', glob.glob('resources/sounds/*.*')), \
+            ('config', glob.glob('resources/config/*.cfg')), \
+            ('resources/web', glob.glob('resources/web/*.*'))] + \
+           getResourceDirs('resources/dict', True, 'resources') + \
+           getResourceDirs('resources/letters', True, 'resources')
+
+class InstallScripts(install_scripts):
+    '''
+    install_scripts handler to strip any possible ^Ms from files so they will run properly on unix
+    '''
+    
+    def run(self):
+        install_scripts.run(self)
+        for file in self.get_outputs():
+            self.fix(file)
+    
+    def fix(self, path):
+        f = open(path, "rb")
+        data = f.read().replace("\r\n", "\n")
+        f.close()
+        f = open(path, "w")
+        f.write(data)
+        f.close()
+    
+
+class InstallLib(install_lib):
+    
+    def generate_template(self):
+        filename = os.path.join(self.build_dir, dist.APP_NAME, '__installed__.py')
+        self.mkpath(os.path.dirname(filename))
+        
+        install = self.distribution.get_command_obj('install')
+        datadir = os.path.join(install.prefix, 'share', 'games', dist.APP_NAME)
+        
+        fp = open(filename, 'w')
+        fp.write('# Generated by setup.py do not modify\n')
+        fp.write("RESOURCE_PREFIX = %r\n" % datadir)
+        fp.write("SERVER_CONFIG_DIR = %r\n" % install.confdir)
+        fp.write("SERVER_DB_DIR = %r\n" % install.dbdir)
+        fp.write("SERVER_LOG_DIR = %r\n" % install.logdir)
+        fp.close()
+
+        return filename
+    
+    def install(self):
+        template = self.generate_template()
+        return install_lib.install(self) + [template]
+
+class InstallData(install_data):
+    def fix_path(self, item):
+        install = self.distribution.get_command_obj('install')
+        if type(item) in (list, tuple):
+            if 'config' in item[0]:
+                return (item[0].replace('config', install.confdir), item[1])
+            else:
+                return (item[0].replace('resources/', 'share/games/pyscrabble/'), item[1])
+        else:
+            return item
+
+    def finalize_options(self):
+        self.data_files = [ self.fix_path(f) for f in self.data_files ]
+        install_data.finalize_options(self)
+
+class Install(install):
+    user_options = install.user_options + [ ('logdir=', None, "log directory"),
+                                            ('dbdir=', None, "database directory"),
+                                            ('confdir=', None, "configuration directory") ]
+
+    def initialize_options(self):
+        self.logdir = None
+        self.dbdir = None
+        self.confdir = None
+        install.initialize_options(self)
+
+    def finalize_options(self):
+        print self.logdir
+        install.finalize_options(self)
 
 kwargs = {
     'name': 'pyscrabble',
@@ -28,7 +138,7 @@
     'author': 'Kevin Conaway',
     'author_email': 'kevin.a.conaway@gmail.com',
     'url': 'http://pyscrabble.sourceforge.net',
-    'data_files': dist.getDataFiles(),
+    'data_files': getDataFiles(),
     'packages': ['pyscrabble', 'pyscrabble.command', 'pyscrabble.game', 'pyscrabble.gui', 'pyscrabble.net']
 }
 
@@ -77,10 +187,10 @@
     kwargs['data_files'] += [('.', ['CHANGELOG.txt'])]
     kwargs['data_files'] += [('.', ['LICENSE.txt'])]
     #for egg in eggpacks:
-    #    kwargs['data_files'] += dist.getResourceDirs(egg.location, ensureLower=False, basePath=None, outdir='extra')
+    #    kwargs['data_files'] += getResourceDirs(egg.location, ensureLower=False, basePath=None, outdir='extra')
 else:
     kwargs['scripts'] = ['pyscrabble-main.py', 'server_console.py', 'db_upgrade.py']
-    kwargs['data_files'] = [fix_path(x) for x in kwargs['data_files']]
-    kwargs['cmdclass'] = {'install_lib': dist.InstallLib, 'install_scripts' : dist.InstallScripts}
+    #    kwargs['data_files'] = [fix_path(x) for x in kwargs['data_files']]
+    kwargs['cmdclass'] = {'install': Install, 'install_lib': InstallLib, 'install_scripts' : InstallScripts, 'install_data': InstallData}
 
-setup(**kwargs)
\ No newline at end of file
+setup(**kwargs)