19.0 vanilla

This commit is contained in:
Ernad Husremovic 2025-10-03 18:07:25 +02:00
parent 0a7ae8db93
commit 991d2234ca
416 changed files with 646602 additions and 300844 deletions

View file

@ -1,35 +1,41 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import argparse
import io
import urllib.parse
import sys
import textwrap
import urllib.parse
import zipfile
from argparse import RawTextHelpFormatter
from functools import partial
from pathlib import Path
import requests
from ..service.db import (
dump_db,
exp_create_database,
exp_db_exist,
exp_drop,
exp_duplicate_database,
exp_rename,
restore_db,
)
from ..tools import config
from . import Command
from .server import report_configuration
from ..service.db import dump_db, exp_drop, exp_db_exist, exp_duplicate_database, exp_rename, restore_db
from ..tools import config
eprint = partial(print, file=sys.stderr, flush=True)
class Db(Command):
""" Create, drop, dump, load databases """
name = 'db'
description = """
Command-line version of the database manager.
Commands are all filestore-aware.
"""
def run(self, cmdargs):
"""Command-line version of the database manager.
Doesn't provide a `create` command as that's not useful. Commands are
all filestore-aware.
"""
parser = argparse.ArgumentParser(
prog=f'{Path(sys.argv[0]).name} {self.name}',
description=self.__doc__.strip()
)
parser = self.parser
parser.add_argument('-c', '--config')
parser.add_argument('-D', '--data-dir')
parser.add_argument('--addons-path')
@ -42,6 +48,55 @@ class Db(Command):
parser.set_defaults(func=lambda _: exit(parser.format_help()))
subs = parser.add_subparsers()
# INIT ----------------------------------
init = subs.add_parser(
"init",
help="Create and initialize a database",
description="Create an empty database and install the minimum required modules",
formatter_class=RawTextHelpFormatter,
)
init.set_defaults(func=self.init)
init.add_argument(
'database',
help="database to create",
)
init.add_argument(
'--with-demo', action='store_true',
help="install demo data in the new database",
)
init.add_argument(
'--force', action='store_true',
help="delete database if exists",
)
init.add_argument(
'--language', default='en_US',
help="default language for the instance, default 'en_US'",
)
init.add_argument(
'--username', default='admin',
help="admin username, default 'admin'",
)
init.add_argument(
'--password', default='admin',
help="admin password, default 'admin'",
)
init.add_argument(
'--country',
help="country to be set on the main company",
)
init.epilog = textwrap.dedent("""\
Database initialization will install the minimum required modules.
To install more modules, use the `module install` command.
For more info:
$ odoo-bin module install --help
""")
# LOAD ----------------------------------
load = subs.add_parser(
"load", help="Load a dump file.",
description="Loads a dump file into odoo, dump file can be a URL. "
@ -63,11 +118,13 @@ class Db(Command):
)
load.add_argument('dump_file', help="zip or pg_dump file to load")
# DUMP ----------------------------------
dump = subs.add_parser(
"dump", help="Create a dump with filestore.",
description="Creates a dump file. The dump is always in zip format "
"(with filestore), to get a no-filestore format use "
"pg_dump directly.")
"(with filestore), to get pg_dump format, use "
"dump_format argument.")
dump.set_defaults(func=self.dump)
dump.add_argument('database', help="database to dump")
dump.add_argument(
@ -75,6 +132,18 @@ class Db(Command):
help="if provided, database is dumped to specified path, otherwise "
"or if `-`, dumped to stdout",
)
dump.add_argument(
'--format', dest='dump_format', choices=('zip', 'dump'), default='zip',
help="if provided, database is dumped used the specified format, "
"otherwise defaults to `zip`.\n"
"Supported formats are `zip`, `dump` (pg_dump format) ",
)
dump.add_argument(
'--no-filestore', action='store_const', dest='filestore', default=True, const=False,
help="if passed, zip database is dumped without filestore (default: false)"
)
# DUPLICATE -----------------------------
duplicate = subs.add_parser("duplicate", help="Duplicate a database including filestore.")
duplicate.set_defaults(func=self.duplicate)
@ -89,6 +158,8 @@ class Db(Command):
duplicate.add_argument("source")
duplicate.add_argument("target", help="database to copy `source` to, must not exist unless `-f` is specified in which case it will be dropped first")
# RENAME --------------------------------
rename = subs.add_parser("rename", help="Rename a database including filestore.")
rename.set_defaults(func=self.rename)
rename.add_argument(
@ -98,6 +169,8 @@ class Db(Command):
rename.add_argument('source')
rename.add_argument("target", help="database to rename `source` to, must not exist unless `-f` is specified, in which case it will be dropped first")
# DROP ----------------------------------
drop = subs.add_parser("drop", help="Delete a database including filestore")
drop.set_defaults(func=self.drop)
drop.add_argument("database", help="database to delete")
@ -123,6 +196,18 @@ class Db(Command):
args.func(args)
def init(self, args):
self._check_target(args.database, delete_if_exists=args.force)
exp_create_database(
db_name=args.database,
demo=args.with_demo,
lang=args.language,
login=args.username,
user_password=args.password,
country_code=args.country,
phone=None,
)
def load(self, args):
db_name = args.database or Path(args.dump_file).stem
self._check_target(db_name, delete_if_exists=args.force)
@ -151,7 +236,7 @@ class Db(Command):
dump_db(args.database, sys.stdout.buffer)
else:
with open(args.dump_path, 'wb') as f:
dump_db(args.database, f)
dump_db(args.database, f, args.dump_format, args.filestore)
def duplicate(self, args):
self._check_target(args.target, delete_if_exists=args.force)