Merge update and init options and improve help message
- deprecates the init option - replace the keyword "all" by an option "--all" - rename debug into dev like in the client issue4165 review7571003
This commit is contained in:
+13
-10
@@ -21,23 +21,26 @@ def parse_commandline():
|
||||
|
||||
parser.add_argument('--version', action='version',
|
||||
version='%(prog)s ' + VERSION)
|
||||
parser.add_argument("-c", "--config", dest="configfile",
|
||||
parser.add_argument("-c", "--config", dest="configfile", metavar='FILE',
|
||||
help="specify config file")
|
||||
parser.add_argument('--debug', dest='debug', action='store_true',
|
||||
help='enable debug mode')
|
||||
parser.add_argument('--dev', dest='dev', action='store_true',
|
||||
help='enable development mode')
|
||||
parser.add_argument("-v", "--verbose", action="store_true",
|
||||
dest="verbose", help="enable verbose mode")
|
||||
|
||||
parser.add_argument("-d", "--database", dest="database_names", nargs='+',
|
||||
default=[], help="specify the database name")
|
||||
parser.add_argument("-i", "--init", dest="init", nargs='+', default=[],
|
||||
help="init a module (use \"all\" for all modules)")
|
||||
default=[], metavar='DATABASE', help="specify the database name")
|
||||
parser.add_argument("-u", "--update", dest="update", nargs='+', default=[],
|
||||
help="update a module (use \"all\" for all modules)")
|
||||
metavar='MODULE', help="update a module")
|
||||
parser.add_argument("-i", "--init", dest="update", nargs='+',
|
||||
action="append", metavar='MODULE',
|
||||
help="init a module (deprecated use --update)")
|
||||
parser.add_argument("--all", dest="update", action="append_const",
|
||||
const="ir", help="update all installed modules")
|
||||
|
||||
parser.add_argument("--pidfile", dest="pidfile",
|
||||
parser.add_argument("--pidfile", dest="pidfile", metavar='FILE',
|
||||
help="file where the server pid will be stored")
|
||||
parser.add_argument("--logconf", dest="logconf",
|
||||
parser.add_argument("--logconf", dest="logconf", metavar='FILE',
|
||||
help="logging configuration file (ConfigParser format)")
|
||||
parser.add_argument("--cron", dest="cron", action="store_true",
|
||||
help="enable cron")
|
||||
@@ -52,7 +55,7 @@ def parse_commandline():
|
||||
|
||||
options = parser.parse_args()
|
||||
|
||||
if not options.database_names and bool(options.init or options.update):
|
||||
if not options.database_names and options.update:
|
||||
parser.error('Missing database option')
|
||||
return options
|
||||
|
||||
|
||||
@@ -152,11 +152,7 @@ def create_graph(module_list):
|
||||
packages = []
|
||||
|
||||
for module in module_list:
|
||||
try:
|
||||
info = get_module_info(module)
|
||||
except IOError:
|
||||
if module != 'all':
|
||||
raise Exception('Module %s not found' % module)
|
||||
info = get_module_info(module)
|
||||
packages.append((module, info.get('depends', []),
|
||||
info.get('extras_depend', []), info))
|
||||
|
||||
@@ -194,7 +190,7 @@ def create_graph(module_list):
|
||||
|
||||
|
||||
def is_module_to_install(module, update):
|
||||
if 'all' in update and module != 'tests':
|
||||
if module != 'tests':
|
||||
return True
|
||||
elif module in update:
|
||||
return True
|
||||
@@ -373,13 +369,9 @@ def load_modules(database_name, pool, update=None, lang=None):
|
||||
# Migration from 2.2: workflow module removed
|
||||
cursor.execute(*ir_module.delete(
|
||||
where=(ir_module.name == 'workflow')))
|
||||
if 'all' in update:
|
||||
cursor.execute(*ir_module.select(ir_module.name,
|
||||
where=(ir_module.name != 'tests')))
|
||||
else:
|
||||
cursor.execute(*ir_module.select(ir_module.name,
|
||||
where=ir_module.state.in_(('installed', 'to install',
|
||||
'to upgrade', 'to remove'))))
|
||||
cursor.execute(*ir_module.select(ir_module.name,
|
||||
where=ir_module.state.in_(('installed', 'to install',
|
||||
'to upgrade', 'to remove'))))
|
||||
else:
|
||||
cursor.execute(*ir_module.select(ir_module.name,
|
||||
where=ir_module.state.in_(('installed', 'to upgrade',
|
||||
|
||||
+6
-7
@@ -51,7 +51,6 @@ class TrytonServer(object):
|
||||
|
||||
def run(self):
|
||||
"Run the server and never return"
|
||||
update = self.options.init + self.options.update
|
||||
init = {}
|
||||
|
||||
signal.signal(signal.SIGINT, lambda *a: self.stop())
|
||||
@@ -65,14 +64,14 @@ class TrytonServer(object):
|
||||
with open(self.options.pidfile, 'w') as fd_pid:
|
||||
fd_pid.write("%d" % (os.getpid()))
|
||||
|
||||
if not update:
|
||||
if not self.options.update:
|
||||
self.start_servers()
|
||||
|
||||
for db_name in self.options.database_names:
|
||||
init[db_name] = False
|
||||
with Transaction().start(db_name, 0) as transaction:
|
||||
cursor = transaction.cursor
|
||||
if self.options.init:
|
||||
if self.options.update:
|
||||
if not cursor.test():
|
||||
self.logger.info("init db")
|
||||
backend.get('Database').init(cursor)
|
||||
@@ -82,7 +81,7 @@ class TrytonServer(object):
|
||||
raise Exception("'%s' is not a Tryton database!" % db_name)
|
||||
|
||||
for db_name in self.options.database_names:
|
||||
if update:
|
||||
if self.options.update:
|
||||
with Transaction().start(db_name, 0) as transaction:
|
||||
cursor = transaction.cursor
|
||||
if not cursor.test():
|
||||
@@ -93,7 +92,7 @@ class TrytonServer(object):
|
||||
lang = [x[0] for x in cursor.fetchall()]
|
||||
else:
|
||||
lang = None
|
||||
Pool(db_name).init(update=update, lang=lang)
|
||||
Pool(db_name).init(update=self.options.update, lang=lang)
|
||||
|
||||
for db_name in self.options.database_names:
|
||||
if init[db_name]:
|
||||
@@ -131,7 +130,7 @@ class TrytonServer(object):
|
||||
})
|
||||
transaction.cursor.commit()
|
||||
|
||||
if update:
|
||||
if self.options.update:
|
||||
self.logger.info('Update/Init succeed!')
|
||||
logging.shutdown()
|
||||
sys.exit(0)
|
||||
@@ -157,7 +156,7 @@ class TrytonServer(object):
|
||||
args=(dbname,), kwargs={})
|
||||
thread.start()
|
||||
threads[dbname] = thread
|
||||
if self.options.debug:
|
||||
if self.options.dev:
|
||||
for _ in range(60):
|
||||
if monitor():
|
||||
self.restart()
|
||||
|
||||
Reference in New Issue
Block a user