예제 #1
0
def getHandle():
    cfg = handle.RbuildHandle.configClass(readConfigFiles=True)
    cfg.configLine("pluginDirs %s" % os.path.abspath(
        os.path.join(os.path.dirname(__file__), '..', 'plugins')))
    plugins = pluginloader.getPlugins([], cfg.pluginDirs)
    h = handle.RbuildHandle(cfg=cfg, pluginManager=plugins, productStore=None)
    return h
예제 #2
0
 def getRbuildHandle(self,
                     productStore=None,
                     cfg=None,
                     pluginManager=None,
                     userInterface=None,
                     logRoot=None,
                     mockOutput=True):
     # Note: order of arguments is different because code in test suite
     # assumes that first argument is productStore not cfg
     if isinstance(productStore, mock.MockObject):
         productStore.getRbuildConfigPath._mock.setReturn(self.workDir +
                                                          '/rbuildrc')
         productStore.getRmakeConfigPath._mock.setReturn(self.workDir +
                                                         '/rmakerc')
     if cfg is None:
         self.rbuildCfg.repositoryMap = self.cfg.repositoryMap
         cfg = self.rbuildCfg
     if logRoot is None:
         logRoot = self.workDir + '/.rbuild'
     h = handle.RbuildHandle(cfg=cfg,
                             pluginManager=pluginManager,
                             productStore=productStore,
                             userInterface=userInterface,
                             logRoot=logRoot)
     if mockOutput:
         h.ui.outStream = mock.MockObject()
         h.ui.errorStream = mock.MockObject()
     return h
예제 #3
0
 def testBasic(self):
     # can we access plugins from the handle?
     configPath = self.cfg.root + '/etc/rbuildrc'
     util.mkdirChain(os.path.dirname(configPath))
     rbuildCfg = self.rbuildCfg
     self.rbuildCfg.store(open(configPath, 'w'))
     self.mock(rbuildcfg, 'RbuildConfiguration',
               lambda *args, **kw: rbuildCfg)
     rbuildHandle = handle.RbuildHandle()
     assert (rbuildHandle.Build)
     # can we install + use a hook?
     rbuildHandle.installPrehook(rbuildHandle.Config.displayConfig,
                                 self.myHook)
     _, txt = self.captureOutput(rbuildHandle.Config.displayConfig,
                                 rbuildHandle)
     assert (txt.split('\n')[0] == 'My hook!')
예제 #4
0
    def getCommand(self, argv, cfg):
        """
        Initializes plugins so that all commands are available,
        then returns the correct command based on argv.

        @param argv: Argument vector as provided by C{sys.argv}
        @param cfg: An C{RbuildConfiguration} object
        @return: C{commandClass} instance selected by C{argv}
        """
        self.plugins = pluginloader.getPlugins(argv, cfg.pluginDirs)
        self.handle = handle.RbuildHandle(cfg, self.plugins)
        self.handle.ui.pushContext('rBuild %s: %s',
                                   self.version, ' '.join(argv))
        self.plugins.registerCommands(self, self.handle)
        self.plugins.registerFacade(self.handle)
        self.plugins.initialize()
        return mainhandler.MainHandler.getCommand(self, argv, cfg)
예제 #5
0
파일: api1.py 프로젝트: pombreda/rbuild-1
def getHandle(dirName=None, prodDefLabel=None):
    """
        Initializes an rBuild handle object, with a product definition
        as defined by the C{dirName} parameter (which provides a
        C{dirstore.CheckoutProductStore} product store) or the
        C{prodDefLabel} parameter (which provides a more limited
        C{abstract.ProductStore} product store that is insufficient
        for many plugin operations).  If no parameter is specified,
        a  C{dirstore.CheckoutProductStore} product store is provided
        based on the current directory.

        @param dirName: (None) directory for product store
        @param prodDefLabel: (None) label for product definition.
        @return: C{handle} instance
        """
    cfg = handle.RbuildHandle.configClass(readConfigFiles=True)

    if prodDefLabel:
        productStore = None
    else:
        # note that if dirName is None, this defaults to current directory
        productStore = dirstore.CheckoutProductStore(baseDirectory=dirName)

    plugins = pluginloader.getPlugins([], cfg.pluginDirs)
    h = handle.RbuildHandle(cfg=cfg,
                            pluginManager=plugins,
                            productStore=productStore)

    if prodDefLabel:
        productStore = abstract.ProductStore()
        product = productStore.getProduct()
        client = h.facade.conary._getConaryClient()
        stream, _ = product._getStreamFromRepository(client, prodDefLabel)
        stream.seek(0)
        product.parseStream(stream)

    return h
예제 #6
0
 def testGetDefaultConfig(self):
     mock.mock(handle.RbuildHandle, 'configClass')
     h = handle.RbuildHandle(cfg=None, pluginManager=mock.MockObject())
     handle.RbuildHandle.configClass._mock.assertCalled(
         readConfigFiles=True)