Exemplo n.º 1
0
    def test_deployedMode(self):
        """
        The C{dropin.cache} file may not be writable: the cache should still be
        attainable, but an error should be logged to show that the cache
        couldn't be updated.
        """
        # Generate the cache
        plugin.getCache(self.module)

        # Add a new plugin
        FilePath(__file__).sibling('plugin_extra1.py').copyTo(
            self.package.child('pluginextra.py'))

        os.chmod(self.package.path, 0500)
        # Change the right of dropin.cache too for windows
        os.chmod(self.package.child('dropin.cache').path, 0400)
        self.addCleanup(os.chmod, self.package.path, 0700)
        self.addCleanup(os.chmod,
                        self.package.child('dropin.cache').path, 0700)

        cache = plugin.getCache(self.module)
        # The new plugin should be reported
        self.assertIn('pluginextra', cache)
        self.assertIn(self.originalPlugin, cache)

        errors = self.flushLoggedErrors()
        self.assertEquals(len(errors), 1)
        # Windows report OSError, others IOError
        errors[0].trap(OSError, IOError)
Exemplo n.º 2
0
    def test_deployedMode(self):
        """
        The C{dropin.cache} file may not be writable: the cache should still be
        attainable, but an error should be logged to show that the cache
        couldn't be updated.
        """
        # Generate the cache
        plugin.getCache(self.module)

        # Add a new plugin
        FilePath(__file__).sibling('plugin_extra1.py'
            ).copyTo(self.package.child('pluginextra.py'))

        os.chmod(self.package.path, 0500)
        # Change the right of dropin.cache too for windows
        os.chmod(self.package.child('dropin.cache').path, 0400)
        self.addCleanup(os.chmod, self.package.path, 0700)
        self.addCleanup(os.chmod,
            self.package.child('dropin.cache').path, 0700)

        cache = plugin.getCache(self.module)
        # The new plugin should be reported
        self.assertIn('pluginextra', cache)
        self.assertIn(self.originalPlugin, cache)

        errors = self.flushLoggedErrors()
        self.assertEquals(len(errors), 1)
        # Windows report OSError, others IOError
        errors[0].trap(OSError, IOError)
Exemplo n.º 3
0
    def get(room):
        if room in (None, ""): room = "None"

        if not room in House.rooms:
            if FX.appModule:
                app = FX.appModule
                if room in ("__CONFIG__", "__WIDGETQUERY__"): app = "wallaby.apps.inspector"

                try:
                    from twisted.plugin import getCache
                    pkg = __import__(app + '.rooms', globals(), locals(), ["*"], 0)
                    modules = getCache(pkg)

                    if room.lower() in modules:
                        mod = FX.imp(app + '.rooms.' + room.lower())
                        if mod:
                            cls = room.capitalize()

                            if cls in mod.__dict__:
                                ctx = House.rooms[room] = mod.__dict__[cls](room)
                                return ctx
                except:
                    pass
                        
            # No room template found. Create generic room
            House.rooms[room] = Room(room)

        return House.rooms[room]
    def loadUIFiles(self):
        self._sheetPrototypes = {}

        prefs = []

        import wallaby.frontends as frontends
        from twisted.plugin import getCache

        for p in FX.packagePath(FX.appModule + ".prefs"): prefs.append(p)
        for frontend in getCache(frontends):
            for p in FX.packagePath("wallaby.frontends." + frontend + ".prefs"): prefs.append(p)

        import os
        for path in prefs:
            root = re.sub(r'[/\\]','.', path).replace('..', '')
            root = re.sub(r'^.*wallaby\.', 'wallaby.', root)
            files = os.listdir(path)
 
            for file in files:
                if '.py' in file and '.pyc' not in file and 'UI_' in file:
                    basename, ext = os.path.splitext(file)
                    if ext == '.py':
                        mod = FX.imp(root + '.' + basename)
                        print "Loading prefs sheet", root + '.' + basename, mod
                        if mod == None: continue
   
                        import string 
                        cls = basename[0] + string.lower(basename[1]) + basename[2] + string.upper(basename[3]) + basename[4:]
    
                        sheetName = unicode(basename.replace('UI_', ''))
    
                        if not cls in mod.__dict__: continue
                        self._sheetPrototypes[sheetName] = mod.__dict__[cls]
Exemplo n.º 5
0
    def test_cache(self):
        """
        Check that the cache returned by L{plugin.getCache} hold the plugin
        B{testplugin}, and that this plugin has the properties we expect:
        provide L{TestPlugin}, has the good name and description, and can be
        loaded successfully.
        """
        cache = plugin.getCache(self.module)

        dropin = cache[self.originalPlugin]
        self.assertEquals(dropin.moduleName,
                          'mypackage.%s' % (self.originalPlugin,))
        self.assertIn("I'm a test drop-in.", dropin.description)

        # Note, not the preferred way to get a plugin by its interface.
        p1 = [p for p in dropin.plugins if ITestPlugin in p.provided][0]
        self.assertIdentical(p1.dropin, dropin)
        self.assertEquals(p1.name, "TestPlugin")

        # Check the content of the description comes from the plugin module
        # docstring
        self.assertEquals(
            p1.description.strip(),
            "A plugin used solely for testing purposes.")
        self.assertEquals(p1.provided, [ITestPlugin, plugin.IPlugin])
        realPlugin = p1.load()
        # The plugin should match the class present in sys.modules
        self.assertIdentical(
            realPlugin,
            sys.modules['mypackage.%s' % (self.originalPlugin,)].TestPlugin)

        # And it should also match if we import it classicly
        import mypackage.testplugin as tp
        self.assertIdentical(realPlugin, tp.TestPlugin)
Exemplo n.º 6
0
    def test_cache(self):
        """
        Check that the cache returned by L{plugin.getCache} hold the plugin
        B{testplugin}, and that this plugin has the properties we expect:
        provide L{TestPlugin}, has the good name and description, and can be
        loaded successfully.
        """
        cache = plugin.getCache(self.module)

        dropin = cache[self.originalPlugin]
        self.assertEqual(dropin.moduleName,
                         'mypackage.%s' % (self.originalPlugin, ))
        self.assertIn("I'm a test drop-in.", dropin.description)

        # Note, not the preferred way to get a plugin by its interface.
        p1 = [p for p in dropin.plugins if ITestPlugin in p.provided][0]
        self.assertIs(p1.dropin, dropin)
        self.assertEqual(p1.name, "TestPlugin")

        # Check the content of the description comes from the plugin module
        # docstring
        self.assertEqual(p1.description.strip(),
                         "A plugin used solely for testing purposes.")
        self.assertEqual(p1.provided, [ITestPlugin, plugin.IPlugin])
        realPlugin = p1.load()
        # The plugin should match the class present in sys.modules
        self.assertIs(
            realPlugin,
            sys.modules['mypackage.%s' % (self.originalPlugin, )].TestPlugin)

        # And it should also match if we import it classicly
        import mypackage.testplugin as tp
        self.assertIs(realPlugin, tp.TestPlugin)
Exemplo n.º 7
0
    def test_deployedMode(self):
        """
        The C{dropin.cache} file may not be writable: the cache should still be
        attainable, but an error should be logged to show that the cache
        couldn't be updated.
        """
        # Generate the cache
        plugin.getCache(self.module)

        cachepath = self.package.child("dropin.cache")

        # Add a new plugin
        FilePath(__file__).sibling("plugin_extra1.py").copyTo(
            self.package.child("pluginextra.py"))
        invalidateImportCaches()

        os.chmod(self.package.path, 0o500)
        # Change the right of dropin.cache too for windows
        os.chmod(cachepath.path, 0o400)
        self.addCleanup(os.chmod, self.package.path, 0o700)
        self.addCleanup(os.chmod, cachepath.path, 0o700)

        # Start observing log events to see the warning
        events = []
        addObserver(events.append)
        self.addCleanup(removeObserver, events.append)

        cache = plugin.getCache(self.module)
        # The new plugin should be reported
        self.assertIn("pluginextra", cache)
        self.assertIn(self.originalPlugin, cache)

        # Make sure something was logged about the cache.
        expected = "Unable to write to plugin cache %s: error number %d" % (
            cachepath.path,
            errno.EPERM,
        )
        for event in events:
            if expected in textFromEventDict(event):
                break
        else:
            self.fail("Did not observe unwriteable cache warning in log "
                      "events: %r" % (events, ))
Exemplo n.º 8
0
    def test_deployedMode(self):
        """
        The C{dropin.cache} file may not be writable: the cache should still be
        attainable, but an error should be logged to show that the cache
        couldn't be updated.
        """
        # Generate the cache
        plugin.getCache(self.module)

        cachepath = self.package.child('dropin.cache')

        # Add a new plugin
        FilePath(__file__).sibling('plugin_extra1.py'
            ).copyTo(self.package.child('pluginextra.py'))
        invalidateImportCaches()

        os.chmod(self.package.path, 0o500)
        # Change the right of dropin.cache too for windows
        os.chmod(cachepath.path, 0o400)
        self.addCleanup(os.chmod, self.package.path, 0o700)
        self.addCleanup(os.chmod, cachepath.path, 0o700)

        # Start observing log events to see the warning
        events = []
        addObserver(events.append)
        self.addCleanup(removeObserver, events.append)

        cache = plugin.getCache(self.module)
        # The new plugin should be reported
        self.assertIn('pluginextra', cache)
        self.assertIn(self.originalPlugin, cache)

        # Make sure something was logged about the cache.
        expected = "Unable to write to plugin cache %s: error number %d" % (
            cachepath.path, errno.EPERM)
        for event in events:
            if expected in textFromEventDict(event):
                break
        else:
            self.fail(
                "Did not observe unwriteable cache warning in log "
                "events: %r" % (events,))
Exemplo n.º 9
0
 def test_cacheRepr(self):
     """
     L{CachedPlugin} has a helpful C{repr} which contains relevant
     information about it.
     """
     cachedDropin = plugin.getCache(self.module)[self.originalPlugin]
     cachedPlugin = list(p for p in cachedDropin.plugins if p.name == "TestPlugin")[0]
     self.assertEqual(
         repr(cachedPlugin),
         "<CachedPlugin 'TestPlugin'/'mypackage.testplugin' " "(provides 'ITestPlugin, IPlugin')>",
     )
Exemplo n.º 10
0
    def copy_extensions(self, extensions):
        BuildExe.copy_extensions(self, extnsions)

        from bravo.plugins import authenticators
        from bravo.plugins import automatons
        from bravo.plugins import beds
        from bravo.plugins import build_hooks
        from bravo.plugins import compound_hooks
        from bravo.plugins import dig_hooks
        from bravo.plugins import door
        from bravo.plugins import fertilizer
        from bravo.plugins import generators
        from bravo.plugins import aintings
        from bravo.plugins import hysics
        from bravo.plugins import redstone
        from bravo.plugins import teleport
        from bravo.plugins import tracks
        from bravo.plugins import web
        from bravo.plugins import window_hooks
        from bravo.plugins import worldedit
        from bravo.plugins import commands
        from bravo.plugins.commands import common
        from bravo.plugins.commands import debug
        from bravo.plugins.commands import warp
        from bravo.plugins import serializers
        from bravo.plugins.serializers import beta
        from bravo.pluginsvserializers import memory

        plugins = [ authenticators, automatons, beds, build_hooks,
                    compound_hooks, dig_hooks, door, fertilizer, generators,
                    aintings, hysics, redstone, teleport, tracks, web,
                    window_hooks, worldedit, common, debug, warp, commands,
                    beta, memory, serializers,  ]

        for p in plugins:
            getCache(p)

            f = os.join(*(p.__name__.split(".")[:-1] + ["dropin.cache"]))
            full = os.path.join(self.collect_dir, f)

            self.compiled_files.append(f)
Exemplo n.º 11
0
 def test_cacheRepr(self):
     """
     L{CachedPlugin} has a helpful C{repr} which contains relevant
     information about it.
     """
     cachedDropin = plugin.getCache(self.module)[self.originalPlugin]
     cachedPlugin = list(p for p in cachedDropin.plugins
                         if p.name == 'TestPlugin')[0]
     self.assertEqual(
         repr(cachedPlugin),
         "<CachedPlugin 'TestPlugin'/'mypackage.testplugin' "
         "(provides 'ITestPlugin, IPlugin')>")
Exemplo n.º 12
0
 def _getspiders(self, interface, package):
     """This is an override of twisted.plugin.getPlugin, because we're
     interested in catching exceptions thrown when loading spiders such as
     KeyboardInterrupt
     """
     try:
         allDropins = getCache(package)
         for dropin in allDropins.itervalues():
             for plugin in dropin.plugins:
                 adapted = interface(plugin, None)
                 if adapted is not None:
                     yield adapted
     except KeyboardInterrupt:
         sys.stderr.write("Interrupted while loading Scrapy spiders\n")
         sys.exit(2)
Exemplo n.º 13
0
 def _testCache(self):
     cache = plugin.getCache(plugins)
     dropin = cache['testplugin']
     self.assertEquals(dropin.moduleName, 'twisted.plugins.testplugin')
     self.assertNotEquals(dropin.description.find("I'm a test drop-in."), -1)
     p1 = [p for p in dropin.plugins if plugin.ITestPlugin in p.provided][0]
     self.assertIdentical(p1.dropin, dropin)
     self.assertEquals(p1.name, "TestPlugin")
     self.assertEquals(
         p1.description.strip(),
         "A plugin used solely for testing purposes.")
     self.assertEquals(p1.provided, [plugin.ITestPlugin, plugin.IPlugin])
     realPlugin = p1.load()
     self.assertIdentical(realPlugin,
                          sys.modules['twisted.plugins.testplugin'].TestPlugin)
     import twisted.plugins.testplugin as tp
     self.assertIdentical(realPlugin, tp.TestPlugin)
Exemplo n.º 14
0
    def _testCache(self):
        cache = plugin.getCache(plugins)

        dropin = cache['testplugin']
        self.assertEquals(dropin.moduleName, 'twisted.plugins.testplugin')
        self.assertNotEquals(dropin.description.find("I'm a test drop-in."),
                             -1)

        # Note, not the preferred way to get a plugin by its interface.
        p1 = [p for p in dropin.plugins if plugin.ITestPlugin in p.provided][0]
        self.assertIdentical(p1.dropin, dropin)
        self.assertEquals(p1.name, "TestPlugin")
        self.assertEquals(p1.description.strip(),
                          "A plugin used solely for testing purposes.")
        self.assertEquals(p1.provided, [plugin.ITestPlugin, plugin.IPlugin])
        realPlugin = p1.load()
        self.assertIdentical(
            realPlugin, sys.modules['twisted.plugins.testplugin'].TestPlugin)

        import twisted.plugins.testplugin as tp
        self.assertIdentical(realPlugin, tp.TestPlugin)
Exemplo n.º 15
0
    def observer(basePath=""):
        if House._observer == None:
            House._observer = Observer()

            app = FX.appModule
            try:
                from twisted.plugin import getCache
                pkg = __import__(app + '.peer', globals(), locals(), ["*"], 0)
                modules = getCache(pkg)

                fqPeers = []

                for m in modules:
                    fqPeers.append(app + '.peer.' + m)

                House._observer.scan(fqPeers)
            except:
                pass

            House._observer.scan()

        return House._observer
Exemplo n.º 16
0
    def scan(self, peers=None):
        fqPeers = []

        if peers is None:
            import wallaby.pf.peer as peers
            from twisted.plugin import getCache
            peers = getCache(peers)
            root = "wallaby.pf.peer"

            for peer in peers:
                fqPeers.append(root + "." + peer)
        else:
            fqPeers = peers

        for fqPeer in fqPeers:
            
            mod = FX.imp(fqPeer)
            root, basename = fqPeer.rsplit('.', 1)

            if mod == None: continue

            cls = string.upper(basename[0]) + basename[1:]                       

            if not cls in mod.__dict__: continue

            fqn = root + '.' + basename + '.' + cls

            self._fqn[cls] = fqn

            if re.search(r"\.room", root) != None:
                self._rooms[cls] = mod.__dict__[cls]
            else:
                self._peers[cls] = mod.__dict__[cls]

            self._objectTypes[fqn] = mod.__dict__[cls].ObjectType

            for base in mod.__dict__[cls].__bases__:
                fqBase = base.__module__ + '.' + base.__name__
                if not fqBase in self._extendedBy:
                    self._extendedBy[fqBase] = set()

                self._extendedBy[fqBase].add(fqn)

                if not fqn in self._bases:
                    self._bases[fqn] = set()

                self._bases[fqn].add(fqBase)

            if 'Receiving' in mod.__dict__[cls].__dict__:
                for fqa in mod.__dict__[cls].Receiving:
                    pillow = None
                    try:
                        pillow = fqa.split('.')[2]
                    except:
                        print "Split error:", fqa

                    pillow = pillow.replace('!', '')
                    fqa = fqa.replace('!', '')

                    if not pillow in self._inBoundPillows: self._inBoundPillows[pillow] = []
                    if not fqa in self._inBoundPillowsFQ: self._inBoundPillowsFQ[fqa] = []
                    if not fqn in self._inBoundPillowsPerPeer: self._inBoundPillowsPerPeer[fqn] = []
                    self._inBoundPillows[pillow].append(fqn)
                    self._inBoundPillowsFQ[fqa].append(fqn)
                    self._inBoundPillowsPerPeer[fqn].append(fqa)


            for pillow in mod.__dict__[cls].InPillows:
                pillow = pillow.replace('!', '')

                fqa = cls + '.In.' + pillow
                fqa = fqa.replace('!', '')

                if not pillow in self._inBoundPillows: self._inBoundPillows[pillow] = []
                if not fqa in self._inBoundPillowsFQ: self._inBoundPillowsFQ[fqa] = []
                if not fqn in self._inBoundPillowsPerPeer: self._inBoundPillowsPerPeer[fqn] = []
                self._inBoundPillows[pillow].append(fqn)
                self._inBoundPillowsFQ[fqa].append(fqn)
                self._inBoundPillowsPerPeer[fqn].append(fqa)

            if 'Sending' in mod.__dict__[cls].__dict__:
                for fqa in mod.__dict__[cls].Sending:
                    pillow = None
                    try:
                        pillow = fqa.split('.')[2]
                    except:
                        print "Split error:", fqa

                    fqa = fqa.replace('!', '')
                    pillow = pillow.replace('!', '')

                    if not pillow in self._outBoundPillows: self._outBoundPillows[pillow] = []
                    if not fqa in self._outBoundPillowsFQ: self._outBoundPillowsFQ[fqa] = []
                    if not fqn in self._outBoundPillowsPerPeer: self._outBoundPillowsPerPeer[fqn] = []
                    self._outBoundPillows[pillow].append(fqn)
                    self._outBoundPillowsFQ[fqa].append(fqn)
                    self._outBoundPillowsPerPeer[fqn].append(fqa)

            for pillow in mod.__dict__[cls].OutPillows:
                pillow = pillow.replace('!', '')

                fqa = cls + '.Out.' + pillow
                fqa = fqa.replace('!', '')
                if not pillow in self._outBoundPillows: self._outBoundPillows[pillow] = []
                if not fqa in self._outBoundPillowsFQ: self._outBoundPillowsFQ[fqa] = []
                if not fqn in self._outBoundPillowsPerPeer: self._outBoundPillowsPerPeer[fqn] = []
                self._outBoundPillows[pillow].append(fqn)
                self._outBoundPillowsFQ[fqa].append(fqn)
                self._outBoundPillowsPerPeer[fqn].append(fqa)
    def loadUIFiles(self):
        # Do not reload widgets if not changed
        if self.sheets is None or self.sheets == self._lastSheets: return
        self._lastSheets = self.sheets

        self.clear()

        isheets = []

        self._sheetPrototypes = {}

        import wallaby.frontends as frontends
        from twisted.plugin import getCache

        for p in FX.packagePath(FX.appModule + ".isheet"): isheets.append(p)
        for frontend in getCache(frontends):
            for p in FX.packagePath("wallaby.frontends." + frontend + ".isheet"): isheets.append(p)

        import os
        for path in isheets:
            root = re.sub(r'[/\\]','.', path).replace('..', '')
            root = re.sub(r'^.*wallaby\.', 'wallaby.', root)
            files = os.listdir(path)
            for file in files:
                if '.py' in file and '.pyc' not in file and 'UI_' in file:
                    basename, ext = os.path.splitext(file)

                    if ext != '.py': continue

                    mod = FX.imp(root + '.' + basename)
                    if mod == None: continue

                    cls = basename[0] + string.lower(basename[1]) + basename[2] + string.upper(basename[3]) + basename[4:]
    
                    sheetName = unicode(basename.replace('UI_', ''))

                    sheetCache = None

                    if sheetName in self._sheetPrototypes: 
                        continue

                    if re.match(self.sheets, sheetName) is None: 
                        continue

                    if not self.isMultiPage():
                        p = self.parent()
                        while p != None and (not isinstance(p, Container) or not p.isMultiPage()):
                            p = p.parent()

                        if p is not None:
                            sheetCache = p.sheetCache

                            if sheetName in sheetCache:
                                self._sheet = sheetCache[sheetName]
                                return

                    if not cls in mod.__dict__:
                        for key, val in mod.__dict__.items():
                            if key.startswith("Ui_"):
                                cls = key
                                break

                    if not cls in mod.__dict__: continue

                    self._sheetPrototypes[sheetName] = mod.__dict__[cls]

                    sheet = QtGui.QWidget(self)
                    sheet.ui = self._sheetPrototypes[sheetName]()
                    sheet.ui.setupUi(sheet)
                    sheet.setObjectName(sheetName + "Sheet") 

                    if sheetCache is not None:
                        self._sheet = sheet
                        sheetCache[sheetName] = sheet
                        # also add the cached sheet to the current widget
                        # to allow nested widgets to also be loaded

                    self.addChildWidget(sheet)