Example #1
0
    def testJavaMagic(self):
        def _p(fpath):
            return os.path.join(resources.get_archive(), fpath)

        # Copy the jar and the war with names that don't suggest the type with
        # the extension
        ojar = os.path.join(self.workDir, "aJarFile")
        util.copyfile(_p("servlet-api.jar"), ojar)
        oear = os.path.join(self.workDir, "aEarFile")
        util.copyfile(_p("stockgrant.ear"), oear)

        # the EAR file convenienty has a WAR file in it, so let's use it
        warPath = os.path.join(self.workDir, "warfile")
        z = zipfile.ZipFile(oear)
        file(warPath, "a").write(z.read("war-ic.war"))

        tests = [
            (_p("broken.jar"), magic.jar, None),
            (_p("servlet-api.jar"), magic.jar, None),
            (_p("stockgrant.ear"), magic.EAR, ("stockgrant3", "Application description")),
            (_p("ownerships.zip"), magic.ZIP, None),
            (ojar, magic.jar, None),
            (oear, magic.EAR, ("stockgrant3", "Application description")),
            (warPath, magic.WAR, ("WebApp1", None)),
        ]

        for fpath, expClass, metadata in tests:
            m = magic.magic(fpath)
            self.assertEqual(m.__class__, expClass)
            if not metadata:
                continue
            displayName, description = metadata
            self.assertEqual(m.contents["displayName"], displayName)
            if description is not None:
                self.assertEqual(m.contents["description"], description)
Example #2
0
    def testConvertSplash(self):
        if not os.path.exists('/usr/bin/pngtopnm'):
            raise testcase.SkipTestException("pngtopnm is not installed")
        ii = self.getHandler(buildtypes.INSTALLABLE_ISO)

        d1 = tempfile.mkdtemp()
        d2 = tempfile.mkdtemp()

        util.mkdirChain(os.path.join(d1, 'isolinux'))
        util.mkdirChain(os.path.join(d2, 'pixmaps'))
        util.copyfile(resources.get_archive('syslinux-splash.png'),
                os.path.join(d2, 'pixmaps', 'syslinux-splash.png'))
        self.suppressOutput(ii.convertSplash, d1, d2)

        result = os.path.join(d1, 'isolinux', 'splash.lss')
        self.checkSha1(result, 'b36af127d5336db0a39a9955cd44b3a8466aa048')
Example #3
0
    def _KERNEL_copy(self, inputSpec, outputFile, mode):
        inputDir = os.path.abspath(os.path.dirname(inputSpec))
        outputFile = os.path.abspath(outputFile)
        finalFile = os.path.abspath(outputFile).replace(self._contentsDir, self._outputDir)
        inputFileSpec = os.path.basename(inputSpec)
        if (not inputDir.startswith(self._workDir) or
            not outputFile.startswith(self._contentsDir)):
            raise RuntimeError("Can't copy outside contents directory")

        # We only expect one match.  If there are more, they
        # should be identical, anyway
        match = [ x for x in os.listdir(inputDir) if x.startswith(inputFileSpec) ][0]
        util.mkdirChain(os.path.dirname(outputFile))
        util.mkdirChain(os.path.dirname(finalFile))
        self._log.info("copying %s to %s", os.path.join(inputDir, match), outputFile)
        util.copyfile(os.path.join(inputDir, match), outputFile)
        os.chmod(outputFile, mode)   
        self._log.info("linking %s to %s", outputFile, finalFile)
        os.link(outputFile, finalFile)
Example #4
0
 def doFile(self, path):
     fullpath = self.macros.builddir + path
     testpath = self.macros.destdir + self.macros.thistestdir + path
     if not (os.path.islink(testpath) or os.path.exists(testpath)):
         if os.path.islink(fullpath):
             contents = os.readlink(fullpath)
             # only install symlinks by default if they point outside of the builddir
             if contents[0] == '/' and not contents.startswith(self.macros.builddir):
                 util.mkdirChain(os.path.dirname(testpath))
                 os.symlink(contents, testpath)
         elif os.path.isfile(fullpath):
             util.mkdirChain(os.path.dirname(testpath))
             util.copyfile(fullpath, testpath, verbose=False)
             self.replaceBuildPath(testpath)
             # finally, include any symlinks that point
             # to the file we just copied
             if path in self.builddirlinks:
                 for linkpath in self.builddirlinks[path]:
                     linkpath = '%(destdir)s%(thistestdir)s' % self.macros + linkpath
                     if not os.path.islink(linkpath):
                         util.mkdirChain(os.path.dirname(linkpath))
                         os.symlink(self.macros.thistestdir + path, linkpath)
Example #5
0
    def testJavaMagic(self):
        def _p(fpath):
            return os.path.join(resources.get_archive(), fpath)
        # Copy the jar and the war with names that don't suggest the type with
        # the extension
        ojar = os.path.join(self.workDir, "aJarFile")
        util.copyfile(_p('servlet-api.jar'), ojar)
        oear = os.path.join(self.workDir, "aEarFile")
        util.copyfile(_p('stockgrant.ear'), oear)

        # the EAR file convenienty has a WAR file in it, so let's use it
        warPath = os.path.join(self.workDir, "warfile")
        z = zipfile.ZipFile(oear)
        file(warPath, "a").write(z.read("war-ic.war"))

        tests = [
            (_p('broken.jar'),      magic.jar, None),
            (_p('servlet-api.jar'), magic.jar, None),
            (_p('stockgrant.ear'),  magic.EAR,
                ('stockgrant3', 'Application description')),
            (_p('ownerships.zip'),  magic.ZIP, None),
            (ojar,                  magic.jar, None),
            (oear,                  magic.EAR,
                ('stockgrant3', 'Application description')),
            (warPath,               magic.WAR,
                ('WebApp1', None)),
        ]

        for fpath, expClass, metadata in tests:
            m = magic.magic(fpath)
            self.assertEqual(m.__class__, expClass)
            if not metadata:
                continue
            displayName, description = metadata
            self.assertEqual(m.contents['displayName'], displayName)
            if description is not None:
                self.assertEqual(m.contents['description'], description)
Example #6
0
 def doFile(self, path):
     fullpath = self.macros.builddir + path
     testpath = self.macros.destdir + self.macros.thistestdir + path
     if not (os.path.islink(testpath) or os.path.exists(testpath)):
         if os.path.islink(fullpath):
             contents = os.readlink(fullpath)
             # only install symlinks by default if they point outside of the builddir
             if contents[0] == '/' and not contents.startswith(
                     self.macros.builddir):
                 util.mkdirChain(os.path.dirname(testpath))
                 os.symlink(contents, testpath)
         elif os.path.isfile(fullpath):
             util.mkdirChain(os.path.dirname(testpath))
             util.copyfile(fullpath, testpath, verbose=False)
             self.replaceBuildPath(testpath)
             # finally, include any symlinks that point
             # to the file we just copied
             if path in self.builddirlinks:
                 for linkpath in self.builddirlinks[path]:
                     linkpath = '%(destdir)s%(thistestdir)s' % self.macros + linkpath
                     if not os.path.islink(linkpath):
                         util.mkdirChain(os.path.dirname(linkpath))
                         os.symlink(self.macros.thistestdir + path,
                                    linkpath)
Example #7
0
    def convertSplash(self, topdir, tmpPath):
        # convert syslinux-splash.png to splash.lss, if exists
        if os.path.exists(tmpPath + '/pixmaps/syslinux-splash.png'):
            log.info("found syslinux-splash.png, converting to splash.lss")

            splash = file(tmpPath + '/pixmaps/splash.lss', 'w')
            palette = [] # '#000000=0', '#cdcfd5=7', '#c90000=2', '#ffffff=15', '#5b6c93=9']
            pngtopnm = subprocess.Popen(['pngtopnm', tmpPath + '/pixmaps/syslinux-splash.png'], stdout = subprocess.PIPE)
            ppmtolss16 = subprocess.Popen(['ppmtolss16'] + palette, stdin = pngtopnm.stdout, stdout = splash)
            ppmtolss16.communicate()

        # copy the splash.lss files to the appropriate place
        if os.path.exists(tmpPath + '/pixmaps/splash.lss'):
            log.info("found splash.lss; moving to isolinux directory")
            splashTarget = os.path.join(topdir, 'isolinux')
            call('cp', '--remove-destination', tmpPath + '/pixmaps/splash.lss', splashTarget)
            # FIXME: regenerate boot.iso here

        # Locate splash for isolinux vesamenu background.
        for name in ('vesamenu-splash.jpg', 'vesamenu-splash.png'):
            sourcePath = os.path.join(tmpPath, 'pixmaps', name)
            if os.path.exists(sourcePath):
                ext = name.split('.')[-1]
                name = 'splash.%s' % ext
                util.copyfile(sourcePath,
                        os.path.join(topdir, 'isolinux', name))

                # Rewrite isolinux.cfg to point to the background image.
                isolinux = os.path.join(topdir, 'isolinux', 'isolinux.cfg')
                lines = open(isolinux).readlines()
                for n, line in enumerate(lines):
                    if line.startswith('menu background '):
                        lines[n] = 'menu background %s\n' % name
                open(isolinux, 'w').write(''.join(lines))

                break
Example #8
0
def copyfile(source, target):
    if not os.path.exists(target):
        return util.copyfile(source, target)
Example #9
0
 def _RUN_cp(self, inPath, outPath):
     util.copyfile(inPath, outPath)