home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Languages / python / PyObjC-0.47-MIHS / pyobjc-0.47-src / Demo / ObjC / PyServices / pyservicesdaemon.py < prev    next >
Encoding:
Python Source  |  1996-11-14  |  3.8 KB  |  144 lines

  1. #! /usr/local/bin/pyobjc
  2. ## change the above to the path to the python binary that contains
  3. ## the ObjC module.
  4.  
  5. #/**
  6. #*** Copyright (c) 1996 by Bill Bumgarner.  All Rights Reserved
  7. #*** 
  8. #*** This software may be used and distributed freely for any purpose
  9. #*** provided that this notice is included unchanged on any and all copies.
  10. #*** The author does not warrant or guarantee this software in any way.
  11. #*** 
  12. #*** 
  13. #*** All queries, patches, and discussions of the PyObjC project should be
  14. #*** directed to <objc-sig@python.org>.  The author can be reached via
  15. #*** <bbum@friday.com>.
  16. #*** 
  17. #*** $RCSfile: pyservicesdaemon.py,v $
  18. #*** 
  19. #*** $Revision: 1.4 $
  20. #*** 
  21. #*** $Date: 1996/11/15 02:33:31 $
  22. #*** 
  23. #**/
  24.  
  25. import ni
  26. ni.ni()  ## no longer necessary under 1.4
  27.  
  28. import sys
  29. import os
  30.  
  31. def showUsage(msg = None):
  32.    if msg:
  33.       print msg
  34.  
  35.    print """
  36. DPyServicesDaemon.py [-lib-path ...] [-services-path ...]
  37.     -lib-path path       adds path to paths searched for
  38.                          python modules (to the beginning of sys.path)
  39.     -services-path path  directory to be searched for services handlers
  40.  
  41. -lib-path and -services-path can be specified multiple times.
  42. -services-path defaults to "~/Library/PyServices:/LocalLibrary/PyServices".
  43.     Any new values are pre-pended to the default value!
  44. """
  45.    sys.exit(0)
  46.  
  47. try:
  48.    from Demiurge import DPyGetOpt
  49. except:
  50.    msg = """
  51. This package requires the Demiurge package.  It is available from:
  52.  
  53.     http://www.friday.com/~bbum/py-stuff/
  54.    """
  55.    showUsage(msg)
  56.  
  57. try:
  58.    import ObjC
  59. except:
  60.    msg = """
  61. This package requires the ObjC module. Binaries and source can be
  62. obtained from:
  63.  
  64.     ftp://www.thoughtport.net/pub/next/lang/
  65.     
  66. Ongoing development is supported via the Python Software Activity
  67. [PSA]\'s Objective-C SIG:
  68.  
  69.     http://www.python.org/sigs/objc-sig/
  70. """ #'
  71.    showUsage(msg)
  72.  
  73. try:
  74.    import PyServicesDelegate
  75.    import nsdefaults
  76. except:
  77.    msg = """
  78. This package requires the nsdefaults and PyServicesDelegate modules
  79. that are included with the ObjC module.  Binaries and source area
  80. available from:
  81.  
  82.     ftp://www.thoughtport.net/pub/next/lang/
  83.     
  84. Ongoing development is supported via the Python Software Activity
  85. [PSA]'s Objective-C SIG:
  86.  
  87.    http://www.python.org/sigs/objc-sig/
  88. """ # '  
  89.    showUsage(msg)
  90.  
  91. options = ['lib-path=s@',
  92.            'services-path=s@',
  93.            'check-in-as=s']
  94.  
  95. def main():
  96.    oP = DPyGetOpt.newFromOptionSpecification(options)
  97.    try:
  98.       oP.processArguments(sys.argv)
  99.    except:
  100.       showUsage(sys.exc_value)
  101.  
  102.    ### default paths
  103.    defaultPaths = ['~/Library/PyServices', '/LocalLibrary/PyServices']
  104.    defaultPaths = map(lambda p: os.path.expanduser(p), defaultPaths)
  105.  
  106.    ## grab any user specified python library paths...
  107.    lP = oP.valueForOption('lib-path', map(lambda p: p + '/lib/', defaultPaths))
  108.    ## and append 'em to sys.path
  109.    sys.path = lP + sys.path
  110.  
  111.    ## grab services paths
  112.    defaultHandlerPaths = map(lambda p: p + '/PyServicesHandlers', defaultPaths)
  113.    sP = oP.valueForOption('services-path')
  114.    if sP:
  115.       sP = sP + defaultHandlerPaths
  116.    else:
  117.       sP = defaultHandlerPaths
  118.  
  119.    ## find check in name
  120.    ciaName = oP.valueForOption('check-in-as', 'PyServices')
  121.  
  122.    ### import services daemon
  123.    from PyServicesPackage import PyServicesDaemon
  124.    from PyServicesPackage import PyServicesHandler
  125.  
  126.    ### create new services daemon object
  127.    psDaemon = PyServicesDaemon.newDaemon()
  128.  
  129.    ### create the handler-- the daemon will wrap it correctly.
  130.    psHandler = PyServicesHandler.newHandler(sP)
  131.  
  132.    ### this will create a Listener instance listening on the port
  133.    ### named 'ciaName'.  psHandler will handle all incoming services
  134.    ### requests.
  135.    psDaemon.addServicesPort(ciaName, psHandler)
  136.  
  137.    ### run the service (only returns on PyServices/Kill Daemon...)
  138.    sys.exit(psDaemon.run())
  139. ### end main()
  140.    
  141. ### invoke main...
  142. main()
  143.  
  144.