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 an error message for unknown ROS distributions. #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion prerelease_website/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .ajax import get_package_list_for_remote_repo_ajax
from .ajax import get_rdepends_by_level_and_excludes_ajax
from .ajax import get_repo_list_ajax
from .ajax import check_distro_ajax

app = Flask(__name__)

Expand All @@ -18,7 +19,10 @@ def index():

@app.route('/<distro>')
def distro(distro):
return render_template('generate_command.html', distro=distro)
if check_distro_ajax(distro):
return render_template('generate_command.html', distro=distro)
else:
return render_template('404.html', distro=distro), 404


@app.route('/get_repo_list/<distro>')
Expand Down
27 changes: 18 additions & 9 deletions prerelease_website/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import vcstools
import yaml

from .models import DryRosDistro
from .models import WetRosDistro

logger = logging.getLogger('prerelease')
Expand All @@ -36,17 +35,27 @@ def __exit__(self, exc_type, exc_value, traceback):
os.chdir(self.original_cwd)


def check_distro_ajax(ros_distro):
try:
wet_distro = WetRosDistro(ros_distro)
return True
except Exception as e:
return False


def get_repo_list_ajax(ros_distro):
dry_distro = DryRosDistro(ros_distro)
repo_list = dry_distro.get_info()
logger.info("Got dry repo list")
try:
wet_distro = WetRosDistro(ros_distro)
except Exception as e:
return json.dumps({
'status': 500,
'message': str(e),
})

wet_distro = WetRosDistro(ros_distro)
repo_list = {}
for name, d in wet_distro.get_info().items():
if name in repo_list:
logger.info("%s is in both wet and dry rosdistro!!!!" % name)
else:
repo_list[name] = d
repo_list[name] = d

logger.info("Got wet repo list")

return json.dumps({
Expand Down
30 changes: 2 additions & 28 deletions prerelease_website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,6 @@
logger = logging.getLogger('prerelease')


class DryRosDistro(object):
def __init__(self, distro):
self.distro = distro
if distro == 'groovy':
self.distro_obj = rospkg.distro.load_distro(rospkg.distro.distro_uri(distro))
else:
self.distro_obj = None

def get_info(self):
res = {}
if not self.distro_obj:
return res
for name, s in self.distro_obj.stacks.iteritems():
if s.vcs_config.type == 'svn':
url = s.vcs_config.anon_dev
branch = ""
else:
url = s.vcs_config.repo_uri
branch = s.vcs_config.dev_branch
res[name] = {'distro': self.distro + "_dry",
'version': ["devel"],
'url': [url],
'branch': [branch]}
return res


def has_release(repo):
return getattr(repo, 'release_repository', None) is not None

Expand All @@ -49,8 +23,8 @@ def __init__(self, distro):
index = get_index(get_index_url())
self._distribution_file = get_distribution_cache(index, distro).distribution_file
except:
logger.error("Could not load rosdistro distribution cache")
self._distribution_file = None
logger.error("Could not load rosdistro distribution cache for '%s'" % (distro))
raise

def get_release_platforms(self):
return self._distribution_file.release_platforms
Expand Down
7 changes: 7 additions & 0 deletions prerelease_website/templates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "base.html" %}
{% block title %}Page Not Found{% endblock %}
{% block content %}
<h1>Page Not Found</h1>
<p>Unknown ROS distribution '{{ distro }}'.
<p><a href="{{ url_for('index') }}">Back to the main page</a>
{% endblock %}