1313from galaxy .containers .docker_model import DockerVolume
1414from galaxy .tools .deps import docker_util
1515from galaxy .tools .deps .commands import argv_to_str
16- from galaxy .util import unicodify
1716from six import (
1817 add_metaclass ,
1918 iteritems
2019)
21- from six .moves .urllib .request import urlopen
22- from six .moves .urllib .request import urlretrieve
2320
2421from planemo import git
2522from planemo .config import OptionSource
@@ -189,7 +186,15 @@ class = StreamHandler
189186DOWNLOADS_URL = ("https://raw.githubusercontent.com/"
190187 "jmchilton/galaxy-downloads/master/" )
191188DOWNLOADABLE_MIGRATION_VERSIONS = [141 , 127 , 120 , 117 ]
192- LATEST_URL = DOWNLOADS_URL + "latest.sqlite"
189+ MIGRATION_PER_VERSION = {
190+ "master" : 141 ,
191+ "18.05" : 141 ,
192+ "18.01" : 140 ,
193+ "17.09" : 135 ,
194+ "17.05" : 134 ,
195+ "17.01" : 133 ,
196+ }
197+ OLDEST_SUPPORTED_VERSION = 127
193198
194199DATABASE_LOCATION_TEMPLATE = "sqlite:///%s?isolation_level=IMMEDIATE"
195200
@@ -345,14 +350,12 @@ def local_galaxy_config(ctx, runnables, for_tests=False, **kwds):
345350 def config_join (* args ):
346351 return os .path .join (config_directory , * args )
347352
348- latest_galaxy = False
349353 install_env = {
350354 'GALAXY_SKIP_CLIENT_BUILD' : '1' ,
351355 }
352356 if install_galaxy :
353357 _build_eggs_cache (ctx , install_env , kwds )
354358 _install_galaxy (ctx , config_directory , install_env , kwds )
355- latest_galaxy = True
356359 galaxy_root = config_join ("galaxy-dev" )
357360
358361 server_name = "planemo%d" % random .randint (0 , 100000 )
@@ -388,9 +391,9 @@ def config_join(*args):
388391 master_api_key = _get_master_api_key (kwds )
389392 dependency_dir = os .path .join (config_directory , "deps" )
390393 preseeded_database = attempt_database_preseed (
394+ ctx ,
391395 galaxy_root ,
392396 database_location ,
393- latest_galaxy = latest_galaxy ,
394397 ** kwds
395398 )
396399 _ensure_directory (shed_tool_path )
@@ -982,7 +985,7 @@ def _database_connection(database_location, **kwds):
982985
983986
984987def attempt_database_preseed (
985- effective_galaxy_root , database_location , latest_galaxy = False , ** kwds
988+ ctx , effective_galaxy_root , database_location , ** kwds
986989):
987990 """If database location is unset, attempt to seed the database."""
988991 if os .path .exists (database_location ):
@@ -995,12 +998,14 @@ def attempt_database_preseed(
995998
996999 preseeded_database = True
9971000 galaxy_sqlite_database = kwds .get ("galaxy_database_seed" , None )
1001+ galaxy_branch = kwds .get ("galaxy_branch" , None )
9981002 try :
9991003 _download_database_template (
1004+ ctx ,
10001005 effective_galaxy_root ,
10011006 database_location ,
1002- latest = latest_galaxy ,
10031007 galaxy_sqlite_database = galaxy_sqlite_database ,
1008+ galaxy_branch = galaxy_branch
10041009 )
10051010 except Exception as e :
10061011 print (e )
@@ -1010,40 +1015,43 @@ def attempt_database_preseed(
10101015
10111016
10121017def _download_database_template (
1018+ ctx ,
10131019 galaxy_root ,
10141020 database_location ,
1015- latest = False ,
1016- galaxy_sqlite_database = None
1021+ galaxy_sqlite_database = None ,
1022+ galaxy_branch = None ,
10171023):
1024+
10181025 if galaxy_sqlite_database is not None :
10191026 shutil .copyfile (galaxy_sqlite_database , database_location )
10201027 return True
10211028
1022- if latest or not galaxy_root :
1023- symlink_target = unicodify (urlopen (LATEST_URL ).read ())
1024- template_url = DOWNLOADS_URL + symlink_target
1025- urlretrieve (template_url , database_location )
1026- return True
1027-
1028- newest_migration = _newest_migration_version (galaxy_root )
10291029 download_migration = None
1030+ newest_migration = _newest_migration_version (galaxy_root , galaxy_branch )
10301031 for migration in DOWNLOADABLE_MIGRATION_VERSIONS :
1031- if newest_migration > migration :
1032+ if newest_migration >= migration :
10321033 download_migration = migration
10331034 break
10341035
10351036 if download_migration :
10361037 download_name = "db_gx_rev_0%d.sqlite" % download_migration
10371038 download_url = DOWNLOADS_URL + download_name
1038- urlretrieve (download_url , database_location )
1039+ ctx . cache_download (download_url , database_location )
10391040 return True
10401041 else :
10411042 return False
10421043
10431044
1044- def _newest_migration_version (galaxy_root ):
1045- versions = os .path .join (galaxy_root , "lib/galaxy/model/migrate/versions" )
1046- version = max (map (_file_name_to_migration_version , os .listdir (versions )))
1045+ def _newest_migration_version (galaxy_root , galaxy_branch ):
1046+ versions_dir = galaxy_root and os .path .join (galaxy_root , "lib/galaxy/model/migrate/versions" )
1047+ if versions_dir and os .path .exists (versions_dir ):
1048+ version = max (map (_file_name_to_migration_version , os .listdir (versions_dir )))
1049+ elif galaxy_branch :
1050+ for branch in MIGRATION_PER_VERSION :
1051+ if branch in galaxy_branch :
1052+ version = MIGRATION_PER_VERSION [branch ]
1053+ else :
1054+ version = OLDEST_SUPPORTED_VERSION
10471055 return version
10481056
10491057
0 commit comments