Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --dry-run and --pr-only to Open Embedded #131

Merged
merged 9 commits into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 30 additions & 39 deletions superflore/generators/bitbake/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import os
import sys

Expand All @@ -21,61 +20,31 @@
from superflore.generate_installers import generate_installers
from superflore.generators.bitbake.gen_packages import regenerate_installer
from superflore.generators.bitbake.ros_meta import RosMeta
from superflore.parser import get_parser
from superflore.repo_instance import RepoInstance
from superflore.TempfileManager import TempfileManager
from superflore.utils import clean_up
from superflore.utils import err
from superflore.utils import file_pr
from superflore.utils import info
from superflore.utils import load_pr
from superflore.utils import ok
from superflore.utils import save_pr
from superflore.utils import warn

# Modify if a new distro is added
active_distros = ['indigo', 'kinetic', 'lunar']
# just update packages, by default.
mode = 'update'
preserve_existing = True
overlay = None


def main():
global overlay
global preserve_existing

parser = argparse.ArgumentParser('Deploy ROS packages into Yocto Linux')
parser.add_argument(
'--ros-distro',
help='regenerate packages for the specified distro',
type=str
)
parser.add_argument(
'--all',
help='regenerate all packages in all distros',
action="store_true"
)
parser.add_argument(
'--output-repository-path',
help='location of the Git repo',
type=str
)
preserve_existing = True
overlay = None
parser = get_parser('Deploy ROS packages into Yocto Linux')
parser.add_argument(
'--tar-archive-dir',
help='location to store archived packages',
type=str
)
parser.add_argument(
'--only',
nargs='+',
help='generate only the specified packages'
)
parser.add_argument(
'--pr-comment',
help='comment to add to the PR',
type=str
)
parser.add_argument(
'--upstream-repo',
help='location of the upstream repository',
type=str
)
selected_targets = active_distros
args = parser.parse_args(sys.argv[1:])
pr_comment = args.pr_comment
Expand All @@ -86,6 +55,21 @@ def main():
warn('"{0}" distro detected...'.format(args.ros_distro))
selected_targets = [args.ros_distro]
preserve_existing = False
elif args.dry_run and args.pr_only:
parser.error('Invalid args! cannot dry-run and file PR')
elif args.pr_only and not args.output_repository_path:
parser.error('Invalid args! no repository specified')
elif args.pr_only:
try:
prev_overlay = RepoInstance(args.output_repository_path, False)
msg, title = load_pr()
prev_overlay.pull_request(msg, title)
clean_up()
sys.exit(0)
except Exception as e:
err('Failed to file PR!')
err('reason: {0}'.format(e))
sys.exit(1)
repo_org = 'allenh1'
repo_name = 'meta-ros'
if args.upstream_repo:
Expand Down Expand Up @@ -159,6 +143,9 @@ def main():
regen_dict = dict()
regen_dict[args.ros_distro] = args.only
overlay.commit_changes(args.ros_distro)
if args.dry_run:
save_pr(overlay, args.only, pr_comment)
sys.exit(0)
delta = "Regenerated: '%s'\n" % args.only
file_pr(overlay, delta, '', pr_comment, distro=args.ros_distro)
ok('Successfully synchronized repositories!')
Expand Down Expand Up @@ -230,5 +217,9 @@ def main():

# Commit changes and file pull request
overlay.commit_changes(args.ros_distro)
if args.dry_run:
info('Running in dry mode, not filing PR')
save_pr(overlay, delta, missing_deps, pr_comment)
sys.exit(0)
file_pr(overlay, delta, missing_deps, pr_comment)
ok('Successfully synchronized repositories!')
96 changes: 12 additions & 84 deletions superflore/generators/ebuild/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,82 +13,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import os
import sys
import time

from rosinstall_generator.distro import get_distro
from superflore.generate_installers import generate_installers
from superflore.generators.ebuild.gen_packages import regenerate_pkg
from superflore.generators.ebuild.overlay_instance import RosOverlay
from superflore.parser import get_parser
from superflore.repo_instance import RepoInstance
from superflore.TempfileManager import TempfileManager
from superflore.utils import clean_up
from superflore.utils import err
from superflore.utils import file_pr
from superflore.utils import info
from superflore.utils import load_pr
from superflore.utils import ok
from superflore.utils import save_pr
from superflore.utils import warn

# Modify if a new distro is added
active_distros = ['indigo', 'kinetic', 'lunar']
# just update packages, by default.
preserve_existing = True
overlay = None


def clean_up():
if os.path.exists('.pr-message.tmp'):
os.remove('.pr-message.tmp')
if os.path.exists('.pr-title.tmp'):
os.remove('.pr-title.tmp')


def main():
global overlay
global preserve_existing

parser = argparse.ArgumentParser('Deploy ROS packages into Gentoo Linux')
parser.add_argument(
'--ros-distro',
help='regenerate packages for the specified distro',
type=str
)
parser.add_argument(
'--all',
help='regenerate all packages in all distros',
action="store_true"
)
parser.add_argument(
'--dry-run',
help='run without filing a PR to remote',
action="store_true"
)
parser.add_argument(
'--pr-only',
help='ONLY file a PR to remote',
action='store_true'
)
parser.add_argument(
'--output-repository-path',
help='location of the Git repo',
type=str
)
parser.add_argument(
'--only',
nargs='+',
help='generate only the specified packages'
)
parser.add_argument(
'--pr-comment',
help='comment to add to the PR',
type=str
)
parser.add_argument(
'--upstream-repo',
help='location of the upstream repository',
type=str
)
overlay = None
preserve_existing = True
parser = get_parser('Deploy ROS packages into Gentoo Linux')
args = parser.parse_args(sys.argv[1:])
pr_comment = args.pr_comment
selected_targets = None
Expand All @@ -103,24 +54,9 @@ def main():
elif args.pr_only and not args.output_repository_path:
parser.error('Invalid args! no repository specified')
elif args.pr_only:
try:
with open('.pr-message.tmp', 'r') as msg_file:
msg = msg_file.read().rstrip('\n')
with open('.pr-title.tmp', 'r') as title_file:
title = title_file.read().rstrip('\n')
except OSError:
err('Failed to open PR title/message file!')
err(
'Please supply the %s and %s files' % (
'.pr_message.tmp',
'.pr_title.tmp'
)
)
raise
try:
prev_overlay = RepoInstance(args.output_repository_path, False)
info('PR message:\n"%s"\n' % msg)
info('PR title:\n"%s"\n' % title)
msg, title = load_pr()
prev_overlay.pull_request(msg, title)
clean_up()
sys.exit(0)
Expand Down Expand Up @@ -194,15 +130,10 @@ def main():
overlay.regenerate_manifests(regen_dict)
overlay.commit_changes(args.ros_distro)
if args.dry_run:
# TODO(allenh1): update this PR style.
info('Running in dry mode, not filing PR')
title_file = open('.pr-title.tmp', 'w')
title_file.write('rosdistro sync, {0}\n'.format(time.ctime()))
pr_message_file = open('.pr-message.tmp', 'w')
pr_message_file.write('%s\n%s\n' % (pr_comment, ''))
save_pr(overlay, args.only, pr_comment)
sys.exit(0)
file_pr(overlay, '', '', pr_comment)
clean_up()
delta = "Regenerated: '%s'\n" % args.only
file_pr(overlay, delta, '', pr_comment)
ok('Successfully synchronized repositories!')
sys.exit(0)

Expand Down Expand Up @@ -275,10 +206,7 @@ def main():

if args.dry_run:
info('Running in dry mode, not filing PR')
title_file = open('.pr-title.tmp', 'w')
title_file.write('rosdistro sync, {0}\n'.format(time.ctime()))
pr_message_file = open('.pr-message.tmp', 'w')
pr_message_file.write('%s\n%s\n' % (delta, missing_deps))
save_pr(overlay, delta, missing_deps, pr_comment)
sys.exit(0)
file_pr(overlay, delta, missing_deps, pr_comment)

Expand Down
62 changes: 62 additions & 0 deletions superflore/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2018 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse


# set up a parser and return it
def get_parser(tool_tip, is_generator=True):
parser = argparse.ArgumentParser(tool_tip)
if is_generator:
parser.add_argument(
'--ros-distro',
help='regenerate packages for the specified distro',
type=str
)
parser.add_argument(
'--all',
help='regenerate all packages in all distros',
action="store_true"
)
parser.add_argument(
'--dry-run',
help='run without filing a PR to remote',
action="store_true"
)
parser.add_argument(
'--pr-only',
help='ONLY file a PR to remote',
action='store_true'
)
parser.add_argument(
'--output-repository-path',
help='location of the Git repo',
type=str
)
parser.add_argument(
'--only',
nargs='+',
help='generate only the specified packages'
)
parser.add_argument(
'--pr-comment',
help='comment to add to the PR',
type=str
)
parser.add_argument(
'--upstream-repo',
help='location of the upstream repository',
type=str
)
return parser
40 changes: 39 additions & 1 deletion superflore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import re
import string
import sys
import time

from superflore.exceptions import UnknownLicense
from superflore.exceptions import UnknownPlatform
Expand All @@ -41,15 +42,45 @@ def info(string): # pragma: no cover
print(colored('>>>> {0}'.format(string), 'cyan'))


def file_pr(overlay, delta, missing_deps, comment, distro=None):
def get_pr_text(comment=None):
msg = ''
if comment:
msg += '%s\n' % comment
msg += 'To reproduce this PR, run the following command.\n\n'
args = sys.argv
args[0] = args[0].split('/')[-1]
msg += '```\n%s\n```' % ' '.join(args)


def save_pr(overlay, delta, missing_deps, comment):
with open('.pr-title.tmp', 'w') as title_file:
title_file.write('rosdistro sync, {0}\n'.format(time.ctime()))
with open('.pr-message.tmp', 'w') as pr_msg_file:
pr_msg_file.write('%s\n' % get_pr_text(comment))


def load_pr():
try:
with open('.pr-message.tmp', 'r') as msg_file:
msg = msg_file.read().rstrip('\n')
with open('.pr-title.tmp', 'r') as title_file:
title = title_file.read().rstrip('\n')
except OSError:
err('Failed to open PR title/message file!')
err(
'Please supply the %s and %s files' % (
'.pr_message.tmp',
'.pr_title.tmp'
)
)
raise
return msg, title
clean_up()


def file_pr(overlay, delta, missing_deps, comment, distro=None):
try:
msg = get_pr_text(comment)
overlay.pull_request('%s\n%s\n%s' % (msg, delta, missing_deps), distro)
except Exception as e:
err(
Expand All @@ -62,6 +93,13 @@ def file_pr(overlay, delta, missing_deps, comment, distro=None):
sys.exit(1)


def clean_up():
if os.path.exists('.pr-message.tmp'):
os.remove('.pr-message.tmp')
if os.path.exists('.pr-title.tmp'):
os.remove('.pr-title.tmp')


def make_dir(dirname):
try:
os.makedirs(dirname)
Expand Down