Skip to content

Commit

Permalink
Reuse rosdistro functionality to get a distribution cache string
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-rosa committed Apr 2, 2019
1 parent 2692141 commit d5d1917
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions superflore/generators/bitbake/yocto_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,37 +424,11 @@ def generate_distro_cache(basepath, distro, skip_keys=[]):
distro_cache_file_path = '{0}{1}-cache.yaml'.format(
distro_cache_path, distro)
try:
make_dir(distro_cache_path)
from rosdistro import get_index, get_index_url, _get_dist_file_data
import gzip
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
try:
from cStringIO import StringIO
except ImportError:
from io import BytesIO as StringIO
from rosdistro import get_index, get_index_url, get_distribution_cache_string
index_url = get_index_url()
index = get_index(index_url)
dist = index.distributions.get(distro, None)
if not dist:
raise RuntimeError(
'Unknown distribution {0} when looking at {1}'.format(distro, index_url))
cache_url = dist.get('distribution_cache', None)
if not cache_url:
raise RuntimeError(
'Distribution {0} has no cache'.format(distro))
raw_data = urlopen(cache_url, timeout=10).read()
if cache_url.endswith('.yaml.gz'):
yaml_gz_stream = StringIO(raw_data)
f = gzip.GzipFile(fileobj=yaml_gz_stream, mode='rb')
yaml_str = f.read()
f.close()
if not isinstance(yaml_str, str):
yaml_str = yaml_str.decode('utf-8')
else:
yaml_str = raw_data.decode('utf-8')
yaml_str = get_distribution_cache_string(index, distro)
make_dir(distro_cache_path)
with open(distro_cache_file_path, "w") as distro_cache_file:
distro_cache_file.write(yaml_str)
ok('Wrote {0}'.format(distro_cache_file_path))
Expand Down

0 comments on commit d5d1917

Please sign in to comment.