From: <umg...@us...> - 2006-08-15 15:02:16
|
Revision: 337 Author: umgangee Date: 2006-08-15 08:02:10 -0700 (Tue, 15 Aug 2006) ViewCVS: http://svn.sourceforge.net/pybridge/?rev=337&view=rev Log Message: ----------- Add detection of lib/python/pybridge/ package. Removed detection of lib/python2.X/site-packages/pybridge, since "import pybridge" does that automatically! Modified Paths: -------------- trunk/pybridge/bin/pybridge trunk/pybridge/bin/pybridge-server Modified: trunk/pybridge/bin/pybridge =================================================================== --- trunk/pybridge/bin/pybridge 2006-08-14 20:12:33 UTC (rev 336) +++ trunk/pybridge/bin/pybridge 2006-08-15 15:02:10 UTC (rev 337) @@ -18,7 +18,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -import os, sys +import os +import sys PYTHON_VERSION = sys.version_info[:2] @@ -44,19 +45,19 @@ raise SystemExit("Error: Twisted Core %s or higher required" % TWISTED_REQUIRED) -# Determine the base directory. -currentdir = os.path.dirname(os.path.abspath(sys.argv[0])) -basedir = os.path.abspath(os.path.join(currentdir, '..')) +try: # If PyBridge is installed system-wide, this finds it automatically. + import pybridge +except ImportError: # Locate the PyBridge package. + currentdir = os.path.dirname(os.path.abspath(sys.argv[0])) + basedir = os.path.abspath(os.path.join(currentdir, '..')) + # The package path should be relative to the base directory. + if os.path.exists(os.path.join(basedir, 'lib', 'python')): + pythonpath = os.path.join(basedir, 'lib', 'python') + else: + pythonpath = basedir + sys.path.insert(0, pythonpath) # Place PyBridge package in PYTHONPATH. -# Find the Python module path, relative to the base directory. -if os.path.exists(os.path.join(basedir, 'lib')): - pythonpath = os.path.join(basedir, 'lib', 'python%d.%d' % PYTHON_VERSION, 'site-packages') -else: - pythonpath = basedir -sys.path.insert(0, pythonpath) - - import pybridge.ui pybridge.ui.run() Modified: trunk/pybridge/bin/pybridge-server =================================================================== --- trunk/pybridge/bin/pybridge-server 2006-08-14 20:12:33 UTC (rev 336) +++ trunk/pybridge/bin/pybridge-server 2006-08-15 15:02:10 UTC (rev 337) @@ -41,6 +41,18 @@ print "\nError: %s" % error sys.exit(2) + try: # If PyBridge is installed system-wide, this finds it automatically. + import pybridge + except ImportError: # Locate the PyBridge package. + currentdir = os.path.dirname(os.path.abspath(sys.argv[0])) + basedir = os.path.abspath(os.path.join(currentdir, '..')) + # The package path should be relative to the base directory. + if os.path.exists(os.path.join(basedir, 'lib', 'python')): + pythonpath = os.path.join(basedir, 'lib', 'python') + else: + pythonpath = basedir + sys.path.insert(0, pythonpath) # Place PyBridge package in PYTHONPATH. + for opt, arg in opts: if opt in ('-h', '--help'): usage() @@ -53,30 +65,16 @@ print "\nError: invalid value %s specified for %s" % (arg, opt) sys.exit(2) elif opt in ('-v', '--version'): - import pybridge print "PyBridge Server version %s" % pybridge.__version__ sys.exit(0) - # Determine the base directory. - currentdir = os.path.dirname(os.path.abspath(sys.argv[0])) - basedir = os.path.abspath(os.path.join(currentdir, '..')) - - # Find the Python module path, relative to the base directory. - if os.path.exists(os.path.join(basedir, 'lib')): - pythonver = 'python%d.%d' % sys.version_info[:2] - pythonpath = os.path.join(basedir, 'lib', pythonver, 'site-packages') - else: - pythonpath = basedir - - sys.path.insert(0, pythonpath) - from twisted.internet import reactor from twisted.python import log from pybridge.server import factory # TODO: replace with a service. log.startLogging(sys.stdout) # Log to stdout. - reactor.listenTCP(PORT, factory) # Default PyBridge port. + reactor.listenTCP(PORT, factory) reactor.run() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <umg...@us...> - 2006-09-20 11:00:30
|
Revision: 344 http://svn.sourceforge.net/pybridge/?rev=344&view=rev Author: umgangee Date: 2006-09-20 04:00:26 -0700 (Wed, 20 Sep 2006) Log Message: ----------- Force import of pybridge package, after path to pybridge has been inserted in sys.path. Running "pybridge-server -v" on local (not installed) PyBridge setups will now work. Modified Paths: -------------- trunk/pybridge/bin/pybridge trunk/pybridge/bin/pybridge-server Modified: trunk/pybridge/bin/pybridge =================================================================== --- trunk/pybridge/bin/pybridge 2006-09-20 10:56:47 UTC (rev 343) +++ trunk/pybridge/bin/pybridge 2006-09-20 11:00:26 UTC (rev 344) @@ -56,6 +56,7 @@ else: pythonpath = basedir sys.path.insert(0, pythonpath) # Place PyBridge package in PYTHONPATH. + import pybridge import pybridge.ui Modified: trunk/pybridge/bin/pybridge-server =================================================================== --- trunk/pybridge/bin/pybridge-server 2006-09-20 10:56:47 UTC (rev 343) +++ trunk/pybridge/bin/pybridge-server 2006-09-20 11:00:26 UTC (rev 344) @@ -52,6 +52,7 @@ else: pythonpath = basedir sys.path.insert(0, pythonpath) # Place PyBridge package in PYTHONPATH. + import pybridge for opt, arg in opts: if opt in ('-h', '--help'): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <umg...@us...> - 2007-06-22 11:27:03
|
Revision: 436 http://svn.sourceforge.net/pybridge/?rev=436&view=rev Author: umgangee Date: 2007-06-22 04:27:04 -0700 (Fri, 22 Jun 2007) Log Message: ----------- Replace getopt with OptionParser to make life easier. Modified Paths: -------------- trunk/pybridge/bin/pybridge trunk/pybridge/bin/pybridge-server Modified: trunk/pybridge/bin/pybridge =================================================================== --- trunk/pybridge/bin/pybridge 2007-06-21 15:57:33 UTC (rev 435) +++ trunk/pybridge/bin/pybridge 2007-06-22 11:27:04 UTC (rev 436) @@ -1,7 +1,7 @@ #!/usr/bin/env python # PyBridge -- online contract bridge made easy. -# Copyright (C) 2004-2006 PyBridge Project. +# Copyright (C) 2004-2007 PyBridge Project. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -12,7 +12,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -20,45 +20,59 @@ import os import sys +from optparse import OptionParser -PYTHON_VERSION = sys.version_info[:2] +def main(): + PYTHON_VERSION = sys.version_info[:2] -# Some version dependencies. -PYTHON_REQUIRED = (2, 3) -PYGTK_REQUIRED = '2.0' -TWISTED_REQUIRED = '1.3.0' + # Some version dependencies. + PYTHON_REQUIRED = (2, 3) + PYGTK_REQUIRED = '2.0' + TWISTED_REQUIRED = '2.0.0' -# Check version requirements. + # Check version requirements. -if PYTHON_VERSION < PYTHON_REQUIRED: - raise SystemExit("Error: Python %d.%d or higher required" % PYTHON_REQUIRED) + if PYTHON_VERSION < PYTHON_REQUIRED: + raise SystemExit, "Error: Python %d.%d+ required" % PYTHON_REQUIRED -if hasattr(sys, 'frozen'): # For py2exe distribution. - os.environ['PATH'] += ";lib;" -else: - import pygtk - pygtk.require(PYGTK_REQUIRED) + if hasattr(sys, 'frozen'): # For py2exe distribution. + os.environ['PATH'] += ";lib;" + else: + import pygtk + try: + pygtk.require(PYGTK_REQUIRED) + except AssertionError: + raise SystemExit, "Error: PyGTK %s+ required" % PYGTK_REQUIRED -import twisted.copyright -if twisted.copyright.version < TWISTED_REQUIRED: - raise SystemExit("Error: Twisted Core %s or higher required" % TWISTED_REQUIRED) + import twisted.copyright + if twisted.copyright.version < TWISTED_REQUIRED: + raise SystemExit, "Error: Twisted Core %s+ required" % TWISTED_REQUIRED + try: # If PyBridge is installed system-wide, this finds it automatically. + import pybridge + except ImportError: # Locate the PyBridge package. + currentdir = os.path.dirname(os.path.abspath(sys.argv[0])) + basedir = os.path.abspath(os.path.join(currentdir, '..')) + # The package path should be relative to the base directory. + if os.path.exists(os.path.join(basedir, 'lib', 'python')): + pythonpath = os.path.join(basedir, 'lib', 'python') + else: + pythonpath = basedir -try: # If PyBridge is installed system-wide, this finds it automatically. - import pybridge -except ImportError: # Locate the PyBridge package. - currentdir = os.path.dirname(os.path.abspath(sys.argv[0])) - basedir = os.path.abspath(os.path.join(currentdir, '..')) - # The package path should be relative to the base directory. - if os.path.exists(os.path.join(basedir, 'lib', 'python')): - pythonpath = os.path.join(basedir, 'lib', 'python') - else: - pythonpath = basedir - sys.path.insert(0, pythonpath) # Place PyBridge package in PYTHONPATH. - import pybridge + sys.path.insert(0, pythonpath) # Place PyBridge package in PYTHONPATH. + try: + import pybridge + except ImportError: + raise SystemExit, "Fatal error: could not locate PyBridge installation." + parser = OptionParser(version="PyBridge %s" % pybridge.__version__) + options, args = parser.parse_args() -import pybridge.ui -pybridge.ui.run() + import pybridge.ui + pybridge.ui.run() + +if __name__ == '__main__': + main() + Modified: trunk/pybridge/bin/pybridge-server =================================================================== --- trunk/pybridge/bin/pybridge-server 2007-06-21 15:57:33 UTC (rev 435) +++ trunk/pybridge/bin/pybridge-server 2007-06-22 11:27:04 UTC (rev 436) @@ -20,27 +20,12 @@ import os import sys -import getopt +from optparse import OptionParser -def usage(): - print "Usage: pybridge-server [options]" - print "-h : Print this help message and exit." - print "-p PORT : Listen for connections on specified port." - print "-v : Print version number and exit." - - def main(): PORT = 5040 - - try: - opts, args = getopt.getopt(sys.argv[1:], 'hp:v', - ['help', 'port=', 'version']) - except getopt.GetoptError, error: - usage() - print "\nError: %s" % error - sys.exit(2) - + try: # If PyBridge is installed system-wide, this finds it automatically. import pybridge except ImportError: # Locate the PyBridge package. @@ -51,31 +36,27 @@ pythonpath = os.path.join(basedir, 'lib', 'python') else: pythonpath = basedir + sys.path.insert(0, pythonpath) # Place PyBridge package in PYTHONPATH. - import pybridge - - for opt, arg in opts: - if opt in ('-h', '--help'): - usage() - sys.exit(0) - elif opt in ('-p', '--port'): - try: - PORT = int(arg) - except ValueError: - usage() - print "\nError: invalid value %s specified for %s" % (arg, opt) - sys.exit(2) - elif opt in ('-v', '--version'): - print "PyBridge Server version %s" % pybridge.__version__ - sys.exit(0) - + try: + import pybridge + except ImportError: + raise SystemExit, "Fatal error: could not locate PyBridge installation." + + parser = OptionParser(version="PyBridge Server %s" % pybridge.__version__) + + parser.add_option('-p', '--port', type=int, dest='port', default=PORT, + help="listen for connections on specified port") + + options, args = parser.parse_args() + from twisted.internet import reactor from twisted.python import log log.startLogging(sys.stdout) # Log to stdout. - + # TODO: replace with a service. from pybridge.server import factory - reactor.listenTCP(PORT, factory) + reactor.listenTCP(options.port, factory) reactor.run() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |