Beispiel #1
0
def setupPackagePath():
    """
    set up all project paths specified in the FLU_PROJECT_PATH environment
    variable.

    This should be called by every Flumotion binary before starting/importing
    any other flumotion code.
    """
    import os
    from flumotion.common import package, log
    from flumotion.configure import configure

    registryPaths = [
        configure.pythondir,
    ]
    if 'FLU_PROJECT_PATH' in os.environ:
        paths = os.environ['FLU_PROJECT_PATH']
        registryPaths += paths.split(':')

    log.debug('setup', 'registry paths: %s' % ", ".join(registryPaths))
    for path in registryPaths:
        log.debug('setup', 'registering package path: %s' % path)
        # we register with the path as part of the key, since
        # these aren't meant to be replaced
        package.getPackager().registerPackagePath(path,
                                                  "FLU_PROJECT_PATH_" + path)
Beispiel #2
0
        def unpackAndRegister((zips, toFetch, sums)):
            for name in toFetch:
                if name not in zips:
                    msg = "Missing bundle %s was not received"
                    self.warning(msg, name)
                    raise errors.NoBundleError(msg % name)

                b = bundle.Bundle(name)
                b.setZip(zips[name])
                path = self._unbundler.unbundle(b)

            # register all package paths; to do so we need to reverse sums
            sums.reverse()
            ret = []
            for name, md5 in sums:
                self.log('registerPackagePath for %s' % name)
                path = os.path.join(configure.cachedir, name, md5)
                if not os.path.exists(path):
                    self.warning("path %s for bundle %s does not exist",
                        path, name)
                else:
                    package.getPackager().registerPackagePath(path, name)
                ret.append((name, path))

            return ret
Beispiel #3
0
        def unpackAndRegister((zips, toFetch, sums)):
            for name in toFetch:
                if name not in zips:
                    msg = "Missing bundle %s was not received"
                    self.warning(msg, name)
                    raise errors.NoBundleError(msg % name)

                b = bundle.Bundle(name)
                b.setZip(zips[name])
                path = self._unbundler.unbundle(b)

            # register all package paths; to do so we need to reverse sums
            sums.reverse()
            ret = []
            for name, md5 in sums:
                self.log('registerPackagePath for %s' % name)
                path = os.path.join(configure.cachedir, name, md5)
                if not os.path.exists(path):
                    self.warning("path %s for bundle %s does not exist", path,
                                 name)
                else:
                    package.getPackager().registerPackagePath(path, name)
                ret.append((name, path))

            return ret
    def testPyRegisterBeforeImportWithoutHooks(self):
        # when registering mypackage paths before having imported anything,
        # __path__ does not get fixed up automatically

        # first show we cannot import mypackage
        self.assertRaises(ImportError, self._import, "mypackage")

        # register both projects
        packager = package.getPackager()
        packager.registerPackagePath(self.onedir, 'one', prefix="mypackage")
        packager.registerPackagePath(self.twodir, 'two', prefix="mypackage")

        self._failIfRaises(ImportError, self._import, "mypackage")

        # "import mypackage" imported mypackage from twodir, because it
        # was added last; also, it only has twodir in its __path__
        import mypackage
        self.failUnless(mypackage.__file__.startswith(self.twodir))
        self.assertEquals(len(mypackage.__path__), 1)
        self.failUnless(mypackage.__path__[0].startswith(self.twodir))

        # this means we can only import mypackage.B now, not mypackage.A
        self._failIfRaises(ImportError, self._import, "mypackage.B")
        self.assertRaises(ImportError, self._import, "mypackage.A")
        packager.unregister()
Beispiel #5
0
    def testPyRegisterBeforeImportWithoutHooks(self):
        # when registering mypackage paths before having imported anything,
        # __path__ does not get fixed up automatically

        # first show we cannot import mypackage
        self.assertRaises(ImportError, self._import, "mypackage")

        # register both projects
        packager = package.getPackager()
        packager.registerPackagePath(self.onedir, 'one', prefix="mypackage")
        packager.registerPackagePath(self.twodir, 'two', prefix="mypackage")

        self._failIfRaises(ImportError, self._import, "mypackage")

        # "import mypackage" imported mypackage from twodir, because it
        # was added last; also, it only has twodir in its __path__
        import mypackage
        self.failUnless(mypackage.__file__.startswith(self.twodir))
        self.assertEquals(len(mypackage.__path__), 1)
        self.failUnless(mypackage.__path__[0].startswith(self.twodir))

        # this means we can only import mypackage.B now, not mypackage.A
        self._failIfRaises(ImportError, self._import, "mypackage.B")
        self.assertRaises(ImportError, self._import, "mypackage.A")
        packager.unregister()
Beispiel #6
0
def setupPackagePath():
    """
    set up all project paths specified in the FLU_PROJECT_PATH environment
    variable.

    This should be called by every Flumotion binary before starting/importing
    any other flumotion code.
    """
    import os
    from flumotion.common import package, log
    from flumotion.configure import configure

    registryPaths = [configure.pythondir, ]
    if 'FLU_PROJECT_PATH' in os.environ:
        paths = os.environ['FLU_PROJECT_PATH']
        registryPaths += paths.split(':')

    log.debug('setup', 'registry paths: %s' % ", ".join(registryPaths))
    for path in registryPaths:
        log.debug('setup', 'registering package path: %s' % path)
        # we register with the path as part of the key, since
        # these aren't meant to be replaced
        package.getPackager().registerPackagePath(path,
            "FLU_PROJECT_PATH_" + path)
Beispiel #7
0
    def remote_bootstrap(self, workerName, host, port,
                         transport, authenticator, packagePaths):
        """
        I receive the information on how to connect to the manager. I also set
        up package paths to be able to run the component.

        Called by the worker's JobAvatar.

        @param workerName:    the name of the worker running this job
        @type  workerName:    str
        @param host:          the host that is running the manager
        @type  host:          str
        @param port:          port on which the manager is listening
        @type  port:          int
        @param transport:     'tcp' or 'ssl'
        @type  transport:     str
        @param authenticator: remote reference to the worker-side authenticator
        @type  authenticator: L{twisted.spread.pb.RemoteReference} to a
                              L{flumotion.twisted.pb.Authenticator}
        @param packagePaths:  ordered list of
                              (package name, package path) tuples
        @type  packagePaths:  list of (str, str)
        """
        self._workerName = workerName
        self._managerHost = host
        self._managerPort = port
        self._managerTransport = transport
        if authenticator:
            self._authenticator = fpb.RemoteAuthenticator(authenticator)
        else:
            self.debug('no authenticator, will not be able to log '
                       'into manager')
            self._authenticator = None

        packager = package.getPackager()
        for name, path in packagePaths:
            self.debug('registering package path for %s' % name)
            self.log('... from path %s' % path)
            packager.registerPackagePath(path, name)
Beispiel #8
0
    def remote_bootstrap(self, workerName, host, port, transport,
                         authenticator, packagePaths):
        """
        I receive the information on how to connect to the manager. I also set
        up package paths to be able to run the component.

        Called by the worker's JobAvatar.

        @param workerName:    the name of the worker running this job
        @type  workerName:    str
        @param host:          the host that is running the manager
        @type  host:          str
        @param port:          port on which the manager is listening
        @type  port:          int
        @param transport:     'tcp' or 'ssl'
        @type  transport:     str
        @param authenticator: remote reference to the worker-side authenticator
        @type  authenticator: L{twisted.spread.pb.RemoteReference} to a
                              L{flumotion.twisted.pb.Authenticator}
        @param packagePaths:  ordered list of
                              (package name, package path) tuples
        @type  packagePaths:  list of (str, str)
        """
        self._workerName = workerName
        self._managerHost = host
        self._managerPort = port
        self._managerTransport = transport
        if authenticator:
            self._authenticator = fpb.RemoteAuthenticator(authenticator)
        else:
            self.debug('no authenticator, will not be able to log '
                       'into manager')
            self._authenticator = None

        packager = package.getPackager()
        for name, path in packagePaths:
            self.debug('registering package path for %s' % name)
            self.log('... from path %s' % path)
            packager.registerPackagePath(path, name)
Beispiel #9
0
try:
    import docutils
except ImportError:
    print "Not importing docutils"
    pass

from flumotion.common import boot
boot.init_gobject()
boot.init_gst()
from twisted.internet import gtk2reactor
gtk2reactor.install(useGtk=False)

# reinstall our import hooks that could have been overridden by
# pygtk/pygst ltihooks
from flumotion.common import package
package.getPackager().install()

# monkey patching twisted doc errors
from twisted.spread import pb


def login(self, credentials, client=None):
    """Login and get perspective from remote PB server.

    Currently only credentials implementing IUsernamePassword are
    supported.

    @return: Deferred of RemoteReference to the perspective."""


def getRootObject(self):
Beispiel #10
0
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)
Beispiel #11
0
    from misc import setup
    setup.setup()
except ImportError:
    print "Not importing misc.setup"
    pass

from flumotion.common import boot
boot.init_gobject()
boot.init_gst()
from twisted.internet import gtk2reactor
gtk2reactor.install(useGtk=False)

# reinstall our import hooks that could have been overridden by
# pygtk/pygst ltihooks
from flumotion.common import package
package.getPackager().install()

# monkey patching twisted doc errors
from twisted.spread import pb


def login(self, credentials, client=None):
    """Login and get perspective from remote PB server.

    Currently only credentials implementing IUsernamePassword are
    supported.

    @return: Deferred of RemoteReference to the perspective."""


def getRootObject(self):
 def testCurrent(self):
     packager = package.getPackager()
     packager.registerPackagePath(self.tempdir, 'tempdir')
     packager.unregister()
Beispiel #13
0
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)
Beispiel #14
0
 def testCurrent(self):
     packager = package.getPackager()
     packager.registerPackagePath(self.tempdir, 'tempdir')
     packager.unregister()
Beispiel #15
0
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)