Chroma config profile
* Remove old packages, and repos from updated profiles
Add help to repos and profile chroma-config command
* Add usage for repos and profile
* Fix typo
@@ -986,9 +986,19 @@ def register_profile(profile_file):
kwargs["name"] = data["name"]
profile = ServerProfile.objects.create(**kwargs)
+ # Remove absent repos
+ for repo in profile.repolist.all():
+ if repo.repo_name not in data["repolist"]:
+ profile.repolist.remove(repo)
+
for name in data["repolist"]:
profile.repolist.add(Repo.objects.get(repo_name=name))
+ # Remove absent packages
+ for package_name in profile.packages:
+ if package_name not in data["packages"]:
+ ServerProfilePackage.objects.filter(server_profile=profile, package_name=package_name).delete()
+
for package_name in data["packages"]:
ServerProfilePackage.objects.get_or_create(server_profile=profile, package_name=package_name)
@@ -1119,6 +1129,7 @@ def chroma_config():
else:
log.info("\nContainer setup complete.")
sys.exit(0)
+
elif command == "dbsetup":
if "--no-dbspace-check" in sys.argv:
check_db_space = False
@@ -1127,6 +1138,7 @@ def chroma_config():
check_db_space = True
service_config._setup_database(check_db_space)
+
elif command == "validate":
errors = service_config.validate()
print_errors(errors)
@@ -1134,41 +1146,77 @@ def chroma_config():
sys.exit(1)
else:
sys.exit(0)
+
elif command == "stop":
service_config.stop()
+
elif command == "start":
service_config.start()
+
elif command == "restart":
service_config.stop()
service_config.start()
+
elif command == "repos":
+
+ def repos_usage():
+ print("usage: repos [scan|help|register REPOFILE|delete REPONAME|install REPONAME TARBALL]")
+ sys.exit(0)
+
+ if len(sys.argv) < 3:
+ repos_usage()
+
operation = sys.argv[2]
- if operation == "scan":
+ if operation == "help":
+ repos_usage()
+
+ elif operation == "scan":
service_config.scan_repos()
+
elif operation == "register":
register_repo(sys.argv[3])
+
elif operation == "delete":
service_config.delete_repo(sys.argv[3])
+
elif operation == "install":
service_config.install_repo(sys.argv[3], sys.argv[4])
+
else:
raise NotImplementedError(operation)
+
elif command == "profile":
+
+ def profile_usage():
+ print("usage: profile [register|delete|default] PROFILE")
+ sys.exit(0)
+
+ if len(sys.argv) < 3:
+ profile_usage()
+
operation = sys.argv[2]
- if operation == "register":
+ if operation == "help":
+ profile_usage()
+
+ elif operation == "register":
try:
register_profile(open(sys.argv[3]))
except IOError:
- print("Error opening %s" % sys.argv[3])
+ log.error("Error opening %s" % sys.argv[3])
sys.exit(-1)
+
elif operation == "delete":
delete_profile(sys.argv[3])
+
elif operation == "default":
default_profile(sys.argv[3])
+
else:
raise NotImplementedError(operation)
+
elif command == "clearsessions":
service_config.clear_sessions()
+
else:
log.error("Invalid command '%s'" % command)
sys.exit(-1)
