Skip to content

Commit

Permalink
Rework database template downloading.
Browse files Browse the repository at this point in the history
 - Only use latest strategy introduced in 053be7e if we have just downloaded the latet verion of Galaxy.
 - Otherwise, look at Galaxy's migrations and pick the newest download that planemo is sure will work.

This fixes planemo for stable versions of Galaxy (and a little older) but the long term solution going forward is to move this functionality into Galaxy (since Galaxy should know pretty clearly what version of the database it is on).
  • Loading branch information
jmchilton committed Feb 13, 2015
1 parent ac4f828 commit dff4f33
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions planemo/galaxy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@

DOWNLOADS_URL = ("https://raw.githubusercontent.com/"
"jmchilton/galaxy-downloads/master/")
DOWNLOADABLE_MIGRATION_VERSIONS = [127, 120, 117]
LATEST_URL = DOWNLOADS_URL + "latest.sqlite"

FAILED_TO_FIND_GALAXY_EXCEPTION = (
Expand Down Expand Up @@ -106,7 +107,9 @@ def config_join(*args):
created_config_directory = True
config_directory = mkdtemp()
try:
latest_galaxy = False
if __install_galaxy_if_needed(config_directory, kwds):
latest_galaxy = True
galaxy_root = config_join("galaxy-central-master")

__handle_dependency_resolution(config_directory, kwds)
Expand All @@ -118,9 +121,13 @@ def config_join(*args):
preseeded_database = True

try:
template_url = DOWNLOADS_URL + urllib.urlopen(LATEST_URL).read()
urlretrieve(template_url, database_location)
except Exception:
_download_database_template(
galaxy_root,
database_location,
latest=latest_galaxy
)
except Exception as e:
print e
# No network access - just roll forward from null.
preseeded_database = False

Expand Down Expand Up @@ -200,6 +207,41 @@ def config_join(*args):
shutil.rmtree(config_directory)


def _download_database_template(galaxy_root, database_location, latest=False):
if latest:
template_url = DOWNLOADS_URL + urllib.urlopen(LATEST_URL).read()
urlretrieve(template_url, database_location)
return True

newest_migration = _newest_migration_version(galaxy_root)
download_migration = None
for migration in DOWNLOADABLE_MIGRATION_VERSIONS:
if newest_migration > migration:
download_migration = migration
break

if download_migration:
download_name = "db_gx_rev_0%d.sqlite" % download_migration
download_url = DOWNLOADS_URL + download_name
urlretrieve(download_url, database_location)
return True
else:
return False


def _newest_migration_version(galaxy_root):
versions = os.path.join(galaxy_root, "lib/galaxy/model/migrate/versions")
version = max(map(_file_name_to_migration_version, os.listdir(versions)))
return version


def _file_name_to_migration_version(name):
try:
return int(name[0:4])
except ValueError:
return -1


def __find_galaxy_root(ctx, **kwds):
galaxy_root = kwds.get("galaxy_root", None)
if galaxy_root:
Expand Down

0 comments on commit dff4f33

Please sign in to comment.