예제 #1
0
 def __init__(self, cfg):
     recipe.Recipe.__init__(self, cfg)
     self.macros = macros.Macros()
     self.macros.update(recipe.loadMacros(cfg.defaultMacros))
     self.theMainDir = 'dummy-1.0'
     self.macros.builddir = tempfile.mkdtemp()
     self.macros.destdir = tempfile.mkdtemp()
     self.macros.maindir = self.theMainDir
     self.srcdirs = [cfg.sourceSearchDir]
     self.buildinfo = buildinfo.BuildInfo(self.macros.builddir)
     self.buildinfo.begin()
     self.laReposCache = lookaside.RepositoryCache(None, cfg=cfg)
     self.fileFinder = lookaside.FileFinder('dummy', self.laReposCache,
                                            self.srcdirs, {},
                                            cfg.mirrorDirs)
     self.name = 'dummy'
     self.version = '1.0'
     self.explicitMainDir = False
     self._derivedFiles = {}
예제 #2
0
def getRecipeObj(repos,
                 name,
                 version,
                 flavor,
                 trv,
                 loadInstalledSource=None,
                 installLabelPath=None,
                 loadRecipeSpecs=None,
                 buildLabel=None,
                 groupRecipeSource=None,
                 cfg=None):
    if cfg:
        cfg = copy.deepcopy(cfg)
    else:
        cfg = conarycfg.ConaryConfiguration(False)
    cfg.initializeFlavors()
    branch = version.branch()
    if not buildLabel:
        buildLabel = version.branch().label()
    if not installLabelPath:
        cfg.installLabelPath = [buildLabel]
    else:
        cfg.installLabelPath = installLabelPath
    cfg.buildFlavor = flavor
    cfg.defaultBasePackages = []
    name = name.split(':')[0]
    use.LocalFlags._clear()
    assert (flavorutil.getArch(flavor))
    use.setBuildFlagsFromFlavor(name, flavor, error=False)
    use.resetUsed()
    use.track(True)
    ignoreInstalled = not loadInstalledSource
    macros = {
        'buildlabel': buildLabel.asString(),
        'buildbranch': version.branch().asString()
    }
    cfg.lookaside = tempfile.mkdtemp()
    try:
        loader = RecipeLoaderFromSourceTrove(trv,
                                             repos,
                                             cfg,
                                             name + ':source',
                                             branch,
                                             ignoreInstalled=ignoreInstalled,
                                             db=loadInstalledSource,
                                             buildFlavor=flavor)
        recipeClass = loader.getRecipe()
        recipeClass._trove = trv
        if recipe.isGroupRecipe(recipeClass):
            recipeObj = recipeClass(repos,
                                    cfg,
                                    buildLabel,
                                    flavor,
                                    None,
                                    extraMacros=macros)
            recipeObj.sourceVersion = version
            recipeObj.loadPolicy()
            recipeObj.setup()
        elif (recipe.isPackageRecipe(recipeClass)
              or recipe.isFactoryRecipe(recipeClass)
              or recipe.isCapsuleRecipe(recipeClass)):
            if recipe.isFactoryRecipe(recipeClass):
                #This requires a specific capability in conary
                compat.ConaryVersion().requireFactoryRecipeGeneration()
                #Load the FactoryRecipe
                factoryClass = recipeClass
                loaded = cook.loadFactoryRecipe(factoryClass, cfg, repos,
                                                flavor)
                recipeClass = loaded.getRecipe()
            lcache = lookaside.RepositoryCache(repos)
            recipeObj = recipeClass(cfg,
                                    lcache, [],
                                    macros,
                                    lightInstance=True)
            recipeObj.sourceVersion = version
            recipeObj.populateLcache()
            if not recipeObj.needsCrossFlags():
                recipeObj.crossRequires = []
            recipeObj.loadPolicy()
            recipeObj.setup()
        elif recipe.isInfoRecipe(recipeClass):
            recipeObj = recipeClass(cfg, None, None, macros)
            recipeObj.sourceVersion = version
            recipeObj.setup()
        elif recipe.isRedirectRecipe(recipeClass):
            binaryBranch = version.getBinaryVersion().branch()
            recipeObj = recipeClass(repos, cfg, binaryBranch, flavor)
            recipeObj.sourceVersion = version
            recipeObj.setup()
        elif recipe.isFileSetRecipe(recipeClass):
            recipeObj = recipeClass(repos,
                                    cfg,
                                    buildLabel,
                                    flavor,
                                    extraMacros=macros)
            recipeObj.sourceVersion = version
            recipeObj.setup()
        else:
            raise RuntimeError, 'Unknown class type %s for recipe %s' % (
                recipeClass, name)
    finally:
        util.rmtree(cfg.lookaside)
    return recipeObj, loader
예제 #3
0
    def testDuplicateBasenames(self):
        self.resetCache()
        self.resetWork()
        self.resetRepository()
        repos = self.openRepository()
        cfg = self.cfg
        repCache = lookaside.RepositoryCache(repos, cfg=cfg)

        try:
            contentServer = rephelp.HTTPServerController(getRequester())
            contentURL = contentServer.url()

            origDir = os.getcwd()
            os.chdir(self.workDir)
            self.newpkg('test')
            os.chdir('test')
            testdir = '/'.join((self.workDir, 'test'))

            log.setVerbosity(log.INFO)
            self.logFilter.add()

            # first, look for a file that does not exist
            assert lookaside.findAll(self.cfg,
                                     repCache,
                                     contentURL + '/404/foo',
                                     'test', (testdir, ),
                                     allowNone=True) is None
            # make sure that we got a negative cache entry
            assert os.stat(self.cacheDir + '/NEGATIVE/test/404/foo')

            # now look for a file that does exist
            assert lookaside.findAll(self.cfg,
                                     repCache,
                                     contentURL + '/200/foo',
                                     'test', (testdir, ),
                                     allowNone=True) is not None
            # make sure that we got a the cache entry
            assert os.stat(self.cacheDir + '/test/200/foo')

            # put two different files with the same name name in the cache
            fooDir = os.path.join(self.cacheDir, 'test/foo.conary.com/foo/')
            os.makedirs(fooDir)
            self.writeFile(os.path.join(fooDir, 'theFile'),
                           'Foo version of the file\n')
            barDir = os.path.join(self.cacheDir, 'test/bar.conary.com/bar/')
            os.makedirs(barDir)
            self.writeFile(os.path.join(barDir, 'theFile'),
                           'Bar version of the file\n')

            # this file shouldn't be found
            path = lookaside.findAll(self.cfg,
                                     repCache,
                                     'http://baz.conary.com/foo/theFile',
                                     'test', (testdir, ),
                                     allowNone=True)
            self.assertEqual(path, None)
            # this file should be found and have the right contents
            path = lookaside.findAll(self.cfg,
                                     repCache,
                                     'http://foo.conary.com/foo/theFile',
                                     'test', (testdir, ),
                                     allowNone=True)
            f = open(path)
            self.assertEqual(f.readline()[0:3], 'Foo')
            f.close()
            # so should this one
            path = lookaside.findAll(self.cfg,
                                     repCache,
                                     'http://bar.conary.com/bar/theFile',
                                     'test', (testdir, ),
                                     allowNone=True)
            f = open(path)
            self.assertEqual(f.readline()[0:3], 'Bar')
            f.close()
        finally:
            contentServer.kill()
예제 #4
0
파일: recipe.py 프로젝트: sweptr/conary
    def __init__(self,
                 cfg,
                 lightInstance=False,
                 laReposCache=None,
                 srcdirs=None):
        if laReposCache is None:
            laReposCache = lookaside.RepositoryCache(None)
        assert (self.__class__ is not Recipe)
        self.validate()
        self.cfg = cfg
        self.externalMethods = {}
        # lightInstance for only instantiating, not running (such as checkin)
        self._lightInstance = lightInstance
        self._sources = []
        self.loadSourceActions()
        self.buildinfo = None
        self.metadataSkipSet = [
            'keyValue',
        ]
        self.laReposCache = laReposCache
        self.srcdirs = srcdirs
        self.sourcePathMap = {}
        self.pathConflicts = {}
        self._recordMethodCalls = False
        self.methodsCalled = []
        self.unusedMethods = set()
        self.methodDepth = 0
        self._pathTranslations = []
        self._repos = None
        self._capsulePathMap = {}
        self._capsulePackageMap = {}
        self._capsuleDataMap = {}
        self._capsules = {}
        self._lcstate = None
        self._propertyMap = {}

        baseMacros = loadMacros(cfg.defaultMacros)
        self.macros = macros.Macros(ignoreUnknown=lightInstance)
        self.macros.update(baseMacros)

        # Metadata is a hash keyed on a trove name and with a list of
        # per-trove-name MetadataItem like objects (well, dictionaries)
        self._metadataItemsMap = {}
        # Old metadata, keyed on trove name, with ((n, v, f), metadata, log)
        # as value
        self._oldMetadataMap = {}
        self._filteredKeyValueMetadata = set()
        # Multi-URL map, used for multiple URL support in addArchive et al
        self.multiurlMap = {}
        # Search method for sources
        self.cookType = self.COOK_TYPE_LOCAL

        superClasses = self.__class__.__mro__

        for itemName in dir(self):
            if itemName[0] == '_':
                continue
            item = getattr(self, itemName)
            if inspect.ismethod(item):
                if item.im_class == type:
                    # classmethod
                    continue
                className = self.__class__.__name__
                for class_ in superClasses:
                    classItem = getattr(class_, itemName, None)
                    if classItem is None:
                        continue
                    if classItem.im_func == item.im_func:
                        className = class_.__name__
                if className in [
                        'Recipe', 'AbstractPackageRecipe',
                        'SourcePackageRecipe', 'BaseRequiresRecipe',
                        'GroupRecipe', '_GroupRecipe', 'GroupSetRecipe',
                        '_GroupSetRecipe', 'RedirectRecipe',
                        'AbstractDerivedPackageRecipe', 'DerivedPackageRecipe',
                        'AbstractDerivedCapsuleRecipe', 'DerivedCapsuleRecipe',
                        'FilesetRecipe', '_BaseGroupRecipe'
                ]:
                    continue
                setattr(self, itemName, self._wrapMethod(className, item))
                self.unusedMethods.add((className, item.__name__))

        # Inspected only when it is important to know for reporting
        # purposes what was specified in the recipe per se, and not
        # in superclasses or in defaultBuildRequires
        self._recipeRequirements = {
            'buildRequires': list(self.buildRequires),
            'crossRequires': list(self.crossRequires)
        }

        self._includeSuperClassBuildReqs()
        self._includeSuperClassCrossReqs()
        self.transitiveBuildRequiresNames = None
        self._subscribeLogPath = None
        self._subscribedPatterns = []
        self._logFile = None
        self._isCrossCompileTool = False
        self._isCrossCompiling = False
예제 #5
0
    def testLookAsideTest1(self):
        raise testhelp.SkipTestException(
            "tests shouldn't talk to the internet")
        self.resetCache()
        self.resetWork()
        self.resetRepository()
        repos = self.openRepository()
        cfg = self.cfg
        repCache = lookaside.RepositoryCache(repos, cfg=cfg)

        origDir = os.getcwd()
        os.chdir(self.workDir)
        self.newpkg('test')
        os.chdir('test')
        testdir = '/'.join((self.workDir, 'test'))

        log.setVerbosity(log.INFO)
        self.logFilter.add()
        # first, look for a file that does not exist
        assert (lookaside.findAll(self.cfg,
                                  repCache,
                                  'http://example.conary.com/foo',
                                  'test', (testdir, ),
                                  allowNone=True) is None)
        # make sure that we got a negative cache entry
        assert (os.stat('/'.join(
            (self.cacheDir, 'NEGATIVE/test/example.conary.com/foo'))))

        # now make sure that this works for ftp as well (urllib workaround)
        #    XXX WORKAROUND until FTP works in eng lab
        #assert(lookaside.findAll(self.cfg, repCache,
        #    'ftp://download.rpath.com/blah', 'test', (testdir,),
        #     allowNone=True) is None)
        # make sure that we got a negative cache entry
        #assert(os.stat('/'.join((self.cacheDir,
        #                         'NEGATIVE/test/download.rpath.com/blah'))))

        # now we put a file in place
        f = file(os.sep.join((testdir, 'bar')), 'w')
        f.write('this is a test')
        f.close()
        c = lookaside.findAll(self.cfg, repCache, 'bar', 'test', (testdir, ))
        # it does not need to cache it; it is known to exist
        assert (c == os.sep.join((testdir, 'bar')))

        # Test httpHeaders:
        c = util.normpath(
            lookaside.findAll(self.cfg,
                              repCache,
                              'http://www.google.com/preferences',
                              'test', (testdir, ),
                              httpHeaders={'Accept-Language': 'es-es'}))
        assert (c == '/'.join(
            (self.cacheDir, 'test/www.google.com/preferences')))
        #open the page and check to see if it's in spanish
        f = open(c)
        contents = f.read()
        f.close()
        assert 'Preferencias globales' in contents

        # we need a web page to actually test the cache in operation
        # we do it a second time to make sure that the cache works
        for i in (0, 1):
            c = util.normpath(
                lookaside.findAll(self.cfg, repCache,
                                  'http://wiki.rpath.com/wiki/Main_Page',
                                  'test', (testdir, )))
            assert (c == '/'.join(
                (self.cacheDir, 'test/wiki.rpath.com/wiki/Main_Page')))
        self.logFilter.remove()
        self.logFilter.compare((
            '+ Trying http://example.conary.com/foo...',
            # XXX WORKAROUND until FTP works in eng lab
            #'+ Trying ftp://download.rpath.com/blah...',
            #'+ Downloading ftp://download.rpath.com/blah...',
            '+ Trying http://www.google.com/preferences...',
            '+ Downloading http://www.google.com/preferences...',
            '+ Trying http://wiki.rpath.com/wiki/Main_Page...',
            '+ Downloading http://wiki.rpath.com/wiki/Main_Page...'))

        recipestr = """
class TestLookaside(PackageRecipe):
    name = 'test'
    version = '1'
    clearBuildReqs()

    def setup(r):
        r.addSource('bar', dest='/')
"""
        self.writeFile('test.recipe', recipestr)
        self.addfile('test.recipe')
        self.addfile('bar', binary=True)
        self.commit()
        os.chdir(origDir)

        # ensure that a localOnly=True lookup in the repository works;
        # for this, we need a prepped recipeObj for its RepositoryCache
        # object
        recipeObj = self.getRecipeObjFromRepos('test', repos)
        self.logFilter.add()
        c = lookaside.findAll(self.cfg,
                              recipeObj.laReposCache,
                              'bar',
                              'test', (),
                              localOnly=True)
        self.logFilter.remove()
        self.logFilter.compare('+ found bar in repository', )
        assert (c == os.sep.join((self.cacheDir, 'test', 'bar')))