Example #1
0
    def test_full(self):
        root = self.name.rstrip('0123456789')

        with self.workspace() as w:
            self.assertRun('rock --runtime=%s init' % self.name, cwd=w.path)
            with open(w.join('.rock.yml')) as f:
                self.assertEqual(f.read(), 'runtime: %s\n' % self.name)
            for name in self.init_files:
                self.assertTrue(os.path.isfile(w.join(name)), 'found file %s' % name)
            for name in self.init_directories:
                p = w.join(name)
                self.assertTrue(os.path.isdir(p), 'found directory %s' % name)
                ops.run('rmdir ${path}', path=p)
            ops.run('cp -r ${src_path}/* ${dst_path}',
                src_path=self.project_path(), dst_path=w.path)
            for command in ('build', 'test', 'clean'):
                r = self.assertRun('rock %s --help' % command, cwd=w.path)
                match = 'Usage: rock %s' % command
                self.assertEqual(r.stdout.split('\n')[0].strip()[0:len(match)], match)
            self.assertRun('rock build', cwd=w.path)
            result = self.assertRun('rock run sample test', cwd=w.path)
            self.assertEquals(result.stdout.rstrip(), '<p>test</p>')
            self.assertRun('rock test', cwd=w.path)
            if self.create_lock:
                self.assertRun(self.create_lock, cwd=w.path)
            self.assertRun('rock clean', cwd=w.path)
            self.assertNotRun('rock test', cwd=w.path)
            self.assertRun('rock build --deployment', cwd=w.path)
            self.assertRun('rock test', cwd=w.path)
Example #2
0
File: brpm.py Project: silas/brpm
 def sources(self):
     if self.rpm_spec:
         for src, _, _ in self.rpm_spec.sources:
             name = None
             for value in ("http://", "https://", "ftp://"):
                 if src.startswith(value):
                     dst = os.path.join(self.root_path, src.split("/")[-1])
                     if not os.path.exists(dst):
                         log.info("Retrieving source %s" % src)
                         ops.run("curl -sL ${src} > ${dst}", src=src, dst=dst, **self.ops_run)
Example #3
0
File: brpm.py Project: silas/brpm
    def run(self):
        if os.path.exists(self.build_path):
            ops.rm(self.build_path, recursive=True)
        ops.mkdir(self.build_path)

        # Build repository directories
        for arch in ["SRPMS"] + self.options.arch:
            path = os.path.join(self.repo_path, "build", self.dist_name, self.dist_version, arch)
            ops.mkdir(path)
            if not os.path.exists(os.path.join(path, "repodata")):
                ops.run("createrepo --update ${dst}", dst=path, **self.ops_run)

        # Try to get source files if they don't exist locally
        self.sources()

        # Build SRPM
        result = self.srpm()
        if result:
            self.srpm_path = result.stdout.strip()[7:]
        else:
            ops.exit(code=result.code)

        srpm_dst_path = os.path.join(self.repo_path, "build", self.dist_name, self.dist_version, "SRPMS")

        # Build RPMs
        for arch in self.options.arch:
            result = self.rpm(arch)
            if not result:
                ops.exit(code=result.code, text=result.stderr)
            arch_dst_path = os.path.join(self.repo_path, "build", self.dist_name, self.dist_version, arch)
            ops.mkdir(arch_dst_path)
            # TODO(silas):  don't build multiple times on noarch
            ops.run("mv ${src}/*.noarch.rpm ${dst}", src=self.build_path, dst=arch_dst_path, **self.ops_run)
            arch_list = [arch]
            if arch == "i386":
                arch_list.append("i686")
            for a in arch_list:
                ops.run("mv ${src}/*${arch}.rpm ${dst}", src=self.build_path, arch=a, dst=arch_dst_path, **self.ops_run)
            # Find and move distribution srpm
            srpms = glob.glob(os.path.join(self.build_path, "*.src.rpm"))
            srpms = [os.path.basename(path) for path in srpms]
            srpm_name = os.path.basename(self.srpm_path)
            if srpm_name in srpms:
                srpms.remove(srpm_name)
            srpm_path = os.path.join(self.build_path, srpms[0]) if srpms else self.srpm_path
            ops.run("mv ${src} ${dst}", src=srpm_path, dst=srpm_dst_path, **self.ops_run)
            # Update repository
            ops.run("createrepo --update ${dst}", dst=arch_dst_path, **self.ops_run)
Example #4
0
 def do(self, text='', code=0):
     r = ops.run(
         'python ${run} ${code} ${text}',
         run=self.run_path,
         code=code,
         text=text,
     )
     return r
Example #5
0
File: brpm.py Project: silas/brpm
 def srpm(self):
     command = "rpmbuild"
     if self.options.dist == "epel-5":
         command += ' --define "_source_filedigest_algorithm=1"'
     command += ' --define "_sourcedir ${root_path}"'
     command += ' --define "_specdir ${root_path}"'
     command += ' --define "_srcrpmdir ${build_path}"'
     command += ' -bs --nodeps "${spec_path}"'
     return ops.run(
         command, build_path=self.build_path, spec_path=self.spec_path, root_path=self.root_path, **self.ops_run
     )
Example #6
0
File: brpm.py Project: silas/brpm
 def rpm(self, arch):
     command = "mock -vr ${dist}-${arch}"
     command += " --resultdir=${build_path}"
     command += " ${srpm_path}"
     return ops.run(
         command,
         dist=self.options.dist,
         arch=arch,
         build_path=self.build_path,
         srpm_path=self.srpm_path,
         **self.ops_run
     )
Example #7
0
File: brpm.py Project: silas/brpm
def run():
    import optparse

    release = {"/etc/fedora-release": "fedora", "/etc/redhat-release": "epel"}

    dist = ""
    for path, name in release.items():
        if os.path.isfile(path) and not os.path.islink(path):
            with open(path) as f:
                version = f.read().split()[2].partition(".")[0]
                dist = "%s-%s" % (name, version)
                break

    arch = ops.run("uname -m").stdout.strip()
    if arch != "x86_64":
        arch == "i386"

    usage = "Usage: %prog [options] file..."
    parser = optparse.OptionParser(usage=usage)
    parser.add_option(
        "-d", "--dist", dest="dist", help="distribution" + " (%s)" % dist if dist else "", default=dist, metavar="DIST"
    )
    parser.add_option("-s", "--start", dest="start", help="start building with PACKAGE", metavar="PACKAGE")
    parser.add_option("-o", "--only", dest="only", help="build only PACKAGE", metavar="PACKAGE")
    parser.add_option(
        "-a",
        "--arch",
        dest="arch",
        default=arch,
        help="comma separated list of architectures (%s)" % arch,
        metavar="ARCH",
    )
    options, args = parser.parse_args()

    if not args:
        args = ["."]

    if not options.dist:
        ops.exit(code=1, text="Dist option is required")

    if not options.arch:
        ops.exit(code=1, text="Arch is required")
    else:
        options.arch = [arch.strip() for arch in options.arch.split(",")]
        if "" in options.arch:
            options.arch.remove("")

    build(args, options)
Example #8
0
 def assertNotRun(self, *args, **kwargs):
     kwargs['combine'] = True
     r = ops.run(*args, **kwargs)
     self.assertFalse(r, '\n\n' + r.stdout + '\n\n' + r.stderr)
     return r
Example #9
0
 def test_stdin(self):
     results = ops.run('bash', stdin='echo -n ok')
     self.assertEqual(results.stdout, b'ok')
Example #10
0
 def test_list(self):
     args = ['?!*', '=', '?!*']
     results = ops.run('test ${args}', args=args)
     self.assertTrue(results)
     self.assertEqual(results.code, 0)
Example #11
0
 def test_dict(self):
     args = {'-f': self.run_path}
     results = ops.run('test ${args}', args=args)
     self.assertTrue(results)
     self.assertEqual(results.code, 0)