import os
import logging

from kaa.base import ipc
from client import *
from server import *

__all__ = [ 'connect' ]

# connected client object
_client = None

def connect(epgdb, logfile='/tmp/kaa-epg.log', loglevel=logging.INFO):
    """
    """
    global _client

    # get server filename
    server = os.path.join(os.path.dirname(__file__), 'server.py')

    if epgdb.find(':') >= 0:
        # epg is remote:  host:port
        # TODO: create socket, pass it to client
        _client = GuideClient("epg")

    else:
        # epg is local
        _client = ipc.launch([server, logfile, str(loglevel), epgdb], 2, GuideClient, "epg")
    return _client



import os
import logging
from socket import gethostbyname, gethostname

from kaa.base import ipc
from client import *
from server import *

__all__ = [ 'connect', 'DEFAULT_EPG_PORT', 'GuideClient', 'GuideServer' ]

# connected client object
_client = None

def connect(epgdb, address='127.0.0.1', logfile='/tmp/kaa-epg.log', loglevel=logging.INFO):
    """
    """
    global _client

    if _client:
        return _client

    if address.split(':')[0] not in ['127.0.0.1', '0.0.0.0'] and \
       address != gethostbyname(gethostname()):
        # epg is remote:  host:port
        if address.find(':') >= 0:
            host, port = address.split(':', 1)
        else:
            host = address
            port = DEFAULT_EPG_PORT

        # create socket, pass it to client
        _client = GuideClient((host, port))

    else:
        # EPG is local, only use unix socket

        # get server filename
        server = os.path.join(os.path.dirname(__file__), 'server.py')

        _client = ipc.launch([server, logfile, str(loglevel), epgdb, address], 
                              2, GuideClient, "epg")

    return _client



Add the ability to use inet socket as well.
Add the ability to use inet socket as well.


git-svn-id: ffaf500d3baede20d2f41eac1d275ef07405e077@1236 a8f5125c-1e01-0410-8897-facf34644b8e

  import os
  import logging
+ from socket import gethostbyname, gethostname
  
  from kaa.base import ipc
  from client import *
  from server import *
  
- __all__ = [ 'connect' ]
+ __all__ = [ 'connect', 'DEFAULT_EPG_PORT', 'GuideClient', 'GuideServer' ]
  
  # connected client object
  _client = None
  
- def connect(epgdb, logfile='/tmp/kaa-epg.log', loglevel=logging.INFO):
+ def connect(epgdb, address='127.0.0.1', logfile='/tmp/kaa-epg.log', loglevel=logging.INFO):
      """
      """
      global _client
  
-     # get server filename
-     server = os.path.join(os.path.dirname(__file__), 'server.py')
+     if _client:
+         return _client
  
-     if epgdb.find(':') >= 0:
+     if address.split(':')[0] not in ['127.0.0.1', '0.0.0.0'] and \
+        address != gethostbyname(gethostname()):
          # epg is remote:  host:port
+         if address.find(':') >= 0:
+             host, port = address.split(':', 1)
+         else:
+             host = address
+             port = DEFAULT_EPG_PORT
+ 
-         # TODO: create socket, pass it to client
+         # create socket, pass it to client
-         _client = GuideClient("epg")
+         _client = GuideClient((host, port))
  
      else:
-         # epg is local
+         # EPG is local, only use unix socket
+ 
+         # get server filename
+         server = os.path.join(os.path.dirname(__file__), 'server.py')
+ 
-         _client = ipc.launch([server, logfile, str(loglevel), epgdb], 2, GuideClient, "epg")
+         _client = ipc.launch([server, logfile, str(loglevel), epgdb, address], 
+                               2, GuideClient, "epg")
+ 
      return _client
  
  
  
Add the ability to use inet socket as well.
## Code Before:
import os
import logging

from kaa.base import ipc
from client import *
from server import *

__all__ = [ 'connect' ]

# connected client object
_client = None

def connect(epgdb, logfile='/tmp/kaa-epg.log', loglevel=logging.INFO):
    """
    """
    global _client

    # get server filename
    server = os.path.join(os.path.dirname(__file__), 'server.py')

    if epgdb.find(':') >= 0:
        # epg is remote:  host:port
        # TODO: create socket, pass it to client
        _client = GuideClient("epg")

    else:
        # epg is local
        _client = ipc.launch([server, logfile, str(loglevel), epgdb], 2, GuideClient, "epg")
    return _client



## Instruction:
Add the ability to use inet socket as well.
## Code After:
import os
import logging
from socket import gethostbyname, gethostname

from kaa.base import ipc
from client import *
from server import *

__all__ = [ 'connect', 'DEFAULT_EPG_PORT', 'GuideClient', 'GuideServer' ]

# connected client object
_client = None

def connect(epgdb, address='127.0.0.1', logfile='/tmp/kaa-epg.log', loglevel=logging.INFO):
    """
    """
    global _client

    if _client:
        return _client

    if address.split(':')[0] not in ['127.0.0.1', '0.0.0.0'] and \
       address != gethostbyname(gethostname()):
        # epg is remote:  host:port
        if address.find(':') >= 0:
            host, port = address.split(':', 1)
        else:
            host = address
            port = DEFAULT_EPG_PORT

        # create socket, pass it to client
        _client = GuideClient((host, port))

    else:
        # EPG is local, only use unix socket

        # get server filename
        server = os.path.join(os.path.dirname(__file__), 'server.py')

        _client = ipc.launch([server, logfile, str(loglevel), epgdb, address], 
                              2, GuideClient, "epg")

    return _client


