2011-07-26 13:30:07 -04:00
|
|
|
#!/usr/bin/env python
|
2017-10-12 17:10:12 +01:00
|
|
|
|
2018-03-23 09:41:05 -04:00
|
|
|
import argparse
|
2015-02-25 12:52:47 -05:00
|
|
|
import os
|
|
|
|
|
import sys
|
2017-12-13 20:56:37 +00:00
|
|
|
|
2016-02-18 13:38:07 +00:00
|
|
|
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, "lib")))
|
2015-02-25 12:52:47 -05:00
|
|
|
|
|
|
|
|
import galaxy.config
|
2025-02-10 15:30:39 +00:00
|
|
|
from galaxy import model
|
2022-03-01 15:36:40 +01:00
|
|
|
from galaxy.model.mapping import init_models_from_config
|
2015-02-25 12:52:47 -05:00
|
|
|
from galaxy.objectstore import build_object_store_from_config
|
2015-07-13 20:13:28 +01:00
|
|
|
from galaxy.util import nice_size
|
2018-03-23 09:41:05 -04:00
|
|
|
from galaxy.util.script import (
|
|
|
|
|
app_properties_from_args,
|
|
|
|
|
populate_config_args,
|
2022-02-02 15:26:21 -05:00
|
|
|
)
|
2015-02-25 12:52:47 -05:00
|
|
|
|
2017-08-17 00:33:02 +01:00
|
|
|
default_config = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, "config/galaxy.ini"))
|
2011-09-07 09:05:52 -04:00
|
|
|
|
2018-03-23 09:41:05 -04:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
parser.add_argument("-u", "--username", dest="username", help="Username of user to update", default="all")
|
|
|
|
|
parser.add_argument("-e", "--email", dest="email", help="Email address of user to update", default="all")
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--dry-run",
|
|
|
|
|
dest="dryrun",
|
|
|
|
|
help="Dry run (show changes but do not save to database)",
|
|
|
|
|
action="store_true",
|
|
|
|
|
default=False,
|
|
|
|
|
)
|
|
|
|
|
populate_config_args(parser)
|
|
|
|
|
args = parser.parse_args()
|
2011-07-26 13:30:07 -04:00
|
|
|
|
2015-02-25 12:52:47 -05:00
|
|
|
|
2011-07-26 13:30:07 -04:00
|
|
|
def init():
|
2018-03-23 09:41:05 -04:00
|
|
|
if args.username == "all":
|
|
|
|
|
args.username = None
|
|
|
|
|
if args.email == "all":
|
|
|
|
|
args.email = None
|
2012-02-09 13:26:14 -05:00
|
|
|
|
2018-03-23 09:41:05 -04:00
|
|
|
app_properties = app_properties_from_args(args)
|
|
|
|
|
config = galaxy.config.Configuration(**app_properties)
|
2017-08-17 00:33:02 +01:00
|
|
|
object_store = build_object_store_from_config(config)
|
2022-03-01 15:30:15 +01:00
|
|
|
engine = config.database_connection.split(":")[0]
|
2025-02-10 15:30:39 +00:00
|
|
|
return init_models_from_config(config, object_store=object_store).context, object_store, engine
|
2011-07-26 13:30:07 -04:00
|
|
|
|
2012-09-28 14:30:10 -04:00
|
|
|
|
2023-02-07 17:27:17 -05:00
|
|
|
def quotacheck(sa_session, users, engine, object_store):
|
2017-08-17 00:33:02 +01:00
|
|
|
sa_session.refresh(user)
|
2011-07-26 13:30:07 -04:00
|
|
|
current = user.get_disk_usage()
|
2017-10-12 17:10:12 +01:00
|
|
|
print(user.username, "<" + user.email + ">:", end=" ")
|
2019-08-14 16:08:04 +02:00
|
|
|
|
|
|
|
|
if not args.dryrun:
|
2019-08-14 16:15:49 +02:00
|
|
|
# Apply new disk usage
|
2023-02-07 17:27:17 -05:00
|
|
|
user.calculate_and_set_disk_usage(object_store)
|
2019-08-14 16:15:49 +02:00
|
|
|
# And fetch
|
2019-08-14 16:08:04 +02:00
|
|
|
new = user.get_disk_usage()
|
2012-09-28 14:30:10 -04:00
|
|
|
else:
|
2023-02-07 17:27:17 -05:00
|
|
|
new = user.calculate_disk_usage_default_source(object_store)
|
2019-08-14 16:08:04 +02:00
|
|
|
|
2017-10-12 17:10:12 +01:00
|
|
|
print("old usage:", nice_size(current), "change:", end=" ")
|
2017-08-17 00:33:02 +01:00
|
|
|
if new in (current, None):
|
2017-10-12 17:10:12 +01:00
|
|
|
print("none")
|
2011-07-26 13:30:07 -04:00
|
|
|
else:
|
2012-09-28 16:11:38 -04:00
|
|
|
if new > current:
|
2024-04-27 16:03:22 +01:00
|
|
|
print(f"+{nice_size(new - current)}")
|
2012-10-03 13:40:54 -04:00
|
|
|
else:
|
2024-04-27 16:03:22 +01:00
|
|
|
print(f"-{nice_size(current - new)}")
|
2011-07-26 13:30:07 -04:00
|
|
|
|
2016-11-14 21:12:14 +00:00
|
|
|
|
2011-07-26 13:30:07 -04:00
|
|
|
if __name__ == "__main__":
|
2017-10-12 17:10:12 +01:00
|
|
|
print("Loading Galaxy model...")
|
2025-02-10 15:30:39 +00:00
|
|
|
sa_session, object_store, engine = init()
|
2011-07-26 13:30:07 -04:00
|
|
|
|
2018-03-23 09:41:05 -04:00
|
|
|
if not args.username and not args.email:
|
2017-08-17 00:33:02 +01:00
|
|
|
user_count = sa_session.query(model.User).count()
|
2024-11-24 21:35:20 +00:00
|
|
|
print(f"Processing {user_count} users...")
|
2017-08-17 00:33:02 +01:00
|
|
|
for i, user in enumerate(sa_session.query(model.User).enable_eagerloads(False).yield_per(1000)):
|
2024-11-24 21:35:20 +00:00
|
|
|
print(f"{int(float(i) / user_count * 100):3d}%", end=" ")
|
2023-02-07 17:27:17 -05:00
|
|
|
quotacheck(sa_session, user, engine, object_store)
|
2017-10-12 17:10:12 +01:00
|
|
|
print("100% complete")
|
2012-02-09 13:26:14 -05:00
|
|
|
object_store.shutdown()
|
2017-08-17 00:33:02 +01:00
|
|
|
sys.exit(0)
|
2018-03-23 09:41:05 -04:00
|
|
|
elif args.username:
|
|
|
|
|
user = sa_session.query(model.User).enable_eagerloads(False).filter_by(username=args.username).first()
|
|
|
|
|
elif args.email:
|
|
|
|
|
user = sa_session.query(model.User).enable_eagerloads(False).filter_by(email=args.email).first()
|
2011-07-26 13:30:07 -04:00
|
|
|
if not user:
|
2017-10-12 17:10:12 +01:00
|
|
|
print("User not found")
|
2017-08-17 00:33:02 +01:00
|
|
|
sys.exit(1)
|
2023-02-07 17:27:17 -05:00
|
|
|
quotacheck(sa_session, user, engine, object_store)
|
2012-02-09 13:26:14 -05:00
|
|
|
object_store.shutdown()
|