256 lines
6.8 KiB
Python
Executable File
256 lines
6.8 KiB
Python
Executable File
# -*- coding: utf-8 -*-
|
|
|
|
import sys
|
|
from urllib.parse import urlparse
|
|
|
|
from .config import Config
|
|
from .environments import ENVIRONMENTS, Environment
|
|
from .functions import DatenpolFunctions
|
|
|
|
def main():
|
|
def _usage():
|
|
print('Verwendung: dp <environment> <command> [<module_name>/<setup_function>]')
|
|
print(' dp list-envs\n')
|
|
print('Commands:')
|
|
print(' create Neue Datenbank erstellen')
|
|
print(' create_from_dump Neue Datenbank von Dump erstellen')
|
|
print(' setup Modulinstallation, Konfigurationen')
|
|
print(' setup_part setup_function Aufruf eines einzelnen Setup-Schrittes')
|
|
print(' "setup_part info" listet die verfügbaren')
|
|
print(' Setup-Schritte auf')
|
|
print(' rollout Setzt Dokumentnummern, importiert Benutzer,')
|
|
print(' setzt dp_dmi auf noupdate, ...')
|
|
print(' update modul1 modul2 ... Module updaten')
|
|
print(' install module_name Modul installieren')
|
|
print(' uninstall module_name Modul deinstallieren')
|
|
print(' cancel_upgrade module_name Abbruch Modulinstallation')
|
|
print(' update_modules Update aller Module in der config-Modulliste')
|
|
print(' update_all Update aller verfügbaren Module')
|
|
print(' anonym Daten anonymisieren (Namen, Adresse, E-Mail, ...)')
|
|
print(' invalidate_email E-Mail Adressen invalidieren (@ > #)')
|
|
sys.exit(3)
|
|
|
|
argv = sys.argv[1:]
|
|
|
|
if not argv:
|
|
_usage()
|
|
|
|
# RUNBOT
|
|
# ./dp runbot create [db] [port] [working-dir]
|
|
|
|
if argv[0] == 'runbot':
|
|
import os
|
|
cmd = argv[1]
|
|
db = argv[2]
|
|
port = argv[3]
|
|
setup_path = argv[4]
|
|
|
|
env = Environment('http://localhost', port, db, 'admin', 'admin', 'admin')
|
|
os.chdir(setup_path)
|
|
elif argv[0] == 'list-envs':
|
|
print('name: host:port dbname username')
|
|
for env_name in sorted(ENVIRONMENTS):
|
|
env = ENVIRONMENTS[env_name]
|
|
print('%s: %s:%s %s %s' % (env_name, env.host, env.port, env.dbname, env.username))
|
|
return
|
|
else:
|
|
if len(argv) != 2:
|
|
if len(argv) == 3 and argv[1] in ['install', 'uninstall', 'cancel_update', 'setup_part']:
|
|
pass
|
|
elif len(argv) >= 3 and argv[1] == 'update':
|
|
pass
|
|
else:
|
|
_usage()
|
|
|
|
cmd = argv[1]
|
|
|
|
env = ENVIRONMENTS.get(argv[0])
|
|
if not env:
|
|
print('Unbekannte Umgebung')
|
|
_usage()
|
|
|
|
if env.config:
|
|
config = env.config
|
|
else:
|
|
config = Config()
|
|
instance = DatenpolFunctions(env, config)
|
|
|
|
methods = None
|
|
|
|
if cmd == 'test':
|
|
methods = [
|
|
'login',
|
|
]
|
|
|
|
if cmd == 'create':
|
|
methods = [
|
|
'create_db',
|
|
'login',
|
|
]
|
|
|
|
if cmd == 'dump':
|
|
methods = [
|
|
'create_dump',
|
|
]
|
|
|
|
if cmd == 'restore':
|
|
methods = [
|
|
'create_db_from_dump',
|
|
]
|
|
|
|
if cmd == 'drop':
|
|
methods = [
|
|
'drop_db',
|
|
]
|
|
|
|
if cmd == 'load_languages':
|
|
methods = [
|
|
'login',
|
|
'load_languages'
|
|
]
|
|
|
|
setup_methods = [
|
|
'login',
|
|
'install_modules',
|
|
'set_default_settings',
|
|
#'set_warehouse',
|
|
#'stock_set_cost_method',
|
|
#'set_incoterms',
|
|
'set_company',
|
|
'enable_res_config_for_company', # muss bei multicompany ausgefuehrt werden
|
|
'set_multicompany_data', # set_multicompany_data
|
|
'set_uom',
|
|
'set_taxes',
|
|
'set_fiscal_position',
|
|
#'setup_journals',
|
|
'set_decimal_price',
|
|
'set_default_values',
|
|
#'set_translations',
|
|
#'set_default_removal_strategy',
|
|
#'default_set_order_policy',
|
|
'update_values',
|
|
#'update_special_values',
|
|
'set_password_for_admin_users',
|
|
'set_sys_params',
|
|
#'setup_reports',
|
|
#'consume_tours',
|
|
'disable_planners',
|
|
'set_admin_rights',
|
|
'load_languages'
|
|
]
|
|
|
|
if cmd == 'setup':
|
|
methods = setup_methods
|
|
|
|
if cmd == 'rollout':
|
|
methods = [
|
|
'login',
|
|
#'set_sequences',
|
|
#'set_dmi_noupdate',
|
|
#'dmi_confirm_inventory',
|
|
#'import_users',
|
|
]
|
|
|
|
if cmd == 'update':
|
|
instance.config.module_name = argv[2:]
|
|
methods = [
|
|
'login',
|
|
'update_module',
|
|
]
|
|
|
|
if cmd == 'install':
|
|
instance.config.module_name = argv[2]
|
|
methods = [
|
|
'login',
|
|
'install_module',
|
|
]
|
|
|
|
if cmd == 'uninstall':
|
|
instance.config.module_name = argv[2]
|
|
methods = [
|
|
'login',
|
|
'uninstall_module',
|
|
]
|
|
|
|
if cmd == 'cancel_upgrade':
|
|
instance.config.module_name = argv[2]
|
|
methods = [
|
|
'login',
|
|
'cancel_upgrade_module',
|
|
]
|
|
|
|
if cmd == 'update_modules':
|
|
methods = [
|
|
'login',
|
|
'update_modules',
|
|
]
|
|
|
|
if cmd == 'update_all':
|
|
methods = [
|
|
'login',
|
|
'update_all',
|
|
]
|
|
|
|
if cmd == 'setup_part':
|
|
if (argv[2] == 'info') or (argv[2] not in setup_methods):
|
|
print('Verfügbare Setup-Schritte:', ', '.join(setup_methods))
|
|
return
|
|
|
|
methods = [
|
|
'login',
|
|
argv[2],
|
|
]
|
|
|
|
if cmd == 'anonym':
|
|
methods = [
|
|
'login',
|
|
'make_anonymous',
|
|
]
|
|
|
|
if cmd == 'invalidate_email':
|
|
methods = [
|
|
'login',
|
|
'invalidate_email',
|
|
]
|
|
|
|
if not methods:
|
|
print('Unbekanntes Kommando')
|
|
_usage()
|
|
|
|
print(env)
|
|
|
|
local_netlocs = [
|
|
'localhost',
|
|
'127.0.0.1',
|
|
'::1',
|
|
]
|
|
netloc = urlparse(env.host).netloc
|
|
if (netloc not in local_netlocs) or (env.pwd is None):
|
|
print('\nAchtung, diese Umgebung ist nicht lokal!\n')
|
|
|
|
print(cmd)
|
|
print(instance.config.module_name if instance.config.module_name else '')
|
|
print()
|
|
|
|
env.pwd = input('Passwort: ')
|
|
|
|
if cmd in ['create','dump','restore']:
|
|
env.super_admin_pw = input('Super-Admin-Passwort: ')
|
|
|
|
print()
|
|
|
|
for method in methods:
|
|
doc = getattr(instance, method).__doc__
|
|
# print(doc)
|
|
sys.stdout.flush()
|
|
res = getattr(instance, method)()
|
|
print('\r%s: %s' % (res and 'OK ' or 'ERROR ', doc))
|
|
if not res:
|
|
print('Abbruch wegen Fehler')
|
|
return
|
|
|
|
print('\nAbgeschlossen.')
|
|
|
|
if __name__ == '__main__':
|
|
main()
|