Esempio n. 1
0
def rename_database(http_client: T_HttpClient, url: str, master_password: str,
                    *, old_name: str, new_name: str) -> bool:
    return rpc_result(http_client,
                      url,
                      service=__SERVICE,
                      method='rename',
                      args=[master_password, old_name, new_name],
                      ensure_instance_of=bool)
Esempio n. 2
0
def drop_database(http_client: T_HttpClient, url: str, master_password: str, *,
                  db_name: str) -> bool:
    return rpc_result(http_client,
                      url,
                      service=__SERVICE,
                      method="drop",
                      args=[master_password, db_name],
                      ensure_instance_of=bool)
Esempio n. 3
0
def list_countries(http_client: T_HttpClient, url: str = '') -> List[str]:
    service, method = __SERVICE, 'list_countries'

    return rpc_result(http_client,
                      url,
                      service=service,
                      method=method,
                      ensure_instance_of=list)
Esempio n. 4
0
def list_countries(http_client: T_HttpClient, url: str,
                   master_password: str) -> List[str]:
    return rpc_result(http_client,
                      url,
                      service=__SERVICE,
                      method='list_countries',
                      args=[master_password],
                      ensure_instance_of=list)
Esempio n. 5
0
def version(http_client: T_HttpClient, url: str = '') -> str:
    service, method = __SERVICE, 'version'

    return rpc_result(http_client,
                      url,
                      service=service,
                      method=method,
                      ensure_instance_of=str)
Esempio n. 6
0
def migrate_databases(http_client: T_HttpClient, url: str,
                      master_password: str, *, databases: List[str]) -> bool:
    return rpc_result(http_client,
                      url,
                      service=__SERVICE,
                      method='migrate_databases',
                      args=[master_password, databases],
                      ensure_instance_of=bool)
Esempio n. 7
0
def duplicate_database(http_client: T_HttpClient, url: str,
                       master_password: str, *, db_original_name: str,
                       db_name: str) -> bool:
    return rpc_result(http_client,
                      url,
                      service=__SERVICE,
                      method='duplicate_database',
                      args=[master_password, db_original_name, db_name],
                      ensure_instance_of=bool)
Esempio n. 8
0
def change_admin_password(http_client: T_HttpClient, url: str,
                          master_password: str, *, new_password: str) -> bool:
    # web/database/change_password / POST form-encoded / params master_pwd, master_pwd_new
    return rpc_result(http_client,
                      url,
                      service=__SERVICE,
                      method="change_admin_password",
                      args=[master_password, new_password],
                      ensure_instance_of=bool)
Esempio n. 9
0
def about(http_client: T_HttpClient, url: str = '', *, extended):
    service, method = __SERVICE, 'about'
    args = [extended]

    return rpc_result(http_client,
                      url,
                      service=service,
                      method=method,
                      args=args)
Esempio n. 10
0
def list_databases(http_client: T_HttpClient,
                   url: str,
                   *_,
                   document: Optional[bool] = None) -> List[str]:
    return rpc_result(http_client,
                      url,
                      service=__SERVICE,
                      method='list',
                      args=None if document is None else [document],
                      ensure_instance_of=list)
Esempio n. 11
0
def dump_database(http_client: T_HttpClient,
                  url: str,
                  master_password: str,
                  *,
                  db_name: str,
                  format: str = "zip") -> bytes:
    res = rpc_result(http_client,
                     url,
                     service=__SERVICE,
                     method='dump',
                     args=[master_password, db_name, format],
                     ensure_instance_of=str)
    return base64.b64decode(res)
Esempio n. 12
0
def db_exist(http_client: T_HttpClient,
             url: str = '',
             *,
             db_name: str) -> bool:
    service, method = __SERVICE, 'db_exist'
    args = [db_name]

    return rpc_result(http_client,
                      url,
                      service=service,
                      method=method,
                      args=args,
                      ensure_instance_of=bool)
Esempio n. 13
0
def list_databases(http_client: T_HttpClient,
                   url: str = '',
                   *,
                   document: bool = False) -> List[str]:
    service, method = __SERVICE, 'list'
    args = [document]

    return rpc_result(http_client,
                      url,
                      service=service,
                      method=method,
                      args=args,
                      ensure_instance_of=bool)
Esempio n. 14
0
def change_admin_password(http_client: T_HttpClient,
                          url: str = '',
                          *,
                          admin_password: str,
                          new_password: str) -> bool:
    service, method = __SERVICE, 'change_admin_password'
    args = [admin_password, new_password]

    return rpc_result(http_client,
                      url,
                      service=service,
                      method=method,
                      args=args,
                      ensure_instance_of=bool)
Esempio n. 15
0
def drop_database(http_client: T_HttpClient,
                  url: str = '',
                  *,
                  admin_password: str,
                  db_name: str) -> bool:
    service, method = __SERVICE, 'drop'
    args = [admin_password, db_name]

    return rpc_result(http_client,
                      url,
                      service=service,
                      method=method,
                      args=args,
                      ensure_instance_of=bool)
Esempio n. 16
0
def login(http_client: T_HttpClient,
          url: str = '',
          *,
          db: str,
          login: str,
          password: str) -> Union[int, Literal[False]]:
    service, method = __SERVICE, 'login'
    args = [db, login, password]

    return rpc_result(http_client,
                      url,
                      service=service,
                      method=method,
                      args=args)
Esempio n. 17
0
def migrate_databases(http_client: T_HttpClient,
                      url: str = '',
                      *,
                      admin_password: str,
                      databases: List[str]) -> bool:
    service = __SERVICE
    method = 'migrate_databases'
    args = [admin_password, databases]

    return rpc_result(http_client,
                      url,
                      service=service,
                      method=method,
                      args=args,
                      ensure_instance_of=bool)
Esempio n. 18
0
def authenticate(http_client: T_HttpClient,
                 url: str = '',
                 *,
                 db: str,
                 login: str,
                 password: str,
                 user_agent_env: Mapping) -> Union[int, Literal[False]]:
    service, method = __SERVICE, 'authenticate'
    args = [db, login, password, user_agent_env]

    return rpc_result(http_client,
                      url,
                      service=service,
                      method=method,
                      args=args)
Esempio n. 19
0
def dump_database(http_client: T_HttpClient,
                  url: str = '',
                  *,
                  admin_password: str,
                  db_name: str,
                  format: str = "zip") -> bytes:
    service, method = __SERVICE, 'dump'
    args = [admin_password, db_name, format]

    res = rpc_result(http_client,
                     url,
                     service=service,
                     method=method,
                     args=args,
                     ensure_instance_of=str)
    return res.encode()
Esempio n. 20
0
def restore_database(http_client: T_HttpClient,
                     url: str = '',
                     *,
                     admin_password: str,
                     db_name: str,
                     data: bytes,
                     copy: bool = False) -> bool:
    service, method = __SERVICE, 'restore'
    args = [admin_password, db_name, data, copy]

    return rpc_result(http_client,
                      url,
                      service=service,
                      method=method,
                      args=args,
                      ensure_instance_of=bool)
Esempio n. 21
0
def restore_database(http_client: T_HttpClient,
                     url: str,
                     master_password: str,
                     *,
                     db_name: str,
                     data: Union[bytes, str],
                     copy: bool = False) -> bool:
    # /web/database/restore / POST multipart/form-data / params: master_pwd, backup_file, name, copy
    if isinstance(data, bytes):
        data = base64.b64encode(data).decode('ascii')
    return rpc_result(http_client,
                      url,
                      service=__SERVICE,
                      method='restore',
                      args=[master_password, db_name, data, copy],
                      ensure_instance_of=bool)
Esempio n. 22
0
def execute_kw(
    http_client: T_HttpClient,
    url: str,
    db: str,
    uid: int,
    password: str,
    *,
    obj: str,
    method: str,
    args: list,
    kwargs: Optional[dict] = None
) -> Union[bool, dict, int, List[dict], List[int]]:

    url = '' if url is None else url
    return rpc_result(http_client,
                      url,
                      service=__SERVICE,
                      method="execute_kw",
                      args=[db, uid, password, obj, method, args, kwargs])
Esempio n. 23
0
def db_exist(http_client: T_HttpClient,
             url: str,
             *_,
             db_name: Optional[str] = None) -> bool:
    # support list unpacking used with model methods
    # [http_client, url: str, db: str, uid: int, password: str]
    # if _ has 3 items and the second is an int we can assume _[0] has the db_name
    db_name = _[0] if db_name is None and len(_) == 3 and isinstance(
        _[1], int) else db_name

    if db_name is None:
        raise RuntimeError("[db_exist] No database name provided.")

    return rpc_result(http_client,
                      url,
                      service=__SERVICE,
                      method='db_exist',
                      args=[db_name],
                      ensure_instance_of=bool)
Esempio n. 24
0
def execute_kw(
    http_client: T_HttpClient,
    url: str = '',
    *,
    db: str,
    uid: int,
    password: str,
    obj: str,
    method: str,
    args: list,
    kw: Optional[dict] = None
) -> Union[bool, dict, int, List[dict], List[int]]:

    args = [db, uid, password, obj, method, args]

    return rpc_result(http_client,
                      url,
                      service='object',
                      method='execute_kw',
                      args=args,
                      kwargs=kw)
Esempio n. 25
0
def create_database(http_client: T_HttpClient,
                    url: str,
                    master_password: str,
                    *,
                    db_name: str,
                    demo: bool,
                    lang: str,
                    user_password: Optional[str] = None,
                    login: Optional[str] = None,
                    country_code: Optional[str] = None,
                    phone: Optional[str] = None) -> bool:
    args: list = [master_password, db_name, demo, lang]
    opt_args: list = [user_password, login, country_code, phone]
    while len(opt_args) > 0 and opt_args[-1] is None:
        opt_args = opt_args[:-1]
    args.extend(opt_args)

    return rpc_result(http_client,
                      url,
                      service=__SERVICE,
                      method="create_database",
                      args=args,
                      ensure_instance_of=bool)
Esempio n. 26
0
def create_database(http_client: T_HttpClient,
                    url: str = '',
                    *,
                    admin_password: str,
                    db_name: str,
                    demo: bool,
                    lang: str,
                    user_password: str = 'admin',
                    login: str = 'admin',
                    country_code: str = None,
                    phone: str = None) -> bool:
    service, method = __SERVICE, 'create_database'
    args = [
        admin_password, db_name, demo, lang, user_password, login,
        country_code, phone
    ]

    return rpc_result(http_client,
                      url,
                      service=service,
                      method=method,
                      args=args,
                      ensure_instance_of=bool)
Esempio n. 27
0
def about(http_client: T_HttpClient, url: str = '', *_,
          extended: Optional[bool] = None) -> Union[str, Tuple[str, str]]:
    return rpc_result(http_client, url, service=__SERVICE, method='about',
                      args=[] if extended is None else [True if extended else False],
                      ensure_instance_of=list if extended else str)
Esempio n. 28
0
def version(http_client: T_HttpClient, url: str = '', *_) -> str:
    return rpc_result(http_client, url, service=__SERVICE, method='version', ensure_instance_of=dict)
Esempio n. 29
0
def set_loglevel(http_client: T_HttpClient, url: str = '', *_,
                 loglevel, logger: Optional[str] = None):
    args = [loglevel, logger] if logger is not None else [loglevel]
    return rpc_result(http_client, url, service=__SERVICE, method='set_loglevel',
                      args=args, ensure_instance_of=bool)
Esempio n. 30
0
def login(http_client: T_HttpClient, url: str, db: str, login: str,
          password: str) -> Union[int, Literal[False]]:
    return rpc_result(http_client, url, service=__SERVICE, method='login',
                      args=[db, login, password])