# -*- coding: utf-8 -*- import urlparse import sys from config_at import Config from environments import ENVIRONMENTS, Environment from functions import CamadeusFunctions def main(): def _usage(): print 'cam.py [create|setup|rollout|update] []' print 'cam.py list-envs' sys.exit(3) argv = sys.argv[1:] config = Config() if not argv: _usage() # RUNBOT # ./cam 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 ['update', 'install']: # 'update' requires additional param 'module_name' pass else: _usage() cmd = argv[1] env = ENVIRONMENTS.get(argv[0]) if not env: print 'Unbekannte Umgebung' _usage() instance = CamadeusFunctions(env, config) methods = None if cmd == 'test': methods = [ 'login', ] if cmd == 'create': methods = [ 'create_db', 'login', 'install_module_sale', 'setup_accounting', 'setup_accounting2', 'set_admin_rights', ] if cmd == 'setup': methods = [ 'login', 'uninstall_chat', 'install_modules', 'set_warehouse', 'base_config', 'sale_config', 'hr_config', 'stock_config', 'mrp_config', 'stock_set_cost_method', 'set_incoterms', 'purchase_config', 'set_date_format', 'set_company', 'set_taxes', 'set_uom', 'set_steuerzuordnung', 'setup_journals', 'set_currencies', 'set_decimal_price', 'set_default_values', 'set_translations', 'set_default_removal_strategy', 'default_set_order_policy', 'delete_mail_server', 'update_values', 'set_sys_params', 'setup_reports', ] if cmd == 'rollout': methods = [ 'login', 'set_dokumentennummern', '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 == 'update_modules': methods = [ 'login', 'update_modules', ] if cmd == 'update_all': methods = [ 'login', 'update_all', ] if not methods: print 'Unbekanntes Kommando' _usage() print env local_netlocs = [ 'localhost', '127.0.0.1', '::1', ] netloc = urlparse.urlparse(env.host).netloc if netloc not in local_netlocs: print '\nAchtung, diese Umgebung ist nicht lokal!\n' print cmd, print instance.config.module_name if instance.config.module_name else '' print env.pwd = raw_input('Passwort: ') if cmd == 'create': env.super_admin_pw = raw_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()