diff --git a/superflore/generators/bitbake/run.py b/superflore/generators/bitbake/run.py index 8110d67b..5cb81927 100644 --- a/superflore/generators/bitbake/run.py +++ b/superflore/generators/bitbake/run.py @@ -14,6 +14,7 @@ from superflore.generators.bitbake.gen_packages import generate_installers from superflore.generators.bitbake.ros_meta import ros_meta +from superflore import RepoInstance import argparse import shutil import sys @@ -85,20 +86,16 @@ def main(): # clone current repo selected_targets = active_distros - # try: + for x in active_distros: + try: + os.remove('recipes-ros-{0}'.format(x)) + warn_msg =\ + 'removing existing symlink "./recipes-ros-{0}"'.format(x) + RepoInstance.warn(warn_msg) + except: + pass link_existing_files(args.ros_distro) - """ - except FileExistsError: - warn_msg = 'Detected existing rosdistro ebuild structure... ' - warn_msg += 'Removing and overwriting.' - ros_meta.warn(warn_msg) - for x in active_distros: - try: - os.remove('recipes-ros-{0}'.format(x)) - except: - pass - link_existing_files() - """ + # generate installers total_installers = dict() total_broken = set() diff --git a/superflore/generators/ebuild/gen_packages.py b/superflore/generators/ebuild/gen_packages.py index 1dceea5d..fcf4fe62 100644 --- a/superflore/generators/ebuild/gen_packages.py +++ b/superflore/generators/ebuild/gen_packages.py @@ -68,7 +68,6 @@ def get_pkg_version(distro, pkg_name): def generate_installers(distro_name, overlay, preserve_existing=True): - make_dir("ros-{}".format(distro_name)) distro = get_distro(distro_name) pkg_names = get_package_names(distro) total = float(len(pkg_names[0])) @@ -81,9 +80,12 @@ def generate_installers(distro_name, overlay, preserve_existing=True): for i, pkg in enumerate(sorted(pkg_names[0])): version = get_pkg_version(distro, pkg) - ebuild_exists = os.path.exists( - 'ros-{}/{}/{}-{}.ebuild'.format(distro_name, pkg, pkg, version)) - patch_path = 'ros-{}/{}/files'.format(distro_name, pkg) + ebuild_name =\ + '/ros-{0}/{1}/{1}-{2}.ebuild'.format(distro_name, pkg, version) + ebuild_name = overlay.repo.repo_dir + ebuild_name + ebuild_exists = os.path.exists(ebuild_name) + patch_path = '/ros-{}/{}/files'.format(distro_name, pkg) + patch_path = overlay.repo.repo_dir + patch_path has_patches = os.path.exists(patch_path) percent = '%.1f' % (100 * (float(i) / total)) @@ -95,10 +97,17 @@ def generate_installers(distro_name, overlay, preserve_existing=True): succeeded = succeeded + 1 continue # otherwise, remove a (potentially) existing ebuild. - existing = glob.glob('ros-{0}/{1}/*.ebuild'.format(distro_name, pkg)) + existing = glob.glob( + '{0}/ros-{1}/{2}/*.ebuild'.format( + overlay.repo.repo_dir, + distro_name, pkg + ) + ) if existing: overlay.repo.remove_file(existing[0]) - manifest_file = 'ros-{0}/{1}/Manifest'.format(distro_name, pkg) + manifest_file = '{0}/ros-{1}/{2}/Manifest'.format( + overlay.repo.repo_dir, distro_name, pkg + ) overlay.repo.remove_file(manifest_file) try: current = gentoo_installer(distro, pkg, has_patches) @@ -128,21 +137,27 @@ def generate_installers(distro_name, overlay, preserve_existing=True): err("Failed to generate installer for package {}!".format(pkg)) failed = failed + 1 continue # do not generate an incomplete ebuild - make_dir("ros-{}/{}".format(distro_name, pkg)) + make_dir( + "{}/ros-{}/{}".format(overlay.repo.repo_dir, distro_name, pkg) + ) success_msg = 'Successfully generated installer for package' ok('{0}%: {1} \'{2}\'.'.format(percent, success_msg, pkg)) succeeded = succeeded + 1 try: - ebuild_name = '{0}/{1}/{1}-{2}'.format(distro_name, pkg, version) - ebuild_file = open('ros-{0}.ebuild'.format(ebuild_name), "w") - metadata_name = '{0}/{1}/metadata.xml'.format(distro_name, pkg) - metadata_file = open('ros-{0}'.format(metadata_name), "w") - + ebuild_file = '{0}/ros-{1}/{2}/{2}-{3}.ebuild'.format( + overlay.repo.repo_dir, + distro_name, pkg, version + ) + ebuild_file = open(ebuild_file, "w") + metadata_file = '{0}/ros-{1}/{2}/metadata.xml'.format( + overlay.repo.repo_dir, + distro_name, pkg + ) + metadata_file = open(metadata_file, "w") ebuild_file.write(ebuild_text) metadata_file.write(metadata_text) changes.append('*{0} --> {1}*'.format(pkg, version)) - except: err("Failed to write ebuild/metadata to disk!") installers.append(current) diff --git a/superflore/generators/ebuild/overlay_instance.py b/superflore/generators/ebuild/overlay_instance.py index e43e34e7..6a5591c1 100644 --- a/superflore/generators/ebuild/overlay_instance.py +++ b/superflore/generators/ebuild/overlay_instance.py @@ -18,11 +18,19 @@ def get_random_branch_name(): class RosOverlay(object): - def __init__(self): + def __init__(self, repo_dir=None): # clone repo into a random tmp directory. - self.repo = RepoInstance('ros', 'ros-overlay', get_random_tmp_dir()) + do_clone = True + if repo_dir: + do_clone = not os.path.exists(os.path.realpath(repo_dir)) + self.repo = RepoInstance( + 'ros', 'ros-overlay', + repo_dir or get_random_tmp_dir(), + do_clone + ) self.branch_name = get_random_branch_name() - self.repo.clone() + if do_clone: + self.repo.clone() branch_msg = 'Creating new branch {0}...'.format(self.branch_name) self.repo.info(branch_msg) self.repo.create_branch(self.branch_name) diff --git a/superflore/generators/ebuild/run.py b/superflore/generators/ebuild/run.py index 2cb1ed2a..5c38f15f 100755 --- a/superflore/generators/ebuild/run.py +++ b/superflore/generators/ebuild/run.py @@ -30,51 +30,13 @@ overlay = None -def link_existing_files(mode): +def clean_up(distro, preserve_repo=False): global overlay - sym_link_msg = 'Symbolicly linking files from {0}/ros-{1}...' - dir_fmt = '{0}/ros-{1}' - if not mode: - for x in active_distros: - RepoInstance.info(sym_link_msg.format(overlay.repo.repo_dir, x)) - os.symlink(dir_fmt.format(overlay.repo.repo_dir, x), './ros-' + x) - else: - # only link the relevant directory. - RepoInstance.info(sym_link_msg.format(overlay.repo_dir, mode)) - os.symlink( - dir_fmt.format(overlay.repo.repo_dir, mode), - './ros-' + mode - ) - - -def get_existing_repo(): - existing_path = None - for x in active_distros: - curr = './ros-{0}'.format(x) - if os.path.exists(curr): - existing_path = curr - break - if not existing_path: - raise RuntimeError('No existing repo found') - # get the actual location of the repo - repo_dir = os.path.realpath('{0}/../'.format(existing_path)) - # TODO(allenh1): make this configurable - git_repo = RepoInstance('ros', 'ros-overlay', repo_dir, do_clone=False) - return git_repo - - -def clean_up(distro): - global overlay - clean_msg = \ - 'Cleaning up tmp directory {0}...'.format(overlay.repo.repo_dir) - RepoInstance.info(clean_msg) - shutil.rmtree(overlay.repo.repo_dir) - RepoInstance.info('Cleaning up symbolic links...') - if distro in active_distros: - os.remove('ros-{0}'.format(distro)) - else: - for x in active_distros: - os.remove('ros-{0}'.format(x)) + if not preserve_repo: + clean_msg = \ + 'Cleaning up tmp directory {0}...'.format(overlay.repo.repo_dir) + RepoInstance.info(clean_msg) + shutil.rmtree(overlay.repo.repo_dir) if os.path.exists('.pr-message.tmp'): os.remove('.pr-message.tmp') if os.path.exists('.pr-title.tmp'): @@ -115,6 +77,11 @@ def main(): help='ONLY file a PR to remote', action='store_true' ) + parser.add_argument( + '--output-repository-path', + help='location of the Git repo', + type=str + ) args = parser.parse_args(sys.argv[1:]) @@ -127,6 +94,8 @@ def main(): elif args.dry_run and args.pr_only: RepoInstance.error('Invalid args! cannot dry-run and file PR') sys.exit(1) + elif args.pr_only and not args.output_repository_path: + RepoInstance.error('Invalid args! no repository specified') elif args.pr_only: try: with open('.pr-message.tmp', 'r') as msg_file: @@ -143,7 +112,7 @@ def main(): ) sys.exit(1) try: - prev_overlay = get_existing_repo() + prev_overlay = RepoInstance(args.output_repository_path) RepoInstance.info('PR message:\n"%s"\n' % msg) RepoInstance.info('PR title:\n"%s"\n' % title) prev_overlay.pull_request(msg, title) @@ -154,22 +123,8 @@ def main(): RepoInstance.error('reason: {0}'.format(e)) sys.exit(1) # clone current repo - overlay = RosOverlay() + overlay = RosOverlay(args.output_repository_path) selected_targets = active_distros - - try: - link_existing_files(args.ros_distro) - except os.FileExistsError: - warn_msg = 'Detected existing rosdistro ebuild structure... ' - warn_msg += 'Removing and overwriting.' - RepoInstance.warn(warn_msg) - for x in active_distros: - try: - os.remove('ros-{0}'.format(x)) - except: - pass - - link_existing_files(args.ros_distro) # generate installers total_installers = dict() total_broken = set() @@ -246,5 +201,5 @@ def main(): sys.exit(0) file_pr(overlay, delta, missing_deps) - clean_up(args.ros_distro) + clean_up(args.ros_distro, args.output_repository_path) RepoInstance.happy('Successfully synchronized repositories!') diff --git a/superflore/repo_instance.py b/superflore/repo_instance.py index 7dcfdf40..f3b7ce2f 100644 --- a/superflore/repo_instance.py +++ b/superflore/repo_instance.py @@ -24,10 +24,7 @@ def __init__(self, repo_owner, repo_name, repo_dir=None, do_clone=True): self.repo_name = repo_name repo_url = 'https://github.com/{0}/{1}' self.repo_url = repo_url.format(self.repo_owner, self.repo_name) - if repo_dir is not None: - self.repo_dir = repo_dir - else: - self.repo_dir = self.repo_name + self.repo_dir = repo_dir or self.repo_name if do_clone: self.repo = Repo.clone_from(self.repo_url, self.repo_dir) else: