Example #1
0
        def _accept_slave(res):
            self.slave_status.setConnected(True)

            self.slave_status.updateInfo(
                admin=state.get("admin"),
                host=state.get("host"),
                access_uri=state.get("access_uri"),
                version=state.get("version"),
            )

            self.slave_commands = state.get("slave_commands")
            self.slave_environ = state.get("slave_environ")
            self.slave_basedir = state.get("slave_basedir")
            self.slave_system = state.get("slave_system")
            self.slave = bot
            if self.slave_system == "nt":
                self.path_module = namedModule("ntpath")
            else:
                # most everything accepts / as separator, so posix should be a
                # reasonable fallback
                self.path_module = namedModule("posixpath")
            log.msg("bot attached")
            self.messageReceivedFromSlave()
            self.stopMissingTimer()
            self.botmaster.master.status.slaveConnected(self.slavename)
Example #2
0
        def _accept_slave(res):
            self.slave_status.setConnected(True)

            self.slave_status.updateInfo(
                admin=state.get("admin"),
                host=state.get("host"),
                access_uri=state.get("access_uri"),
                version=state.get("version"),
            )

            self.slave_commands = state.get("slave_commands")
            self.slave_environ = state.get("slave_environ")
            self.slave_basedir = state.get("slave_basedir")
            self.slave_system = state.get("slave_system")
            self.slave = bot
            if self.slave_system == "nt":
                self.path_module = namedModule("ntpath")
            else:
                # most everything accepts / as separator, so posix should be a
                # reasonable fallback
                self.path_module = namedModule("posixpath")
            log.msg("bot attached")
            self.messageReceivedFromSlave()
            self.stopMissingTimer()
            self.master.status.slaveConnected(self.slavename)
Example #3
0
    def postOptions(self):
        """
        Set up conditional defaults and check for dependencies.

        If SSL is not available but an HTTPS server was configured, raise a
        L{UsageError} indicating that this is not possible.

        If no server port was supplied, select a default appropriate for the
        other options supplied.
        """
        if self["port"] is not None:
            self["ports"].append(self["port"])
        if self["https"] is not None:
            try:
                reflect.namedModule("OpenSSL.SSL")
            except ImportError:
                raise usage.UsageError("SSL support not installed")
            sslStrport = "ssl:port={}:privateKey={}:certKey={}".format(
                self["https"],
                self["privkey"],
                self["certificate"],
            )
            self["ports"].append(sslStrport)
        if len(self["ports"]) == 0:
            if self["personal"]:
                path = os.path.expanduser(
                    os.path.join("~", distrib.UserDirectory.userSocketName))
                self["ports"].append("unix:" + path)
            else:
                self["ports"].append("tcp:8080")
Example #4
0
 def change_worker_system(self, system):
     self.worker.worker_system = system
     if system in ['nt', 'win32']:
         self.build.path_module = namedModule('ntpath')
         self.worker.worker_basedir = '\\wrk'
     else:
         self.build.path_module = namedModule('posixpath')
         self.worker.worker_basedir = '/wrk'
Example #5
0
 def changeWorkerSystem(self, system):
     self.worker.worker_system = system
     if system in ['nt', 'win32']:
         self.build.path_module = namedModule('ntpath')
         self.worker.worker_basedir = '\\wrk'
     else:
         self.build.path_module = namedModule('posixpath')
         self.worker.worker_basedir = '/wrk'
 def testCompatibility(self):
     for oldName, newName in movedModules:
         try:
             old = reflect.namedModule(oldName)
             new = reflect.namedModule(newName)
         except ImportError, e:
             continue
         for someName in [x for x in vars(new).keys() if x != '__doc__']:
             self.assertIdentical(getattr(old, someName),
                                  getattr(new, someName))
Example #7
0
 def test_importQtreactor(self):
     """
     Attempting to import L{twisted.internet.qtreactor} should raise an
     C{ImportError} indicating that C{qtreactor} is no longer a part of
     Twisted.
     """
     sys.modules["qtreactor"] = None
     from twisted.plugins.twisted_qtstub import errorMessage
     try:
         namedModule('twisted.internet.qtreactor')
     except ImportError, e:
         self.assertEqual(str(e), errorMessage)
Example #8
0
 def testCompatibility(self):
     for oldName, newName in movedModules:
         try:
             old = reflect.namedModule(oldName)
             new = reflect.namedModule(newName)
         except ImportError, e:
             continue
         for someName in vars(new):
             if someName == '__doc__':
                 continue
             self.assertIdentical(getattr(old, someName),
                                  getattr(new, someName))
Example #9
0
 def test_importQtreactor(self):
     """
     Attempting to import L{twisted.internet.qtreactor} should raise an
     C{ImportError} indicating that C{qtreactor} is no longer a part of
     Twisted.
     """
     sys.modules["qtreactor"] = None
     from twisted.plugins.twisted_qtstub import errorMessage
     try:
         namedModule('twisted.internet.qtreactor')
     except ImportError, e:
         self.assertEqual(str(e), errorMessage)
Example #10
0
def runApp(config):
    global initRun
    platformType = runtime.platform.getType()

    sys.path.append(config['rundir'])

    # Install a reactor immediately.  The application will not load properly
    # unless this is done FIRST; otherwise the first 'reactor' import would
    # trigger an automatic installation of the default reactor.

    # To make this callable from within a running Twisted app, allow as the
    # reactor None to bypass this and use whatever reactor is currently in use.

    if config['reactor']:
        if platformType == 'java':
            from twisted.internet import javareactor
            javareactor.install()
        else:
            from twisted.python.reflect import namedModule
            namedModule(reactorTypes[config['reactor']]).install()

    if platformType != 'posix' or config['debug']:
        # only posix can fork, and debugging requires nodaemon
        config['nodaemon'] = 1

    if config['encrypted']:
        import getpass
        passphrase = getpass.getpass('Passphrase: ')
    else:
        passphrase = None

    # Load the servers.
    # This will fix up accidental function definitions in evaluation spaces
    # and the like.
    initRun = 0
    if os.path.exists(config['pidfile']):
        try:
            pid = int(open(config['pidfile']).read())
        except ValueError:
            sys.exit('Pidfile %s contains non numeric value' % config['pidfile'])

        try:
            os.kill(pid, 0)
        except OSError, why:
            if why[0] == errno.ESRCH:
                # The pid doesnt exists.
                if not config['quiet']:
                    print 'Removing stale pidfile %s' % config['pidfile']
                    os.remove(config['pidfile'])
            else:
                sys.exit('Can\'t check status of PID %s from pidfile %s: %s' % (pid, config['pidfile'], why[1]))
        except AttributeError:
            pass # welcome to windows
Example #11
0
    def attached(self, conn):
        """This is called when the worker connects."""

        metrics.MetricCountEvent.log("AbstractWorker.attached_workers", 1)

        # now we go through a sequence of calls, gathering information, then
        # tell the Botmaster that it can finally give this worker to all the
        # Builders that care about it.

        # Reset graceful shutdown status
        self.worker_status.setGraceful(False)
        # We want to know when the graceful shutdown flag changes
        self.worker_status.addGracefulWatcher(self._gracefulChanged)
        self.conn = conn
        self._old_builder_list = None  # clear builder list before proceed
        self.worker_status.addPauseWatcher(self._pauseChanged)

        self.worker_status.setConnected(True)

        self._applyWorkerInfo(conn.info)
        self.worker_commands = conn.info.get("slave_commands", {})
        self.worker_environ = conn.info.get("environ", {})
        self.worker_basedir = conn.info.get("basedir", None)
        self.worker_system = conn.info.get("system", None)

        self.conn.notifyOnDisconnect(self.detached)

        workerinfo = {
            'admin': conn.info.get('admin'),
            'host': conn.info.get('host'),
            'access_uri': conn.info.get('access_uri'),
            'version': conn.info.get('version')
        }

        yield self.master.data.updates.workerConnected(
            workerid=self.workerid,
            masterid=self.master.masterid,
            workerinfo=workerinfo
        )

        if self.worker_system == "nt":
            self.path_module = namedModule("ntpath")
        else:
            # most everything accepts / as separator, so posix should be a
            # reasonable fallback
            self.path_module = namedModule("posixpath")
        log.msg("bot attached")
        self.messageReceivedFromWorker()
        self.stopMissingTimer()
        self.master.status.workerConnected(self.name)
        yield self.updateWorker()
        yield self.botmaster.maybeStartBuildsForWorker(self.name)
Example #12
0
    def remoteGetWorkerInfo(self):
        info = yield self.protocol.get_message_result({'op': 'get_worker_info'})
        self.info = decode(info)

        worker_system = self.info.get("system", None)
        if worker_system == "nt":
            self.path_module = namedModule("ntpath")
            self.path_expanduser = path_expand_user.nt_expanduser
        else:
            # most everything accepts / as separator, so posix should be a reasonable fallback
            self.path_module = namedModule("posixpath")
            self.path_expanduser = path_expand_user.posix_expanduser
        return self.info
Example #13
0
 def test_supportsThreads(self):
     """
     L{Platform.supportsThreads} returns C{True} if threads can be created in
     this runtime, C{False} otherwise.
     """
     # It's difficult to test both cases of this without faking the threading
     # module.  Perhaps an adequate test is to just test the behavior with
     # the current runtime, whatever that happens to be.
     try:
         namedModule('threading')
     except ImportError:
         self.assertFalse(Platform().supportsThreads())
     else:
         self.assertTrue(Platform().supportsThreads())
Example #14
0
 def test_supportsThreads(self):
     """
     L{Platform.supportsThreads} returns C{True} if threads can be created in
     this runtime, C{False} otherwise.
     """
     # It's difficult to test both cases of this without faking the threading
     # module.  Perhaps an adequate test is to just test the behavior with
     # the current runtime, whatever that happens to be.
     try:
         namedModule('threading')
     except ImportError:
         self.assertFalse(Platform().supportsThreads())
     else:
         self.assertTrue(Platform().supportsThreads())
Example #15
0
	def processComponent (componentName, v):
		if collectionName is not None:
			componentName = "{:s}/{:s}".format(collectionName, componentName)

		# It's a class
		if IComponent.implementedBy(v):
			fileName = namedModule(v.__module__).__file__
			objectName = "{:s}.{:s}".format(v.__module__, v.__name__)
			component = v()

		# It's a function (eg getComponent)
		elif callable(v):
			fileName = namedModule(v.__module__).__file__
			objectName = "{:s}.{:s}".format(v.__module__, v.__name__)
			component = v()

			if not IComponent.providedBy(component):
				raise Error(
					"{:s}.{:s}() does not produce a valid Component".format(
						v.__module__,
						v.__name__
				))

		# It's a string - hopefully a '.fbp' or '.json'
		else:
			import graph
			fileName = os.path.join(moduleDir, str(v))
			objectName = None
			component = graph.loadFile(fileName)

			if not IComponent.providedBy(component):
				raise Error(
					"{:s} does not produce a valid Component".format(
						componentName
				))

		# Make sure we will check the ".py" file
		if fileName[-4:] == ".pyc":
			fileName = fileName[:-1]

		if component.ready:
			return defer.succeed((fileName, objectName, componentName, component))
		else:
			d = defer.Deferred()
			component.once("ready", lambda data: d.callback(
				(fileName, objectName, componentName, component)
			))
			return d
Example #16
0
 def _setup(self):
     self.updates = Updates()
     self.rtypes = RTypes()
     self.plural_rtypes = RTypes()
     for moduleName in self.submodules:
         module = reflect.namedModule(moduleName)
         self._scanModule(module)
Example #17
0
    def test_get_graphql_schema(self):
        if not graphql:
            raise unittest.SkipTest('Test requires graphql')

        # use the test module for basic graphQLSchema generation
        mod = reflect.namedModule('buildbot.test.unit.data.test_connector')
        self.data._scanModule(mod)
        schema = self.data.get_graphql_schema()
        self.assertEqual(
            schema,
            textwrap.dedent("""
        # custom scalar types for buildbot data model
        scalar Date   # stored as utc unix timestamp
        scalar Binary # arbitrary data stored as base85
        scalar JSON  # arbitrary json stored as string, mainly used for properties values
        type Query {
          tests(testid: Int,
           testid__contains: Int,
           testid__eq: Int,
           testid__ge: Int,
           testid__gt: Int,
           testid__le: Int,
           testid__lt: Int,
           testid__ne: Int,
           order: String,
           limit: Int,
           offset: Int): [Test]!
          test(testid: Int): Test
        }
        type Test {
          testid: Int!
        }
        """))
        schema = graphql.build_schema(schema)
Example #18
0
 def test_mode_full_win32path(self):
     self.setup_step(
         bzr.Bzr(repourl='http://bzr.squid-cache.org/bzr/squid3/trunk',
                 mode='full', method='fresh'))
     self.build.path_module = namedModule('ntpath')
     self.expect_commands(
         ExpectShell(workdir='wkdir',
                     command=['bzr', '--version'])
         .exit(0),
         ExpectStat(file=r'wkdir\.buildbot-patched', log_environ=True)
         .exit(1),
         ExpectStat(file=r'wkdir\.bzr', log_environ=True)
         .exit(0),
         ExpectShell(workdir='wkdir',
                     command=['bzr', 'clean-tree', '--force'])
         .exit(0),
         ExpectShell(workdir='wkdir',
                     command=['bzr', 'update'])
         .exit(0),
         ExpectShell(workdir='wkdir',
                     command=['bzr', 'version-info', '--custom', "--template='{revno}"])
         .stdout('100')
         .exit(0)
     )
     self.expect_outcome(result=SUCCESS)
     return self.run_step()
Example #19
0
 def addPackageRecursive(self, package):
     if type(package) is types.StringType:
         try:
             package = reflect.namedModule(package)
         except ImportError, e:
             self.couldNotImport[package] = e
             return
Example #20
0
def loadConfig(options):
    """Load the Warp config"""
    siteDir = FilePath(options['siteDir'])
    sys.path.insert(0, siteDir.path)

    configModule = reflect.namedModule(options['config'])
    config = configModule.config
    runtime.config.update(config)

    runtime.config['siteDir'] = siteDir
    runtime.config['warpDir'] = FilePath(runtime.__file__).parent()

    if options["skipSchemaCheck"]:
        runtime.config["schema"] = runtime.config.get("schema", {})
        runtime.config["schema"]["check"] = False

    store.setupStore()
    translate.loadMessages()

    _session, _base = db_session.setupSession()
    runtime.db_session = _session
    runtime.db_base = _base

    factory = site.WarpSite(resource.WarpResourceWrapper())
    runtime.config['warpSite'] = factory

    return configModule
def moduleMovedForSplit(origModuleName, newModuleName, moduleDesc,
                        projectName, projectURL, globDict):
    from twisted.python import reflect
    modoc = """
%(moduleDesc)s

This module is DEPRECATED. It has been split off into a third party
package, Twisted %(projectName)s. Please see %(projectURL)s.

This is just a place-holder that imports from the third-party %(projectName)s
package for backwards compatibility. To use it, you need to install
that package.
""" % {'moduleDesc': moduleDesc,
       'projectName': projectName,
       'projectURL': projectURL}

    #origModule = reflect.namedModule(origModuleName)
    try:
        newModule = reflect.namedModule(newModuleName)
    except ImportError:
        raise ImportError("You need to have the Twisted %s "
                          "package installed to use %s. "
                          "See %s."
                          % (projectName, origModuleName, projectURL))

    # Populate the old module with the new module's contents
    for k,v in vars(newModule).items():
        globDict[k] = v
    globDict['__doc__'] = modoc
    import warnings
    warnings.warn("%s has moved to %s. See %s." % (origModuleName, newModuleName,
                                                   projectURL),
                  DeprecationWarning, stacklevel=3)
    return
Example #22
0
def executePolicyDir(func, d, prefix=None):
    """
    Execute all .py files in a directory, in alphabetical order, calling func on the module

    This throws a TryError if any of the modules fail.  The result is a list of tuples consisting
    of the module name and str rep of the exception
    """
    ##
    # a bit cheap but we want to temporarily make this direcotry in our path if it isn't already
    # so safe out sys.path, add d to it, and put it back when done
    oldpath = sys.path
    sys.path = [d] + sys.path
    path = d
    if prefix:
        path = os.path.join(path, prefix)
    files = [f[:-3]
             for f in os.listdir(path)
             if f.endswith('.py') and f != '__init__.py']
    files.sort()
    errorRes = []
    try:
        for f in files:
            if prefix:
                f = prefix + '.' + f
            try:
                m = namedModule(f)
                func(m)
            except Exception, err:
                errorRes.append((f, str(err), getStacktrace()))
    finally:
        sys.path = oldpath

    if errorRes:
        raise TryError('Failed to execute all modules', errorRes)
Example #23
0
File: jobs.py Project: D3f0/txscada
    def remote_registerClasses(self, *args):
        """
        Instructs my broker to register the classes specified by the
        argument(s).

        The classes will be registered for B{all} jobs, and are specified by
        their string representations::
        
            <package(s).module.class>
        
        """
        modules = []
        for stringRep in args:
            # Load the class for the string representation
            cls = reflect.namedObject(stringRep)
            # Register instances of the class, including its type and module
            pb.setUnjellyableForClass(stringRep, cls)
            if cls.__module__ not in modules:
                modules.append(cls.__module__)
        # Try to build the modules for the classes in case they've changed
        # since the last run
        for module in modules:
            try:
                rebuild(reflect.namedModule(module), doLog=False)
            except:
                pass
Example #24
0
def moduleMovedForSplit(origModuleName, newModuleName, moduleDesc,
                        projectName, projectURL, globDict):
    from twisted.python import reflect
    modoc = """
%(moduleDesc)s

This module is DEPRECATED. It has been split off into a third party
package, Twisted %(projectName)s. Please see %(projectURL)s.

This is just a place-holder that imports from the third-party %(projectName)s
package for backwards compatibility. To use it, you need to install
that package.
""" % {'moduleDesc': moduleDesc,
       'projectName': projectName,
       'projectURL': projectURL}

    #origModule = reflect.namedModule(origModuleName)
    try:
        newModule = reflect.namedModule(newModuleName)
    except ImportError:
        raise ImportError("You need to have the Twisted %s "
                          "package installed to use %s. "
                          "See %s."
                          % (projectName, origModuleName, projectURL))

    # Populate the old module with the new module's contents
    for k,v in vars(newModule).items():
        globDict[k] = v
    globDict['__doc__'] = modoc
    import warnings
    warnings.warn("%s has moved to %s. See %s." % (origModuleName, newModuleName,
                                                   projectURL),
                  DeprecationWarning, stacklevel=3)
    return
 def test_mode_full_win32path(self):
     self.setupStep(
         bzr.Bzr(repourl='http://bzr.squid-cache.org/bzr/squid3/trunk',
                 mode='full', method='fresh'))
     self.build.path_module = namedModule('ntpath')
     self.expectCommands(
         ExpectShell(workdir='wkdir',
                     command=['bzr', '--version'])
         + 0,
         Expect('stat', dict(file=r'wkdir\.buildbot-patched',
                             logEnviron=True))
         + 1,
         Expect('stat', dict(file=r'wkdir\.bzr',
                             logEnviron=True))
         + 0,
         ExpectShell(workdir='wkdir',
                     command=['bzr', 'clean-tree', '--force'])
         + 0,
         ExpectShell(workdir='wkdir',
                     command=['bzr', 'update'])
         + 0,
         ExpectShell(workdir='wkdir',
                     command=['bzr', 'version-info', '--custom', "--template='{revno}"])
         + ExpectShell.log('stdio',
                           stdout='100')
         + 0,
     )
     self.expectOutcome(result=SUCCESS, status_text=["update"])
     return self.runStep()
Example #26
0
    def test_scanModule(self):
        # use this module as a test
        mod = reflect.namedModule('buildbot.test.unit.test_data_connector')
        self.data._scanModule(mod)

        # check that it discovered MyResourceType and updated endpoints
        match = self.data.matcher[('test', '10')]
        self.assertIsInstance(match[0], TestEndpoint)
        self.assertEqual(match[1], dict(testid=10))
        match = self.data.matcher[('test', '10', 'p1')]
        self.assertIsInstance(match[0], TestEndpoint)
        match = self.data.matcher[('test', '10', 'p2')]
        self.assertIsInstance(match[0], TestEndpoint)
        match = self.data.matcher[('test',)]
        self.assertIsInstance(match[0], TestsEndpoint)
        self.assertEqual(match[1], dict())
        match = self.data.matcher[('test', 'foo')]
        self.assertIsInstance(match[0], TestsEndpointSubclass)
        self.assertEqual(match[1], dict())

        # and that it found the update method
        self.assertEqual(self.data.updates.testUpdate(), "testUpdate return")

        # and that it added the single root link
        self.assertEqual(self.data.rootLinks,
                         [{'name': 'tests'}])

        # and that it added an attribute
        self.assertIsInstance(self.data.rtypes.test, TestResourceType)
Example #27
0
 def __init__(self, dbapiName, *connargs, **connkw):
     """See ConnectionPool.__doc__
     """
     self.dbapiName = dbapiName
     if self.noisy:
         log.msg("Connecting to database: %s %s %s" % (dbapiName, connargs, connkw))
     self.dbapi = reflect.namedModule(dbapiName)
     assert self.dbapi.apilevel == '2.0', 'DB API module not DB API 2.0 compliant.'
     assert self.dbapi.threadsafety > 0, 'DB API module not sufficiently thread-safe.'
     self.connargs = connargs
     self.connkw = connkw
     import thread
     self.threadID = thread.get_ident
     self.connections = {}
     if connkw.has_key('cp_min'):
         min = connkw['cp_min']
         del connkw['cp_min']
     else:
         min = 3
     if connkw.has_key('cp_max'):
         max = connkw['cp_max']
         del connkw['cp_max']
     else:
         max = 5
     from twisted.internet import reactor
     self.shutdownID = reactor.addSystemEventTrigger('during', 'shutdown', self.finalClose)
Example #28
0
 def test_get_fake_graphql_schema(self):
     # use the test module for basic graphQLSchema generation
     mod = reflect.namedModule('buildbot.test.fake.endpoint')
     self.data._scanModule(mod)
     schema = self.data.get_graphql_schema()
     self.assertEqual(schema, mod.graphql_schema)
     schema = graphql.build_schema(schema)
Example #29
0
 def test_namedModuleLookup(self):
     """
     L{namedModule} should return the module object for the name it is
     passed.
     """
     self.assertIdentical(
         reflect.namedModule("twisted.python.reflect"), reflect)
Example #30
0
 def test_mode_full_win32path(self):
     self.setupStep(
         bzr.Bzr(repourl='http://bzr.squid-cache.org/bzr/squid3/trunk',
                 mode='full', method='fresh'))
     self.build.path_module = namedModule('ntpath')
     self.expectCommands(
         ExpectShell(workdir='wkdir',
                     command=['bzr', '--version'])
         + 0,
         Expect('stat', dict(file=r'wkdir\.buildbot-patched',
                             logEnviron=True))
         + 1,
         Expect('stat', dict(file=r'wkdir\.bzr',
                             logEnviron=True))
         + 0,
         ExpectShell(workdir='wkdir',
                     command=['bzr', 'clean-tree', '--force'])
         + 0,
         ExpectShell(workdir='wkdir',
                     command=['bzr', 'update'])
         + 0,
         ExpectShell(workdir='wkdir',
                     command=['bzr', 'version-info', '--custom', "--template='{revno}"])
         + ExpectShell.log('stdio',
                           stdout='100')
         + 0,
     )
     self.expectOutcome(result=SUCCESS)
     return self.runStep()
Example #31
0
    def remote_registerClasses(self, *args):
        """
        Instructs my broker to register the classes specified by the
        argument(s).

        The classes will be registered for B{all} jobs, and are specified by
        their string representations::
        
            <package(s).module.class>
        
        """
        modules = []
        for stringRep in args:
            # Load the class for the string representation
            cls = reflect.namedObject(stringRep)
            # Register instances of the class, including its type and module
            pb.setUnjellyableForClass(stringRep, cls)
            if cls.__module__ not in modules:
                modules.append(cls.__module__)
        # Try to build the modules for the classes in case they've changed
        # since the last run
        for module in modules:
            try:
                rebuild(reflect.namedModule(module), doLog=False)
            except:
                pass
Example #32
0
    def test_scanModule(self):
        # use this module as a test
        mod = reflect.namedModule('buildbot.test.unit.test_data_connector')
        self.data._scanModule(mod)

        # check that it discovered MyResourceType and updated endpoints
        match = self.data.matcher[('test', '10')]
        self.assertIsInstance(match[0], TestEndpoint)
        self.assertEqual(match[1], dict(testid=10))
        match = self.data.matcher[('test', '10', 'p1')]
        self.assertIsInstance(match[0], TestEndpoint)
        match = self.data.matcher[('test', '10', 'p2')]
        self.assertIsInstance(match[0], TestEndpoint)
        match = self.data.matcher[('test',)]
        self.assertIsInstance(match[0], TestsEndpoint)
        self.assertEqual(match[1], dict())
        match = self.data.matcher[('test', 'foo')]
        self.assertIsInstance(match[0], TestsEndpointSubclass)
        self.assertEqual(match[1], dict())

        # and that it found the update method
        self.assertEqual(self.data.updates.testUpdate(), "testUpdate return")

        # and that it added the single root link
        self.assertEqual(self.data.rootLinks,
                         [{'name': 'tests'}])

        # and that it added an attribute
        self.assertIsInstance(self.data.rtypes.test, TestResourceType)
Example #33
0
 def test_namedModuleLookup(self):
     """
     L{namedModule} should return the module object for the name it is
     passed.
     """
     from twisted.python import monkey
     self.assertIs(reflect.namedModule("twisted.python.monkey"), monkey)
Example #34
0
 def test_namedModuleLookup(self):
     """
     L{namedModule} should return the module object for the name it is
     passed.
     """
     self.assertIdentical(reflect.namedModule("twisted.python.reflect"),
                          reflect)
Example #35
0
def _getSuite(config):
    def _dbg(msg):
        log.msg(iface=itrial.ITrialDebug, parseargs=msg)
    reporterKlass = _getReporter(config)
    log.msg(iface=ITrialDebug, reporter="using reporter reporterKlass: %r" % (reporterKlass,))
    
    suite = runner.TestSuite(reporterKlass(
        tbformat=config['tbformat'],
        args=config['reporter-args'],
        realtime=config['rterrors']),
        _getJanitor(),
        benchmark=config['benchmark'])
    suite.couldNotImport.update(config['_couldNotImport'])
    
    suite.dryRun = config['dry-run']

    for package in config['packages']:
        if isinstance(package, types.StringType):
            try:
                package = reflect.namedModule(package)
            except ImportError, e:
                suite.couldNotImport[package] = failure.Failure()
                continue
        if config['recurse']:
            _dbg("addPackageRecursive(%s)" % (package,))
            suite.addPackageRecursive(package)
        else:
            _dbg("addPackage(%s)" % (package,))
            suite.addPackage(package)
Example #36
0
def getProcessor(input, output, config):
    plugins = plugin.getPlugins(IProcessor)
    for plug in plugins:
        if plug.name == input:
            module = reflect.namedModule(plug.moduleName)
            break
    else:
        # try treating it as a module name
        try:
            module = reflect.namedModule(input)
        except ImportError:
            print '%s: no such input: %s' % (sys.argv[0], input)
            return
    try:
        return process.getProcessor(module, output, config)
    except process.NoProcessorError, e:
        print "%s: %s" % (sys.argv[0], e)
Example #37
0
 def test_namedModuleLookup(self):
     """
     L{namedModule} should return the module object for the name it is
     passed.
     """
     from twisted.python import monkey
     self.assertIs(
         reflect.namedModule("twisted.python.monkey"), monkey)
Example #38
0
def getProcessor(input, output, config):
    plugins = plugin.getPlugins(IProcessor)
    for plug in plugins:
        if plug.name == input:
            module = reflect.namedModule(plug.moduleName)
            break
    else:
        # try treating it as a module name
        try:
            module = reflect.namedModule(input)
        except ImportError:
            print '%s: no such input: %s' % (sys.argv[0], input)
            return
    try:
        return process.getProcessor(module, output, config)
    except process.NoProcessorError, e:
        print "%s: %s" % (sys.argv[0], e)
Example #39
0
    def processComponent(componentName, v):
        if collectionName is not None:
            componentName = "{:s}/{:s}".format(collectionName, componentName)

        # It's a class
        if IComponent.implementedBy(v):
            fileName = namedModule(v.__module__).__file__
            objectName = "{:s}.{:s}".format(v.__module__, v.__name__)
            component = v()

        # It's a function (eg getComponent)
        elif callable(v):
            fileName = namedModule(v.__module__).__file__
            objectName = "{:s}.{:s}".format(v.__module__, v.__name__)
            component = v()

            if not IComponent.providedBy(component):
                raise Error(
                    "{:s}.{:s}() does not produce a valid Component".format(
                        v.__module__, v.__name__))

        # It's a string - hopefully a '.fbp' or '.json'
        else:
            import graph
            fileName = os.path.join(moduleDir, str(v))
            objectName = None
            component = graph.loadFile(fileName)

            if not IComponent.providedBy(component):
                raise Error("{:s} does not produce a valid Component".format(
                    componentName))

        # Make sure we will check the ".py" file
        if fileName[-4:] == ".pyc":
            fileName = fileName[:-1]

        if component.ready:
            return defer.succeed(
                (fileName, objectName, componentName, component))
        else:
            d = defer.Deferred()
            component.once(
                "ready", lambda data: d.callback(
                    (fileName, objectName, componentName, component)))
            return d
Example #40
0
    def buildOptions(self):
        assert self.program is not None

        config = self.optionsClass(self.program)

        config.commandPackage = reflect.namedModule(self.commandPackageName)
        log.msg("Loaded the plugin package: {0.commandPackage}".format(config))

        return config
Example #41
0
 def bot_rebuild(self, sender, message, metadata):
     self.loadBotList()
     from twisted.words import botbot
     from twisted.python.rebuild import rebuild
     from twisted.python.reflect import namedModule
     if message:
         rebuild(namedModule(message))
     else:
         rebuild(botbot)
Example #42
0
def addMod(arg, path, files):
    if "test" in files:
        files.remove("test")
    if "topfiles" in files:
        files.remove("topfiles")
    for fn in files:
        file = os.path.join(path, fn).replace("%s__init__" % os.sep, "")
        if file[-3:] == ".py":
            modName = file[:-3].replace(os.sep, ".")
            try:
                # print 'pre-loading', modName
                reflect.namedModule(modName)
            except ImportError:
                print "import error:", modName
            except:
                print "other error:", modName
            else:
                modnames.append(modName)
Example #43
0
def local_workers():
    workers = []
    for i in range(util.env.MAX_LOCAL_WORKERS):
        worker_ = LocalWorker('lw%03d-%s' % (i, util.env.SUFFIX))
        # Hack to fix a bug stating that LocalWorkers
        # do not have a valid path_module
        worker_.path_module = namedModule('posixpath')
        workers.append(worker_)
    return workers
    def setupStep(self, step, args={}, patch=None, **kwargs):
        step = sourcesteps.SourceStepMixin.setupStep(self, step, args={}, patch=None, **kwargs)
        self.build.getSourceStamp().revision = args.get('revision', None)

        # builddir propety used to create absolute path required in perforce client spec.
        workspace_dir = '/home/user/workspace'
        if _is_windows:
            workspace_dir = r'C:\Users\username\Workspace'
            self.build.path_module = reflect.namedModule("ntpath")
        self.properties.setProperty('builddir', workspace_dir, 'P4')
Example #45
0
 def find_global(modname, clsname):
     try:
         return substituteClasses[(modname, clsname)]
     except KeyError:
         mod = reflect.namedModule(modname)
         try:
             return getattr(mod, clsname)
         except AttributeError:
             raise AttributeError("Module %r (%s) has no attribute %s"
                                  % (mod, modname, clsname))
    def setupStep(self, step, args={}, patch=None, **kwargs):
        step = sourcesteps.SourceStepMixin.setupStep(self, step, args={}, patch=None, **kwargs)
        self.build.getSourceStamp().revision = args.get('revision', None)

        # builddir propety used to create absolute path required in perforce client spec.
        workspace_dir = '/home/user/workspace'
        if _is_windows:
            workspace_dir = r'C:\Users\username\Workspace'
            self.build.path_module = reflect.namedModule("ntpath")
        self.properties.setProperty('builddir', workspace_dir, 'P4')
Example #47
0
def main(options, _args):
    ##
    # Incredible hack right now
    sys.argv = [sys.argv[0]] + ['--help']
    try:
        pipeline = namedModule('vappio.pipelines.' +
                               options('general.pipeline'))
        runPipeline(None, None, pipeline)
    except ImportError:
        errorPrint('The requested pipeline could not be found')
Example #48
0
 def find_global(modname, clsname):
     try:
         return substituteClasses[(modname, clsname)]
     except KeyError:
         mod = reflect.namedModule(modname)
         try:
             return getattr(mod, clsname)
         except AttributeError:
             raise AttributeError("Module %r (%s) has no attribute %s"
                                  % (mod, modname, clsname))
Example #49
0
    def test_get_fake_graphql_schema(self):
        if not graphql:
            raise unittest.SkipTest('Test requires graphql')

        # use the test module for basic graphQLSchema generation
        mod = reflect.namedModule('buildbot.test.fake.endpoint')
        self.data._scanModule(mod)
        schema = self.data.get_graphql_schema()
        self.assertEqual(schema, mod.graphql_schema)
        schema = graphql.build_schema(schema)
Example #50
0
 def __init__(self, original):
     self.original = o = original
     self.name = o.__name__
     self.klass  = original.im_class
     self.module = reflect.namedModule(original.im_class.__module__)
     self.fullName = "%s.%s.%s" % (self.module.__name__, self.klass.__name__,
                                   self.name)
     self.docstr = (o.__doc__ or None)
     self.startTime = 0.0
     self.endTime = 0.0
     self.errors = []
Example #51
0
 def upgrade(self, quiet=False):
     """
     Upgrade this database to the current version
     """
     while self.get_db_version() < self.get_current_version():
         next_version = self.get_db_version() + 1
         next_version_module = reflect.namedModule("buildbot.db.schema.v%d" % next_version)
         upg = next_version_module.Upgrader(self.dbapi, self.conn, self.basedir, quiet)
         upg.upgrade()
         self.conn.commit()
         assert self.get_db_version() == next_version
Example #52
0
def doStartup(options):
    """Utility function to execute the startup function, after
    checking the schema if necessary"""
    from warp.common.schema import getConfig
    if getConfig()["check"]:
        from warp.common import schema
        schema.migrate()

    configModule = reflect.namedModule(options['config'])
    if hasattr(configModule, 'startup'):
        configModule.startup()
Example #53
0
    def load(self):
        if self.loaded:
            raise AlreadyLoadedError(repr(self))
        self.plugins = []

        sys.dont_write_bytecode, olddwbc = True, sys.dont_write_bytecode
        names = listpackage(self.package)
        for name in names:
            plugin = namedModule(self.package + "." + name)
            self.plugins.append(plugin)
        self.loaded = True
        sys.dont_write_bytecode = olddwbc
def _wrappedPdb():
    """
    Wrap an instance of C{pdb.Pdb} with readline support and load any .rcs.

    """

    dbg = pdb.Pdb()
    try:
        namedModule("readline")
    except ImportError:
        print("readline module not available")
        sys.exc_clear()
    for path in (".pdbrc", "pdbrc"):
        if os.path.exists(path):
            try:
                rcFile = file(path, "r")
            except IOError:
                sys.exc_clear()
            else:
                dbg.rcLines.extend(rcFile.readlines())
    return dbg
Example #55
0
def _wrappedPdb():
    """
    Wrap an instance of C{pdb.Pdb} with readline support and load any .rcs.

    """

    dbg = pdb.Pdb()
    try:
        namedModule("readline")
    except ImportError:
        print("readline module not available")
    for path in (".pdbrc", "pdbrc"):
        if os.path.exists(path):
            try:
                rcFile = open(path)
            except OSError:
                pass
            else:
                with rcFile:
                    dbg.rcLines.extend(rcFile.readlines())
    return dbg
Example #56
0
    def opt_help_reactors(self):
        """
        Display a list of possibly available reactor names.
        """
        rcts = sorted(self._getReactorTypes(), key=attrgetter('shortName'))
        notWorkingReactors = ""
        for r in rcts:
            try:
                namedModule(r.moduleName)
                self.messageOutput.write('    %-4s\t%s\n' %
                                         (r.shortName, r.description))
            except ImportError as e:
                notWorkingReactors += ('    !%-4s\t%s (%s)\n' %
                                       (r.shortName, r.description, e.args[0]))

        if notWorkingReactors:
            self.messageOutput.write('\n')
            self.messageOutput.write('    reactors not available '
                                     'on this platform:\n\n')
            self.messageOutput.write(notWorkingReactors)
        raise SystemExit(0)
Example #57
0
    def opt_help_reactors(self):
        """
        Display a list of possibly available reactor names.
        """
        rcts = sorted(self._getReactorTypes(), key=attrgetter('shortName'))
        notWorkingReactors = ""
        for r in rcts:
            try:
                namedModule(r.moduleName)
                self.messageOutput.write('    %-4s\t%s\n' %
                                         (r.shortName, r.description))
            except ImportError as e:
                notWorkingReactors += ('    !%-4s\t%s (%s)\n' %
                                       (r.shortName, r.description, e.args[0]))

        if notWorkingReactors:
            self.messageOutput.write('\n')
            self.messageOutput.write('    reactors not available '
                                     'on this platform:\n\n')
            self.messageOutput.write(notWorkingReactors)
        raise SystemExit(0)
Example #58
0
def _wrappedPdb():
    """
    Wrap an instance of C{pdb.Pdb} with readline support and load any .rcs.

    """

    dbg = pdb.Pdb()
    try:
        namedModule('readline')
    except ImportError:
        print("readline module not available")
    for path in ('.pdbrc', 'pdbrc'):
        if os.path.exists(path):
            try:
                rcFile = open(path, 'r')
            except IOError:
                pass
            else:
                with rcFile:
                    dbg.rcLines.extend(rcFile.readlines())
    return dbg