예제 #1
0
 def pull_request(self, message, title, branch='master', remote='origin'):
     info('Forking repository if a fork does not exist...')
     self.github = Github(os.environ['SUPERFLORE_GITHUB_TOKEN'])
     self.gh_user = self.github.get_user()
     self.gh_upstream = self.github.get_repo(
         '%s/%s' % (self.repo_owner, self.repo_name))
     # TODO(allenh1): Don't fork if you're authorized for repo
     forked_repo = self.gh_user.create_fork(self.gh_upstream)
     info('Pushing changes to fork...')
     self.git.remote('add', 'github', forked_repo.html_url)
     retry_on_exception(
         self.git.push,
         '-u',
         'github',
         self.branch or branch,
         retry_msg='Could not push',
         error_msg='Error during push',
         sleep_secs=0.0,
     )
     info('Filing pull-request...')
     pr_head = '%s:%s' % (self.gh_user.login, self.branch)
     pr = self.gh_upstream.create_pull(title=title,
                                       body=message,
                                       base=self.from_branch or branch,
                                       head=pr_head)
     ok('Successfully filed a pull request.')
     ok('  %s' % pr.html_url)
예제 #2
0
def _gen_recipe_for_package(distro, pkg_name, pkg, repo, ros_pkg,
                            pkg_rosinstall, tar_dir, md5_cache, sha256_cache,
                            patches, incs):
    pkg_dep_walker = DependencyWalker(distro)
    pkg_buildtool_deps = pkg_dep_walker.get_depends(pkg_name, "buildtool")
    pkg_build_deps = pkg_dep_walker.get_depends(pkg_name, "build")
    pkg_run_deps = pkg_dep_walker.get_depends(pkg_name, "run")
    src_uri = pkg_rosinstall[0]['tar']['uri']

    pkg_recipe = yoctoRecipe(pkg_name, distro, src_uri, tar_dir, md5_cache,
                             sha256_cache, patches, incs)
    # add run dependencies
    for rdep in pkg_run_deps:
        pkg_recipe.add_depend(rdep)

    # add build dependencies
    for bdep in pkg_build_deps:
        pkg_recipe.add_depend(bdep)

    # add build tool dependencies
    for tdep in pkg_buildtool_deps:
        pkg_recipe.add_depend(tdep)

    # parse throught package xml
    error_msg = 'Failed to fetch metadata for package {}'.format(pkg_name)
    pkg_xml = retry_on_exception(ros_pkg.get_package_xml,
                                 distro.name,
                                 retry_msg='Could not get package xml!',
                                 error_msg=error_msg)
    pkg_fields = PackageMetadata(pkg_xml)
    pkg_recipe.pkg_xml = pkg_xml
    pkg_recipe.license = pkg_fields.upstream_license
    pkg_recipe.description = pkg_fields.description
    pkg_recipe.homepage = pkg_fields.homepage
    return pkg_recipe
예제 #3
0
def _gen_recipe_for_package(distro, pkg_name, pkg, repo, ros_pkg,
                            pkg_rosinstall, tar_dir, md5_cache, sha256_cache,
                            skip_keys):
    pkg_names = get_package_names(distro)
    pkg_dep_walker = DependencyWalker(distro,
                                      evaluate_condition_context=os.environ)
    pkg_buildtool_deps = pkg_dep_walker.get_depends(pkg_name, "buildtool")
    pkg_build_deps = pkg_dep_walker.get_depends(pkg_name, "build")
    pkg_build_export_deps = pkg_dep_walker.get_depends(pkg_name,
                                                       "build_export")
    pkg_buildtool_export_deps = pkg_dep_walker.get_depends(
        pkg_name, "buildtool_export")
    pkg_exec_deps = pkg_dep_walker.get_depends(pkg_name, "exec")
    pkg_test_deps = pkg_dep_walker.get_depends(pkg_name, "test")
    src_uri = pkg_rosinstall[0]['tar']['uri']

    # parse through package xml
    err_msg = 'Failed to fetch metadata for package {}'.format(pkg_name)
    pkg_xml = retry_on_exception(ros_pkg.get_package_xml,
                                 distro.name,
                                 retry_msg='Could not get package xml!',
                                 error_msg=err_msg)

    pkg_recipe = yoctoRecipe(
        pkg.repository_name,
        len(ros_pkg.repository.package_names),
        pkg_name,
        pkg_xml,
        distro,
        src_uri,
        tar_dir,
        md5_cache,
        sha256_cache,
        skip_keys,
    )
    # add build dependencies
    for bdep in pkg_build_deps:
        pkg_recipe.add_build_depend(bdep, bdep in pkg_names[0])

    # add build tool dependencies
    for btdep in pkg_buildtool_deps:
        pkg_recipe.add_buildtool_depend(btdep, btdep in pkg_names[0])

    # add export dependencies
    for edep in pkg_build_export_deps:
        pkg_recipe.add_export_depend(edep, edep in pkg_names[0])

    # add buildtool export dependencies
    for btedep in pkg_buildtool_export_deps:
        pkg_recipe.add_buildtool_export_depend(btedep, btedep in pkg_names[0])

    # add exec dependencies
    for xdep in pkg_exec_deps:
        pkg_recipe.add_run_depend(xdep, xdep in pkg_names[0])

    # add test dependencies
    for tdep in pkg_test_deps:
        pkg_recipe.add_test_depend(tdep, tdep in pkg_names[0])

    return pkg_recipe
예제 #4
0
def _gen_pkgbuild_for_package(
    distro, pkg_name, pkg, repo, ros_pkg, pkg_rosinstall
):
    pkg_pkgbuild = PkgBuild()

    pkg_pkgbuild.distro = distro.name
    pkg_pkgbuild.src_uri = pkg_rosinstall[0]['tar']['uri']
    pkg_names = get_package_names(distro)
    pkg_dep_walker = DependencyWalker(distro)

    pkg_buildtool_deps = pkg_dep_walker.get_depends(pkg_name, "buildtool")
    pkg_build_deps = pkg_dep_walker.get_depends(pkg_name, "build")
    pkg_run_deps = pkg_dep_walker.get_depends(pkg_name, "run")
    pkg_test_deps = pkg_dep_walker.get_depends(pkg_name, "test")

    pkg_keywords = ['x86', 'amd64', 'arm', 'arm64']

    # add run dependencies
    for rdep in pkg_run_deps:
        pkg_pkgbuild.add_run_depend(rdep, rdep in pkg_names[0])

    # add build dependencies
    for bdep in pkg_build_deps:
        pkg_pkgbuild.add_build_depend(bdep, bdep in pkg_names[0])

    # add build tool dependencies
    for tdep in pkg_buildtool_deps:
        pkg_pkgbuild.add_build_depend(tdep, tdep in pkg_names[0])

    # add test dependencies
    for test_dep in pkg_test_deps:
        pkg_pkgbuild.add_test_depend(test_dep, test_dep in pkg_names[0])

    # add keywords
    for key in pkg_keywords:
        pkg_pkgbuild.add_keyword(key)

    # parse through package xml
    try:
        pkg_xml = retry_on_exception(ros_pkg.get_package_xml, distro.name)
    except Exception:
        warn("fetch metadata for package {}".format(pkg_name))
        return pkg_pkgbuild
    pkg = PackageMetadata(pkg_xml)
    pkg_pkgbuild.upstream_license = pkg.upstream_license
    pkg_pkgbuild.description = pkg.description
    pkg_pkgbuild.homepage = pkg.homepage
    pkg_pkgbuild.build_type = pkg.build_type
    return pkg_pkgbuild
예제 #5
0
def _gen_metadata_for_package(distro, pkg_name, pkg, repo, ros_pkg,
                              pkg_rosinstall):
    pkg_metadata_xml = metadata_xml()
    try:
        pkg_xml = retry_on_exception(ros_pkg.get_package_xml, distro.name)
    except Exception:
        warn("fetch metadata for package {}".format(pkg_name))
        return pkg_metadata_xml
    pkg = PackageMetadata(pkg_xml)
    pkg_metadata_xml.upstream_email = pkg.upstream_email
    pkg_metadata_xml.upstream_name = pkg.upstream_name
    pkg_metadata_xml.longdescription = pkg.longdescription
    pkg_metadata_xml.upstream_bug_url =\
        repo.url.replace("-release", "").replace(".git", "/issues")
    return pkg_metadata_xml
예제 #6
0
    def test_retry_on_exception(self):
        """Test retry on exception"""
        def callback_basic(must_be_one):
            if must_be_one == 1:
                return 'Success'
            raise Exception('Failure')

        def callback_params(must_be_three, must_be_four):
            if must_be_three == 3 and must_be_four == 4:
                return 'Success'
            return None

        def callback_retries(expected_num_retries):
            if callback_retries.limit >= expected_num_retries:
                return callback_retries.limit
            callback_retries.limit += 1
            raise Exception('Failure')
        # Checks success case
        self.assertEqual(retry_on_exception(callback_basic, 1), 'Success')
        # Checks failure case
        with self.assertRaises(Exception):
            retry_on_exception(callback_basic, 2)
        # Checks callback can receive multiple params
        self.assertEqual(retry_on_exception(callback_params, 3, 4), 'Success')
        # Checks it doesn't retry when max_retries is zero; runs just once
        callback_retries.limit = -1
        with self.assertRaises(Exception):
            retry_on_exception(callback_retries, 0, max_retries=0)
        self.assertEqual(callback_retries.limit, 0)
        # Checks it doesn't retry when max_retries is negative; runs just once
        callback_retries.limit = -1
        with self.assertRaises(Exception):
            retry_on_exception(callback_retries, 0, max_retries=-1)
        self.assertEqual(callback_retries.limit, 0)
        # Checks it gets retried 2 times before succeeding at the 3rd
        callback_retries.limit = 0
        self.assertEqual(retry_on_exception(
            callback_retries, 3, max_retries=3), 3)
        # Checks it gets retried 3 times before giving up fully
        callback_retries.limit = -1
        with self.assertRaises(Exception):
            retry_on_exception(callback_retries, 4, max_retries=3)
        self.assertEqual(callback_retries.limit, 3)
        # Check that when retrying 9 times it'll sleep at least 16 seconds
        # 0 + 0.125 + 0.25 + 0.5 + 1 + 2 + 4 + 8 + 0.125 = 16 seconds
        time_before = time.time()
        with self.assertRaises(Exception):
            retry_on_exception(callback_basic, 2, max_retries=9)
        elapsed_time = time.time()-time_before
        self.assertAlmostEqual(elapsed_time, 16, places=0)