erplibre/script/database/list_remote.py
Mathieu Benoit cfbdd9406e [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 14:40:38 -04:00

64 lines
1.5 KiB
Python
Executable file

#!/usr/bin/env bash
import sys
import xmlrpc.client
import click
def get_db_list_xmlrpc(odoo_url):
"""
Retrieves the list of Odoo databases using the XML-RPC API.
"""
try:
common = xmlrpc.client.ServerProxy(f"{odoo_url}/xmlrpc/db")
db_list = common.list()
return db_list
except xmlrpc.client.Fault as e:
print(
f"XML-RPC Error: {e.faultCode} - {e.faultString}", file=sys.stderr
)
return []
except Exception as e:
print(f"Connection Error: {e}", file=sys.stderr)
return []
# --- CLI using Click ---
@click.command()
@click.option(
"--odoo-url",
default="http://localhost:8069",
help="URL of the Odoo server.",
show_default=True,
)
@click.option(
"--raw",
is_flag=True,
help="Output one database per line, without extra formatting. Useful for scripting.",
)
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 ---
if __name__ == "__main__":
list_databases()