2025-10-31 01:10:54 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
import sys
|
[REF] format : passer l'outillage et les tests sous ruff
Le formateur de ce dépôt est ruff depuis qu'il remplace black, qui ne connaît
aucune cible au-delà de py313 ; ce passage applique sa norme à l'arbre entier,
d'un coup, pour qu'aucun commit de fond n'ait à porter du style. L'écart tient
presque entièrement aux chaînes coupées à la main que ruff recolle quand elles
tiennent sur une ligne, et aux « with » multiples qu'il regroupe : aucune
valeur ne change, et les clés de traduction non plus.
Vérifié : la suite unitaire reste verte après le passage, et le contrôle de
syntaxe ne signale rien.
--- EN ---
This repository's formatter is ruff since it replaced black, which knows no
target beyond py313; this pass applies its standard to the whole tree at once,
so that no substantive commit has to carry style. The difference is almost
entirely the hand-split strings ruff joins back when they fit on one line, and
the multiple "with" it merges: no value changes, nor do the translation keys.
Checked: the unit suite stays green after the pass, and the syntax check
reports nothing.
Assisted-by: Claude Opus 5
2026-09-24 13:30:31 -04:00
|
|
|
import xmlrpc.client
|
|
|
|
|
|
2025-10-31 01:10:54 -04:00
|
|
|
import click
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_db_list_xmlrpc(odoo_url):
|
|
|
|
|
"""
|
|
|
|
|
Retrieves the list of Odoo databases using the XML-RPC API.
|
|
|
|
|
"""
|
|
|
|
|
try:
|
2026-03-13 15:04:14 -04:00
|
|
|
common = xmlrpc.client.ServerProxy(f"{odoo_url}/xmlrpc/db")
|
2025-10-31 01:10:54 -04:00
|
|
|
db_list = common.list()
|
|
|
|
|
return db_list
|
|
|
|
|
except xmlrpc.client.Fault as e:
|
2026-03-13 15:04:14 -04:00
|
|
|
print(
|
|
|
|
|
f"XML-RPC Error: {e.faultCode} - {e.faultString}", file=sys.stderr
|
|
|
|
|
)
|
2025-10-31 01:10:54 -04:00
|
|
|
return []
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"Connection Error: {e}", file=sys.stderr)
|
|
|
|
|
return []
|
|
|
|
|
|
2026-03-13 15:04:14 -04:00
|
|
|
|
2025-10-31 01:10:54 -04:00
|
|
|
# --- CLI using Click ---
|
|
|
|
|
@click.command()
|
|
|
|
|
@click.option(
|
2026-03-13 15:04:14 -04:00
|
|
|
"--odoo-url",
|
|
|
|
|
default="http://localhost:8069",
|
|
|
|
|
help="URL of the Odoo server.",
|
|
|
|
|
show_default=True,
|
2025-10-31 01:10:54 -04:00
|
|
|
)
|
|
|
|
|
@click.option(
|
2026-03-13 15:04:14 -04:00
|
|
|
"--raw",
|
2025-10-31 01:10:54 -04:00
|
|
|
is_flag=True,
|
2026-03-13 15:04:14 -04:00
|
|
|
help="Output one database per line, without extra formatting. Useful for scripting.",
|
2025-10-31 01:10:54 -04:00
|
|
|
)
|
|
|
|
|
def list_databases(odoo_url, raw=False):
|
|
|
|
|
"""
|
|
|
|
|
This script lists all available databases on an Odoo server.
|
|
|
|
|
"""
|
|
|
|
|
if not raw:
|
|
|
|
|
click.echo(f"Attempting to connect to Odoo at: {odoo_url}")
|
|
|
|
|
|
|
|
|
|
databases = get_db_list_xmlrpc(odoo_url)
|
|
|
|
|
|
|
|
|
|
if databases:
|
|
|
|
|
if not raw:
|
|
|
|
|
click.echo("\nAvailable databases:")
|
|
|
|
|
for db in databases:
|
|
|
|
|
if not raw:
|
|
|
|
|
click.echo(f"- {db}")
|
|
|
|
|
else:
|
|
|
|
|
click.echo(db)
|
|
|
|
|
else:
|
|
|
|
|
if not raw:
|
|
|
|
|
click.echo("Failed to retrieve the database list.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --- Script Execution ---
|
2026-03-13 15:04:14 -04:00
|
|
|
if __name__ == "__main__":
|
2025-10-31 01:10:54 -04:00
|
|
|
list_databases()
|