def main(): if len(sys.argv) < 2: print "Usage: python %s <Tool shed config file>" % sys.argv[0] sys.exit(0) now = strftime("%Y-%m-%d %H:%M:%S") print " " print "##########################################" print "%s - Migrating current tool archives to new tool repositories" % now # tool_shed_wsgi.ini file ini_file = sys.argv[1] conf_parser = ConfigParser.ConfigParser({'here': os.getcwd()}) conf_parser.read(ini_file) try: db_conn_str = conf_parser.get("app:main", "database_connection") except ConfigParser.NoOptionError: db_conn_str = conf_parser.get("app:main", "database_file") print 'DB Connection: ', db_conn_str # Instantiate app configuration = {} for key, value in conf_parser.items("app:main"): configuration[key] = value app = galaxy.webapps.tool_shed.app.UniverseApplication(global_conf=dict(__file__=ini_file), **configuration) sa_session = app.model.context # Remove the hgweb.config file if it exists hgweb_config = "%s/hgweb.config" % os.getcwd() if os.path.exists(hgweb_config): print "Removing old file: ", hgweb_config os.remove(hgweb_config) repo_records = 0 rca_records = 0 rra_records = 0 for repo in sa_session.query(app.model.Repository): # Remove the hg repository from disk. We have to be careful here, because old # tool files exist in app.config.file_path/tools and we don't want to delete them dir = os.path.join(app.config.file_path, *directory_hash_id(repo.id)) if os.path.exists(dir): print "Removing old repository file directory: ", dir shutil.rmtree(dir) # Delete all records from db tables: # repository_category_association, repository_rating_association, repository print "Deleting db records for repository: ", repo.name for rca in repo.categories: sa_session.delete(rca) rca_records += 1 for rra in repo.ratings: sa_session.delete(rra) rra_records += 1 sa_session.delete(repo) repo_records += 1 sa_session.flush() print "Deleted %d rows from the repository table" % repo_records print "Deleted %d rows from the repository_category_association table" % rca_records print "Deleted %d rows from the repository_rating_association table" % rra_records # Migrate database tool, tool category and tool rating records to new # database repository, repository category and repository rating records # and create the hg repository on disk for each. for tool in get_approved_tools(app, sa_session): create_repository_from_tool(app, sa_session, tool) # Add, commit and push all valid versions of each approved tool to the # associated hg repository. for tool in get_approved_tools(app, sa_session): add_tool_files_to_repository(app, sa_session, tool) app.shutdown() print ' ' print 'Migration to next gen tool shed complete...' print "##########################################" sys.exit(0)
for rca in repo.categories: sa_session.delete(rca) rca_records += 1 for rra in repo.ratings: sa_session.delete(rra) rra_records += 1 sa_session.delete(repo) repo_records += 1 sa_session.flush() print "Deleted %d rows from the repository table" % repo_records print "Deleted %d rows from the repository_category_association table" % rca_records print "Deleted %d rows from the repository_rating_association table" % rra_records # Migrate database tool, tool category and tool rating records to new # database repository, repository category and repository rating records # and create the hg repository on disk for each. for tool in get_approved_tools(app, sa_session): create_repository_from_tool(app, sa_session, tool) # Add, commit and push all valid versions of each approved tool to the # associated hg repository. for tool in get_approved_tools(app, sa_session): add_tool_files_to_repository(app, sa_session, tool) app.shutdown() print ' ' print 'Migration to next gen tool shed complete...' print "##########################################" sys.exit(0) if __name__ == "__main__": main()
def main(): if len(sys.argv) < 2: print("Usage: python %s <Tool shed config file>" % sys.argv[0]) sys.exit(0) now = strftime("%Y-%m-%d %H:%M:%S") print() print("##########################################") print("%s - Migrating current tool archives to new tool repositories" % now) # tool_shed_wsgi.ini file ini_file = sys.argv[1] conf_parser = configparser.ConfigParser({'here': os.getcwd()}) conf_parser.read(ini_file) try: db_conn_str = conf_parser.get("app:main", "database_connection") except configparser.NoOptionError: db_conn_str = conf_parser.get("app:main", "database_file") print('DB Connection: ', db_conn_str) # Instantiate app configuration = {} for key, value in conf_parser.items("app:main"): configuration[key] = value app = galaxy.webapps.tool_shed.app.UniverseApplication(global_conf=dict(__file__=ini_file), **configuration) sa_session = app.model.context # Remove the hgweb.config file if it exists hgweb_config = "%s/hgweb.config" % os.getcwd() if os.path.exists(hgweb_config): print("Removing old file: ", hgweb_config) os.remove(hgweb_config) repo_records = 0 rca_records = 0 rra_records = 0 for repo in sa_session.query(app.model.Repository): # Remove the hg repository from disk. We have to be careful here, because old # tool files exist in app.config.file_path/tools and we don't want to delete them dir = os.path.join(app.config.file_path, *directory_hash_id(repo.id)) if os.path.exists(dir): print("Removing old repository file directory: ", dir) shutil.rmtree(dir) # Delete all records from db tables: # repository_category_association, repository_rating_association, repository print("Deleting db records for repository: ", repo.name) for rca in repo.categories: sa_session.delete(rca) rca_records += 1 for rra in repo.ratings: sa_session.delete(rra) rra_records += 1 sa_session.delete(repo) repo_records += 1 sa_session.flush() print("Deleted %d rows from the repository table" % repo_records) print("Deleted %d rows from the repository_category_association table" % rca_records) print("Deleted %d rows from the repository_rating_association table" % rra_records) # Migrate database tool, tool category and tool rating records to new # database repository, repository category and repository rating records # and create the hg repository on disk for each. for tool in get_approved_tools(app, sa_session): create_repository_from_tool(app, sa_session, tool) # Add, commit and push all valid versions of each approved tool to the # associated hg repository. for tool in get_approved_tools(app, sa_session): add_tool_files_to_repository(app, sa_session, tool) app.shutdown() print() print('Migration to next gen tool shed complete...') print("##########################################") sys.exit(0)
print "Deleting db records for repository: ", repo.name for rca in repo.categories: sa_session.delete( rca ) rca_records += 1 for rra in repo.ratings: sa_session.delete( rra ) rra_records += 1 sa_session.delete( repo ) repo_records += 1 sa_session.flush() print "Deleted %d rows from the repository table" % repo_records print "Deleted %d rows from the repository_category_association table" % rca_records print "Deleted %d rows from the repository_rating_association table" % rra_records # Migrate database tool, tool category and tool rating records to new # database repository, repository category and repository rating records # and create the hg repository on disk for each. for tool in get_approved_tools( app, sa_session ): create_repository_from_tool( app, sa_session, tool ) # Add, commit and push all valid versions of each approved tool to the # associated hg repository. for tool in get_approved_tools( app, sa_session ): add_tool_files_to_repository( app, sa_session, tool ) app.shutdown() print ' ' print 'Migration to next gen tool shed complete...' print "##########################################" sys.exit(0) if __name__ == "__main__": main()