Skip to content

Commit

Permalink
Remove os prefix from consecutive build error. (#51)
Browse files Browse the repository at this point in the history
* Remove os prefix from consecutive build error.

* Added an option to use an existing repository instead of cloning a temporary one.

* Fixing python 2/3 compatibility

* removes sym-link logic
  • Loading branch information
allenh1 authored Aug 11, 2017
1 parent 278d3da commit a2244de
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 94 deletions.
23 changes: 10 additions & 13 deletions superflore/generators/bitbake/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
41 changes: 28 additions & 13 deletions superflore/generators/ebuild/gen_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand All @@ -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))

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 11 additions & 3 deletions superflore/generators/ebuild/overlay_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
77 changes: 16 additions & 61 deletions superflore/generators/ebuild/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down Expand Up @@ -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:])

Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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!')
5 changes: 1 addition & 4 deletions superflore/repo_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a2244de

Please sign in to comment.