home *** CD-ROM | disk | FTP | other *** search
- #! /usr/local/bin/pyobjc
- ## change the above to the path to the python binary that contains
- ## the ObjC module.
-
- #/**
- #*** Copyright (c) 1996 by Bill Bumgarner. All Rights Reserved
- #***
- #*** This software may be used and distributed freely for any purpose
- #*** provided that this notice is included unchanged on any and all copies.
- #*** The author does not warrant or guarantee this software in any way.
- #***
- #***
- #*** All queries, patches, and discussions of the PyObjC project should be
- #*** directed to <objc-sig@python.org>. The author can be reached via
- #*** <bbum@friday.com>.
- #***
- #*** $RCSfile: pyservicesdaemon.py,v $
- #***
- #*** $Revision: 1.4 $
- #***
- #*** $Date: 1996/11/15 02:33:31 $
- #***
- #**/
-
- import ni
- ni.ni() ## no longer necessary under 1.4
-
- import sys
- import os
-
- def showUsage(msg = None):
- if msg:
- print msg
-
- print """
- DPyServicesDaemon.py [-lib-path ...] [-services-path ...]
- -lib-path path adds path to paths searched for
- python modules (to the beginning of sys.path)
- -services-path path directory to be searched for services handlers
-
- -lib-path and -services-path can be specified multiple times.
- -services-path defaults to "~/Library/PyServices:/LocalLibrary/PyServices".
- Any new values are pre-pended to the default value!
- """
- sys.exit(0)
-
- try:
- from Demiurge import DPyGetOpt
- except:
- msg = """
- This package requires the Demiurge package. It is available from:
-
- http://www.friday.com/~bbum/py-stuff/
- """
- showUsage(msg)
-
- try:
- import ObjC
- except:
- msg = """
- This package requires the ObjC module. Binaries and source can be
- obtained from:
-
- ftp://www.thoughtport.net/pub/next/lang/
-
- Ongoing development is supported via the Python Software Activity
- [PSA]\'s Objective-C SIG:
-
- http://www.python.org/sigs/objc-sig/
- """ #'
- showUsage(msg)
-
- try:
- import PyServicesDelegate
- import nsdefaults
- except:
- msg = """
- This package requires the nsdefaults and PyServicesDelegate modules
- that are included with the ObjC module. Binaries and source area
- available from:
-
- ftp://www.thoughtport.net/pub/next/lang/
-
- Ongoing development is supported via the Python Software Activity
- [PSA]'s Objective-C SIG:
-
- http://www.python.org/sigs/objc-sig/
- """ # '
- showUsage(msg)
-
- options = ['lib-path=s@',
- 'services-path=s@',
- 'check-in-as=s']
-
- def main():
- oP = DPyGetOpt.newFromOptionSpecification(options)
- try:
- oP.processArguments(sys.argv)
- except:
- showUsage(sys.exc_value)
-
- ### default paths
- defaultPaths = ['~/Library/PyServices', '/LocalLibrary/PyServices']
- defaultPaths = map(lambda p: os.path.expanduser(p), defaultPaths)
-
- ## grab any user specified python library paths...
- lP = oP.valueForOption('lib-path', map(lambda p: p + '/lib/', defaultPaths))
- ## and append 'em to sys.path
- sys.path = lP + sys.path
-
- ## grab services paths
- defaultHandlerPaths = map(lambda p: p + '/PyServicesHandlers', defaultPaths)
- sP = oP.valueForOption('services-path')
- if sP:
- sP = sP + defaultHandlerPaths
- else:
- sP = defaultHandlerPaths
-
- ## find check in name
- ciaName = oP.valueForOption('check-in-as', 'PyServices')
-
- ### import services daemon
- from PyServicesPackage import PyServicesDaemon
- from PyServicesPackage import PyServicesHandler
-
- ### create new services daemon object
- psDaemon = PyServicesDaemon.newDaemon()
-
- ### create the handler-- the daemon will wrap it correctly.
- psHandler = PyServicesHandler.newHandler(sP)
-
- ### this will create a Listener instance listening on the port
- ### named 'ciaName'. psHandler will handle all incoming services
- ### requests.
- psDaemon.addServicesPort(ciaName, psHandler)
-
- ### run the service (only returns on PyServices/Kill Daemon...)
- sys.exit(psDaemon.run())
- ### end main()
-
- ### invoke main...
- main()
-
-