def boot(path, gtk=False, gst=True, installReactor=True): # python 2.5 and twisted < 2.5 don't work together pythonMM = sys.version_info[0:2] from twisted.copyright import version twistedMM = tuple([int(n) for n in version.split('.')[0:2]]) if pythonMM >= (2, 5) and twistedMM < (2, 5): raise SystemError("Twisted versions older than 2.5.0 do not work with " "Python 2.5 and newer. " "Please upgrade Twisted or downgrade Python.") if gtk or gst: init_gobject() if gtk: init_kiwi() if gst: from flumotion.configure import configure configure.gst_version = init_gst() global USE_GTK, USE_GST USE_GTK = gtk USE_GST = gst init_option_parser(gtk, gst) # installing the reactor could override our packager's import hooks ... if installReactor: from twisted.internet import gtk2reactor try: gtk2reactor.install(useGtk=gtk) except RuntimeError, e: safeprintf(sys.stderr, 'ERROR: %s\n', e) sys.exit(1)
def boot(path, gtk=False, gst=True, installReactor=True): # python 2.5 and twisted < 2.5 don't work together pythonMM = sys.version_info[0:2] from twisted.copyright import version twistedMM = tuple([int(n) for n in version.split('.')[0:2]]) if pythonMM >= (2, 5) and twistedMM < (2, 5): raise SystemError( "Twisted versions older than 2.5.0 do not work with " "Python 2.5 and newer. " "Please upgrade Twisted or downgrade Python.") if gtk or gst: init_gobject() if gtk: init_kiwi() if gst: from flumotion.configure import configure configure.gst_version = init_gst() from gi.repository import GstNet global USE_GTK, USE_GST USE_GTK=gtk USE_GST=gst init_option_parser(gtk, gst) # installing the reactor could override our packager's import hooks ... if installReactor: from twisted.internet import gtk3reactor try: gtk3reactor.install() except RuntimeError, e: safeprintf(sys.stderr, 'ERROR: %s\n', e) sys.exit(1)
# # there is no race condition here -- the reactor doesn't handle # signals until it is run(). reactor.killed = False def setkilled(killed): reactor.killed = killed reactor.addSystemEventTrigger('before', 'startup', setkilled, False) reactor.addSystemEventTrigger('before', 'shutdown', setkilled, True) from flumotion.twisted import reflect from flumotion.common import errors from flumotion.common import setup setup.setup() from flumotion.common import log log.logTwisted() main = reflect.namedAny(path) wrapped = wrap_for_profiling(main) wrapped.__name__ = main.__name__ try: sys.exit(wrapped(sys.argv)) except (errors.FatalError, SystemError), e: safeprintf(sys.stderr, 'ERROR: %s\n', e) sys.exit(1)
def boot(path, gtk=False, gst=True, installReactor=True): # python 2.5 and twisted < 2.5 don't work together pythonMM = sys.version_info[0:2] from twisted.copyright import version twistedMM = tuple([int(n) for n in version.split('.')[0:2]]) if pythonMM >= (2, 5) and twistedMM < (2, 5): raise SystemError( "Twisted versions older than 2.5.0 do not work with " "Python 2.5 and newer. " "Please upgrade Twisted or downgrade Python.") if gtk or gst: init_gobject() if gst: from flumotion.configure import configure configure.gst_version = init_gst() global USE_GTK, USE_GST USE_GTK=gtk USE_GST=gst init_option_parser(gtk, gst) # installing the reactor could override our packager's import hooks ... if installReactor: from twisted.internet import gtk2reactor gtk2reactor.install(useGtk=gtk) from twisted.internet import reactor # ... so we install them again here to be safe from flumotion.common import package package.getPackager().install() # this monkeypatched var exists to let reconnecting factories know # when they should warn about a connection being closed, and when # they shouldn't because the system is shutting down. # # there is no race condition here -- the reactor doesn't handle # signals until it is run(). reactor.killed = False def setkilled(killed): reactor.killed = killed reactor.addSystemEventTrigger('before', 'startup', setkilled, False) reactor.addSystemEventTrigger('before', 'shutdown', setkilled, True) from flumotion.twisted import reflect from flumotion.common import errors from flumotion.common import setup setup.setup() from flumotion.common import log log.logTwisted() # we redefine catching __pychecker__ = 'no-reuseattr' if os.getenv('FLU_PROFILE'): def catching(proc, *args, **kwargs): import statprof statprof.start() try: return proc(*args, **kwargs) finally: statprof.stop() statprof.display() elif os.getenv('FLU_ATEXIT'): def catching(proc, *args, **kwargs): env = os.getenv('FLU_ATEXIT').split(' ') fqfn = env.pop(0) log.info('atexit', 'FLU_ATEXIT set, will call %s(*%r) on exit', fqfn, env) atexitproc = reflect.namedAny(fqfn) try: return proc(*args, **kwargs) finally: log.info('atexit', 'trying to call %r(*%r)', atexitproc, env) atexitproc(*env) else: def catching(proc, *args, **kwargs): return proc(*args, **kwargs) main = reflect.namedAny(path) try: sys.exit(catching(main, sys.argv)) except (errors.FatalError, SystemError), e: safeprintf(sys.stderr, 'ERROR: %s\n', e) sys.exit(1)
def addListener(self, listener, set=None, append=None, remove=None, setitem=None, delitem=None, invalidate=None, set_=None): """ Adds a listener to the remote cache. The caller will be notified of state events via the functions given as the 'set', 'append', and 'remove', 'setitem', and 'delitem' keyword arguments. Always call this method using keyword arguments for the functions; calling them with positional arguments is not supported. Setting one of the event handlers to None will ignore that event. It is an error for all event handlers to be None. @param listener: new listener object that wants to receive cache state change notifications. @type listener: object implementing L{flumotion.twisted.flavors.IStateListener} @param set_: procedure to call when a value is set @type set_: procedure(object, key, value) -> None @param append: procedure to call when a value is appended to a list @type append: procedure(object, key, value) -> None @param remove: procedure to call when a value is removed from a list @type remove: procedure(object, key, value) -> None @param setitem: procedure to call when a value is set in a dict @type setitem: procedure(object, key, subkey, value) -> None @param delitem: procedure to call when a value is removed from a dict. @type delitem: procedure(object, key, subkey, value) -> None @param invalidate: procedure to call when this cache has been invalidated. @type invalidate: procedure(object) -> None """ # F0.8: remove set if set: import warnings warnings.warn('Please use the set_ kwarg instead', DeprecationWarning, stacklevel=2) set_ = set if not (set_ or append or remove or setitem or delitem or invalidate): # FIXME: remove this behavior in F0.6 import sys log.safeprintf(sys.stderr, "Warning: Use of deprecated %r.addListener(%r)" " without explicit event handlers\n", self, listener) set_ = listener.stateSet append = listener.stateAppend remove = listener.stateRemove self._ensureListeners() if listener in self._listeners: raise KeyError( "%r is already a listener of %r" % (listener, self)) self._listeners[listener] = [set_, append, remove, setitem, delitem, invalidate] if invalidate and hasattr(self, '_cache_invalid'): invalidate(self)
def boot(path, gtk=False, gst=True, installReactor=True): # python 2.5 and twisted < 2.5 don't work together pythonMM = sys.version_info[0:2] from twisted.copyright import version twistedMM = tuple([int(n) for n in version.split('.')[0:2]]) if pythonMM >= (2, 5) and twistedMM < (2, 5): raise SystemError("Twisted versions older than 2.5.0 do not work with " "Python 2.5 and newer. " "Please upgrade Twisted or downgrade Python.") if gtk or gst: init_gobject() if gtk: init_kiwi() if gst: from flumotion.configure import configure configure.gst_version = init_gst() global USE_GTK, USE_GST USE_GTK = gtk USE_GST = gst init_option_parser(gtk, gst) # installing the reactor could override our packager's import hooks ... if installReactor: from twisted.internet import gtk2reactor gtk2reactor.install(useGtk=gtk) from twisted.internet import reactor # ... so we install them again here to be safe from flumotion.common import package package.getPackager().install() # this monkeypatched var exists to let reconnecting factories know # when they should warn about a connection being closed, and when # they shouldn't because the system is shutting down. # # there is no race condition here -- the reactor doesn't handle # signals until it is run(). reactor.killed = False def setkilled(killed): reactor.killed = killed reactor.addSystemEventTrigger('before', 'startup', setkilled, False) reactor.addSystemEventTrigger('before', 'shutdown', setkilled, True) from flumotion.twisted import reflect from flumotion.common import errors from flumotion.common import setup setup.setup() from flumotion.common import log log.logTwisted() main = reflect.namedAny(path) wrapped = wrap_for_profiling(main) wrapped.__name__ = main.__name__ try: sys.exit(wrapped(sys.argv)) except (errors.FatalError, SystemError), e: safeprintf(sys.stderr, 'ERROR: %s\n', e) sys.exit(1)
def boot(path, gtk=False, gst=True, installReactor=True): # python 2.5 and twisted < 2.5 don't work together pythonMM = sys.version_info[0:2] from twisted.copyright import version twistedMM = tuple([int(n) for n in version.split('.')[0:2]]) if pythonMM >= (2, 5) and twistedMM < (2, 5): raise SystemError( "Twisted versions older than 2.5.0 do not work with " "Python 2.5 and newer. " "Please upgrade Twisted or downgrade Python.") if gtk or gst: init_gobject() if gtk: init_kiwi() if gst: from flumotion.configure import configure configure.gst_version = init_gst() global USE_GTK, USE_GST USE_GTK=gtk USE_GST=gst init_option_parser(gtk, gst) # installing the reactor could override our packager's import hooks ... if installReactor: from twisted.internet import gtk2reactor gtk2reactor.install(useGtk=gtk) from twisted.internet import reactor # ... so we install them again here to be safe from flumotion.common import package package.getPackager().install() # this monkeypatched var exists to let reconnecting factories know # when they should warn about a connection being closed, and when # they shouldn't because the system is shutting down. # # there is no race condition here -- the reactor doesn't handle # signals until it is run(). reactor.killed = False def setkilled(killed): reactor.killed = killed reactor.addSystemEventTrigger('before', 'startup', setkilled, False) reactor.addSystemEventTrigger('before', 'shutdown', setkilled, True) from flumotion.twisted import reflect from flumotion.common import errors from flumotion.common import setup setup.setup() from flumotion.common import log log.logTwisted() main = reflect.namedAny(path) wrapped = wrap_for_profiling(main) wrapped.__name__ = main.__name__ try: sys.exit(wrapped(sys.argv)) except (errors.FatalError, SystemError), e: safeprintf(sys.stderr, 'ERROR: %s\n', e) sys.exit(1)
# # there is no race condition here -- the reactor doesn't handle # signals until it is run(). reactor.killed = False def setkilled(killed): reactor.killed = killed reactor.addSystemEventTrigger('before', 'startup', setkilled, False) reactor.addSystemEventTrigger('before', 'shutdown', setkilled, True) from flumotion.twisted import reflect from flumotion.common import errors from flumotion.common import setup setup.setup() from flumotion.common import log log.logTwisted() main = reflect.namedAny(path) wrapped = wrap_for_profiling(main) wrapped.__name__ = main.__name__ try: sys.exit(wrapped(sys.argv)) except (errors.FatalError, SystemError), e: safeprintf(sys.stderr, 'ERROR: %s\n', e) sys.exit(1)