Ejemplo n.º 1
0
    def test_branch_jobs(self):
        self.cmd.fromMacros = conarymacros.Macros({'branch': 'foo'})
        self.cmd.toMacros = conarymacros.Macros({'branch': 'bar'})
        mock.mock(bc.utils, 'readJob', 'job')
        mock.mock(bc.utils, 'readTemplate', {
            'name': '/jobs/%(branch)s.xml',
            'templates': [],
        })
        mock.mock(bc.utils, 'writeJob')
        mock.mock(bc.warnings, 'warn')
        mock.mockMethod(self.cmd._updateJobData, 'newJob')

        templateList = ['template']

        self.cmd.branchJobs(templateList)
        bc.utils.readTemplate._mock.assertCalled('template')
        bc.utils.readJob._mock.assertCalled('/jobs/foo.xml')
        bc.utils.writeJob._mock.assertCalled('/jobs/bar.xml', 'newJob')
        bc.warnings.warn._mock.assertNotCalled()

        self.cmd._updateJobData._mock.raiseErrorOnAccess(
            jberrors.TemplateError('error'))
        err = self.assertRaises(
            jberrors.CommandError,
            self.cmd.branchJobs,
            templateList,
        )
        self.assertEqual(str(err), "error parsing job '/jobs/foo.xml'")
Ejemplo n.º 2
0
 def testUpdate(self):
     m1 = macros.Macros()
     m1.a = 'a'
     m1.b = 'b'
     m2 = m1.copy()
     m2.c = 'c'
     m3 = macros.Macros()
     m3.d = 'd'
     m3.e = 'e'
     m4 = m3.copy()
     m4.f = 'f'
     m2.update(m4)
     keys = m2.keys()
     keys.sort()
     assert (keys == ['a', 'b', 'c', 'd', 'e', 'f'])
Ejemplo n.º 3
0
 def setUp(self):
     jbutlerhelp.JButlerHelper.setUp(self)
     self.xml = ("<foo>"
                 "<bar>text to update</bar>"
                 "<baz>some other text</baz>"
                 "</foo>")
     self.doc = etree.fromstring(self.xml)
     self.macros = conarymacros.Macros({'data': 'some data'})
     self.paths = {
         '/foo/bar': '%(data)s',
     }
     self.cmd = bc.BranchCommand()
     self.cmd.toMacros = conarymacros.Macros({'data': 'some data'})
     self.cmd.fromMacros = conarymacros.Macros({'data': 'some old data'})
     self.cmd.jobDir = '/jobs'
Ejemplo n.º 4
0
    def test_branch_jobs_template_macros(self):
        self.cmd.fromMacros = None
        self.cmd.toMacros = conarymacros.Macros({'branch': 'bar'})
        mock.mock(bc.utils, 'readJob', 'job')
        mock.mock(
            bc.utils, 'readTemplate', {
                'name': '/jobs/%(branch)s.xml',
                'templates': [],
                'macros': [
                    ['branch', 'foo'],
                ]
            })
        mock.mock(bc.utils, 'writeJob')
        mock.mock(bc.utils, 'writeTemplate')
        mock.mock(bc.warnings, 'warn')
        mock.mockMethod(self.cmd._updateJobData, 'newJob')

        templateList = ['template']

        self.cmd.branchJobs(templateList)
        bc.utils.readTemplate._mock.assertCalled('template')
        bc.utils.readJob._mock.assertCalled('/jobs/foo.xml')
        bc.utils.writeJob._mock.assertCalled('/jobs/bar.xml', 'newJob')
        bc.warnings.warn._mock.assertCalled(
            'Support for macros stored in templates is deprecated.',
            DeprecationWarning,
        )
Ejemplo n.º 5
0
    def test_branch_jobs_template_macros_templateerror(self):
        self.cmd.fromMacros = None
        self.cmd.toMacros = conarymacros.Macros({'branch': 'bar'})
        mock.mock(bc.utils, 'readJob', 'job')
        mock.mock(
            bc.utils, 'readTemplate', {
                'name': '/jobs/%(branch)s.xml',
                'templates': [],
                'macros': [
                    ['branch', 'foo'],
                ]
            })
        mock.mock(bc.utils, 'writeJob')
        mock.mock(bc.utils, 'writeTemplate')
        mock.mock(bc.warnings, 'warn')
        mock.mockMethod(self.cmd._updateJobData, 'newJob')

        templateList = ['template']

        self.cmd._updateJobData._mock.raiseErrorOnAccess(
            jberrors.TemplateError('error'))
        err = self.assertRaises(
            jberrors.CommandError,
            self.cmd.branchJobs,
            templateList,
        )
        self.assertEqual(str(err), "error parsing job '/jobs/foo.xml'")
        bc.warnings.warn._mock.assertCalled(
            'Support for macros stored in templates is deprecated.',
            DeprecationWarning,
        )
Ejemplo n.º 6
0
 def preProcess(self):
     self.invariantsubtrees = [x[0] for x in self.invariantinclusions]
     # see if we can do debuginfo
     self.debuginfo = False
     # we need this for the debuginfo case
     self.dm = macros.Macros()
     self.dm.update(self.macros)
     # we need to start searching from just below the build directory
     topbuilddir = '/'.join(self.macros.builddir.split('/')[:-1])
     if self.tryDebuginfo and\
        'eu-strip' in self.macros.strip and \
        'debugedit' in self.macros and \
        util.checkPath(self.macros.debugedit):
         if len(self.macros.debugsrcdir) > len(topbuilddir):
             # because we have to overwrite fixed-length strings
             # in binaries, we need to ensure that the value being
             # written is no longer than the existing value to
             # avoid corrupting the binaries
             raise RuntimeError(
                 'insufficient space in binaries'
                 ' for path replacement, add %d characters to buildPath' %
                 (len(self.macros.debugsrcdir) - len(topbuilddir)))
         self.debuginfo = True
         self.debugfiles = set()
         self.dm.topbuilddir = topbuilddir
Ejemplo n.º 7
0
 def testMacros(self):
     m1 = macros.Macros()
     m1.a = 'foo'
     assert (m1.a == 'foo')
     m2 = m1.copy()
     m2.a = 'bar'
     assert (m1.a == 'foo')
     assert (m2.a == 'bar')
     m3 = m2.copy(False)
     m3.a = 'baz'
     assert (m2.a == 'bar')
     assert (m3.a == 'baz')
     m4 = m3
     m4.a = 'blah'
     assert (m3.a == 'blah')
     m1.b = '%(a)s/asdf'
     assert (m1.b == 'foo/asdf')
     m1.trackChanges()
     m1.c = 'foo'
     assert (m1.getTrackedChanges() == ['c'])
     m1.trackChanges(False)
     m1.d = 'bar'
     assert (m1.getTrackedChanges() == ['c'])
     m1.e = '1'
     m1._override('e', '2')
     m1.e = '3'
     assert (m1.e == '2')
     m1.r = 'foo++'
     assert (m1.r == 'foo++')
     assert (m1['r'] == 'foo++')
     assert (str(m1['r.literalRegex']) == 'foo\+\+')
     assert (str("%(r.literalRegex)s" % m1) == 'foo\+\+')
Ejemplo n.º 8
0
    def testCallback(self):
        a = [1]
        m1 = macros.Macros()

        def myfun(name):
            a.append(2)

        m1.setCallback('foo', myfun)
        m1.foo = 'hello'
        assert ('%(foo)s' % m1 == 'hello')
        assert (a == [1, 2])
Ejemplo n.º 9
0
 def testIterItems(self):
     m1 = macros.Macros()
     m1.a = 'a'
     m1.b = 'b'
     m2 = m1.copy()
     m2.c = 'c'
     iterkeys = [x for x in m2.iterkeys()]
     iterkeys.sort()
     assert (iterkeys == ['a', 'b', 'c'])
     keys = m2.keys()
     keys.sort()
     assert (keys == ['a', 'b', 'c'])
     iteritems = [x for x in m2.iteritems()]
     iteritems.sort()
     assert (iteritems == [('a', 'a'), ('b', 'b'), ('c', 'c')])
Ejemplo n.º 10
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 = {}
Ejemplo n.º 11
0
    except Exception, msg:
        errMsg = 'Error initializing cook environment %s=%s[%s]: %s' % \
                                            (name, version, flavor, str(msg))
        _buildFailed(failureFd, errMsg, traceback.format_exc())

    try:
        os.chdir('/tmp')  # make sure we're in a directory
        # that we can write to.  Although
        # this _shouldn't_ be an issue,
        # conary 1.0.{19,20} require it.
        # finally actually cook the recipe!
        groupOptions = cook.GroupCookOptions(
            alwaysBumpCount=False,
            shortenFlavors=cfg.shortenGroupFlavors,
            errorOnFlavorChange=False)
        m = macros.Macros()
        m._override('buildlabel', str(buildLabel))
        m._override('buildbranch', str(buildBranch))
        m._override('binarybranch', str(binaryBranch))
        toCook = compat.ConaryVersion().getObjectsToCook(
            loaders, recipeClasses)
        built = cook.cookObject(repos,
                                cfg,
                                toCook,
                                version,
                                prep=False,
                                macros=m,
                                targetLabel=targetLabel,
                                changeSetFile=csFile,
                                alwaysBumpCount=False,
                                ignoreDeps=False,
Ejemplo n.º 12
0
    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
Ejemplo n.º 13
0
 def testGet(self):
     m1 = macros.Macros()
     m1.march = 'i386'
     m1.target = '%(march)s-unknown-linux'
     assert (m1.target == 'i386-unknown-linux')
     assert (m1._get('target') == '%(march)s-unknown-linux')