2024-08-26 14:55:36 -04:00
|
|
|
#!/usr/bin/env python3
|
2026-03-11 23:15:07 -04:00
|
|
|
# © 2021-2026 TechnoLibre (http://www.technolibre.ca)
|
2024-08-26 14:55:36 -04:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
|
|
|
|
|
2022-01-24 14:00:47 -05:00
|
|
|
import argparse
|
|
|
|
|
import logging
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def execute_shell(cmd):
|
2025-11-26 22:20:43 -05:00
|
|
|
result = subprocess.run(
|
|
|
|
|
cmd,
|
|
|
|
|
shell=True,
|
|
|
|
|
capture_output=True,
|
|
|
|
|
text=True,
|
|
|
|
|
)
|
|
|
|
|
output = (result.stdout or "") + (result.stderr or "")
|
|
|
|
|
return result.returncode, output.strip()
|
2022-01-24 14:00:47 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_config():
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
|
|
|
description="""\
|
|
|
|
|
Drop all database, caution!
|
|
|
|
|
""",
|
|
|
|
|
epilog="""\
|
|
|
|
|
""",
|
|
|
|
|
)
|
2022-01-26 16:39:42 -05:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--test_only",
|
|
|
|
|
help="test and test_* and other by system test.",
|
|
|
|
|
action="store_true",
|
|
|
|
|
)
|
2025-10-31 01:10:54 -04:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--database",
|
|
|
|
|
help="Specify database to delete, separate by coma",
|
|
|
|
|
)
|
2022-01-24 14:00:47 -05:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
return args
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
config = get_config()
|
|
|
|
|
|
2025-11-28 16:32:35 -05:00
|
|
|
status, out_db = execute_shell("./odoo_bin.sh db --list")
|
2022-01-24 14:00:47 -05:00
|
|
|
lst_db = out_db.split("\n")
|
2025-10-31 01:10:54 -04:00
|
|
|
|
|
|
|
|
lst_database_to_delete = []
|
|
|
|
|
if config.database:
|
|
|
|
|
lst_database_to_delete = [
|
|
|
|
|
a.strip() for a in config.database.split(",")
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
cmd_all = "parallel :::"
|
|
|
|
|
cmd_end = ""
|
|
|
|
|
lst_db_name = []
|
2022-01-24 14:00:47 -05:00
|
|
|
for db_name in lst_db:
|
2022-01-26 16:39:42 -05:00
|
|
|
if config.test_only and not (
|
|
|
|
|
db_name in ("test",)
|
|
|
|
|
or db_name.startswith("test_")
|
|
|
|
|
or db_name.startswith("new_project_")
|
|
|
|
|
):
|
|
|
|
|
continue
|
2025-10-31 01:10:54 -04:00
|
|
|
if lst_database_to_delete and db_name not in lst_database_to_delete:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
cmd_end += f' "./odoo_bin.sh db --drop --database {db_name}"'
|
|
|
|
|
lst_db_name.append(db_name)
|
|
|
|
|
if cmd_end:
|
|
|
|
|
execute_shell(cmd_all + cmd_end)
|
|
|
|
|
print("Database deleted :")
|
|
|
|
|
for db_name in lst_db_name:
|
|
|
|
|
print(db_name)
|
2022-01-24 14:00:47 -05:00
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
sys.exit(main())
|