Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

git-svn-id: http://evserver.googlecode.com/svn/trunk@72 e9bb6d7e-af12…

…-11dd-bad7-87afd3b02348
  • Loading branch information...
commit ec17749720a03607b084419a62fc52a0b89a9e31 1 parent 23ccf90
majek04 authored
Showing with 44 additions and 51 deletions.
  1. +29 −32 evserver/main.py
  2. +15 −19 evserver/server.py
View
61 evserver/main.py
@@ -84,6 +84,14 @@ def get_libevent_version(binary):
'''
def find_libevent_binary(userpath):
+ def test_location(dllname):
+ try:
+ a = ctypes.CDLL(dllname)
+ a.close()
+ return True
+ except OSError:
+ return False
+
def getpath(userpath):
if userpath:
if os.path.isdir(userpath):
@@ -92,41 +100,30 @@ def getpath(userpath):
return os.path.realpath(os.path.expanduser(userpath))
raise Exception("%r is not a valid path to %s" % (userpath,libeventbin))
- if os.path.exists('./%s' % libeventbin):
- return './%s' % libeventbin
-
- if os.path.exists(resource_filename(__name__, libeventbin)):
- return resource_filename(__name__, libeventbin)
-
- try:
- a = ctypes.CDLL(libeventbin)
- a.close()
- return libeventbin
- except OSError:
- pass
-
- if os.path.exists('/usr/local/lib/%s' % libeventbin):
- return '/usr/local/lib/%s' % libeventbin
-
- try:
- so = ctypes.util.find_library('event')
- a = ctypes.CDLL(so)
- a.close()
- return so
- except OSError:
- pass
+ dllnames = [
+ resource_filename(__name__, libeventbin),
+ './%s' % libeventbin,
+ '%s' % libeventbin,
+ ctypes.util.find_library('event') or '_invalid_',
+ '/usr/local/lib/%s' % libeventbin,
+ 'event',
+ ]
+ for dllname in dllnames:
+ if test_location(dllname):
+ return dllname
- return libeventbin
+ raise OSError
- so = getpath(userpath)
try:
+ so = getpath(userpath)
ver = get_libevent_version(so)
return so, ver
except OSError:
- raise Exception("**** %r not found or can't be loaded ****\n" % (libeventbin)+
- " try setting the location using --libevent </path/to/the/%s> flag\n" % (libeventbin)+
- " or use 'LD_LIBRARY_PATH=\"../pathtolibeventsobinaries\" %s ...'.\n" % (sys.argv[0]) +
- " you can also try to install libevent in current directory %r or /usr/local/lib" % (os.getcwd()))
+ log.critical("**** %r not found or can't be loaded ****\n" % (libeventbin)+
+ " try setting the location using --libevent </path/to/the/%s> flag\n" % (libeventbin)+
+ " or use 'LD_LIBRARY_PATH=\"../pathtolibeventsobinaries\" %s ...'.\n" % (sys.argv[0]) +
+ " you can also try to install libevent in current directory %r or /usr/local/lib" % (os.getcwd()))
+ os.abort()
@@ -225,16 +222,16 @@ def main(args):
log.info("Running with verbosity %i (>=%s)" % (verbosity, logging.getLevelName(verbosity)))
log.info("Framework=%r, Main dir=%r, args=%r" % (options.framework, os.getcwd(), args))
- oldcwd = os.getcwd()
- os.chdir( resource_filename(__name__, '') )
+ old_cwd = os.getcwd()
+ os.chdir(resource_filename(__name__, ''))
libeventbinary, libeventversion = find_libevent_binary(options.libeventbinary)
ctypes.libeventbinary = libeventbinary
ctypes.libeventbinary_version = libeventversion
import server
+ os.chdir(old_cwd)
log.info("libevent loaded from %r, ver %r" % (libeventbinary, libeventversion,))
- os.chdir(oldcwd)
server.main_init()
View
34 evserver/server.py
@@ -3,15 +3,20 @@
import ctypes
import sys
-import os
import signal
import utils
+import gc
+import os, os.path, logging
+import traceback
+import time
+import StringIO
+import datetime
+from functools import wraps
from pkg_resources import resource_filename
-v = ctypes.libeventbinary_version.replace('-','_').replace('.','_')
+log = logging.getLogger(os.path.basename(__file__))
-oldcwd = os.getcwd()
-os.chdir( os.path.join(resource_filename(__name__, ''), '..') )
+v = ctypes.libeventbinary_version.replace('-','_').replace('.','_')
modulename = 'evserver.ctypes_event_%s' % v
try:
@@ -23,24 +28,15 @@ def my_import(name):
return mod
libevent = my_import(modulename)
except (AttributeError, ImportError), e:
- raise Exception("**** libevent ctypes bindings %r are broken - probably wrong version of binary ****\n" % (modulename,)+
- " currently, libevent.so is loaded from %r \n" %(ctypes.libeventbinary,)+
- " try to specify different 'libevent.so' using '--libevent </path/to/libevent.so> \n"+
- " if that fails, try to create new ctypes bindings for libevent using 'make bindings'\n"+
- " Tried to load the bindings from directory: %r\nError message: %r\n" % (os.getcwd(), str(e)) )
-os.chdir( oldcwd )
+ log.critical("**** libevent ctypes bindings %r are broken - probably wrong version of binary ****\n" % (modulename,)+
+ " currently, libevent.so is loaded from %r \n" %(ctypes.libeventbinary,)+
+ " try to specify different 'libevent.so' using '--libevent </path/to/libevent.so> \n"+
+ " if that fails, try to create new ctypes bindings for libevent using 'make bindings'\n"+
+ " Tried to load the bindings from directory: %r\nError message: %r\n" % (os.getcwd(), str(e)) )
+ os.abort()
-import traceback
-import time
-from functools import wraps
-import StringIO
-import datetime
import request
-import gc
-import os, os.path, logging
-
-log = logging.getLogger(os.path.basename(__file__))
Please sign in to comment.
Something went wrong with that request. Please try again.