forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_shed_config_path.py
82 lines (72 loc) · 2.74 KB
/
update_shed_config_path.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import argparse
import os
import sys
from configparser import ConfigParser
from sqlalchemy import (
create_engine,
MetaData,
)
from sqlalchemy.orm import (
scoped_session,
sessionmaker,
)
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, "lib")))
import galaxy.model.tool_shed_install.mapping as mapping
def main(opts, session, model):
"""
Find all tool shed repositories with the bad path and update with the correct path.
"""
for row in session.query(model.ToolShedRepository).all():
if "shed_config_filename" in row.metadata_:
if row.metadata_["shed_config_filename"] == opts.bad_filename:
row.metadata_["shed_config_filename"] = opts.good_filename
session.add(row)
session.commit()
return 0
def create_database(config_file):
parser = ConfigParser()
parser.read(config_file)
# Determine which database connection to use.
database_connection = parser.get("app:main", "install_database_connection")
if database_connection is None:
database_connection = parser.get("app:main", "database_connection")
if database_connection is None:
database_connection = "sqlite:///{}".format(parser.get("app:main", "database_file"))
if database_connection is None:
print("Unable to determine correct database connection.")
exit(1)
# Initialize the database connection.
engine = create_engine(database_connection)
MetaData(bind=engine)
install_session = scoped_session(sessionmaker(bind=engine, autoflush=False))
model = mapping.init(database_connection)
return install_session, model
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--config_file", dest="config_file", required=True, help="The path to your Galaxy configuration .ini file."
)
parser.add_argument(
"--from",
dest="bad_filename",
required=True,
help="The old, invalid path to the shed_tool_conf.xml or migrated_tools_conf.xml file.",
)
parser.add_argument(
"--to",
dest="good_filename",
required=True,
help="The updated path to the shed_tool_conf.xml or migrated_tools_conf.xml file.",
)
parser.add_argument(
"--force",
dest="force",
action="store_true",
help="Use this flag to set the new path even if the file does not (yet) exist there.",
)
opts = parser.parse_args()
if not os.path.exists(opts.good_filename) and not opts.force:
print(f"The file {opts.good_filename} does not exist, use the --force option to proceed.")
exit(1)
session, model = create_database(opts.config_file)
exit(main(opts, session, model))