Subversion Repositories pyscrabble

Compare Revisions

Ignore whitespace Rev 34 → Rev 39

/trunk/debian/patches/installation.patch
1,9 → 1,9
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 @@
--- a/pyscrabble/net/server.py
+++ b/pyscrabble/net/server.py
@@ -46,7 +46,7 @@ class ScrabbleServerFactory(protocol.Ser
self.db = db.DB()
self.maxUsersLoggedIn = 0
self.startDate = util.Time(seconds=time.time(), dispDate=True)
12,18 → 12,18
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
--- a/pyscrabble/dist.py
+++ b/pyscrabble/dist.py
@@ -3,6 +3,8 @@ import os
import sys
-from distutils.command.install_lib import install_lib
-from distutils.command.install_scripts import install_scripts
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
APP_NAME = 'pyscrabble'
@@ -31,50 +29,13 @@
@@ -31,8 +33,6 @@ except ImportError:
RESOURCE_PREFIX = 'resources'
CONFIG_DIR = get_app_data_dir()
30,47 → 30,12
-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')
def getLocaleDirs(dir, domain):
l = []
@@ -76,6 +76,13 @@ def getDataFiles():
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:
77,57 → 42,72
+ 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)
Ensure config directory exists
@@ -112,11 +119,14 @@ class InstallLib(install_lib):
self.mkpath(os.path.dirname(filename))
install = self.distribution.get_command_obj('install')
- datadir = os.path.join(install.prefix, 'share', APP_NAME)
+ datadir = os.path.join(install.prefix, 'share', 'games', APP_NAME)
fp = open(filename, 'w')
fp.write('# Generated by setup.py do not modify\n')
- fp.write("RESOURCE_PREFIX = '%s'\n" % datadir)
+ 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
@@ -125,6 +135,35 @@ class InstallLib(install_lib):
template = self.generate_template()
return install_lib.install(self) + [template]
-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 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/'+APP_NAME), 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):
+ install.finalize_options(self)
+
class Resource(object):
'''
Filesystem resource
--- pyscrabble-1.6.2.orig/pyscrabble/db.py
+++ pyscrabble-1.6.2/pyscrabble/db.py
@@ -180,4 +219,4 @@ class Resource(object):
@param value:
'''
self.data[item] = value
-
\ No newline at end of file
+
--- a/pyscrabble/db.py
+++ b/pyscrabble/db.py
@@ -1,5 +1,4 @@
from pyscrabble import constants
-from pyscrabble import manager
134,7 → 114,7
from ZODB import FileStorage, DB as _DB
import transaction
@@ -12,8 +11,10 @@
@@ -12,8 +11,10 @@ class DB(object):
'''
Initialize the connection to the DB
'''
147,9 → 127,9
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 @@
--- a/pyscrabble/manager.py
+++ b/pyscrabble/manager.py
@@ -36,6 +36,7 @@ class ResourceManager(object):
'''
self.loaded = True
157,9 → 137,9
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 @@
--- a/server_console.py
+++ b/server_console.py
@@ -76,15 +76,15 @@ class ServerConsole(object):
'''
Configure the server
'''
179,9 → 159,9
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 @@
--- a/setup.py
+++ b/setup.py
@@ -7,21 +7,12 @@ except ImportError:
HAS_PY2EXE = False
import glob
import os
188,10 → 168,6
-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
202,145 → 178,20
- 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:
- 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')
'version': VERSION,
@@ -80,7 +71,7 @@ if HAS_PY2EXE and 'py2exe' in sys.argv:
# kwargs['data_files'] += dist.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}
+ kwargs['cmdclass'] = {'install': dist.Install, 'install_lib': dist.InstallLib, 'install_scripts' : dist.InstallScripts, 'install_data': dist.InstallData}
-setup(**kwargs)
\ No newline at end of file