[FIX] correct stripping of arguments when _reexec() OpenERP
bzr revid: chs@openerp.com-20130612151912-m19okjsdkjo12qnt
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||
# Copyright (C) 2010-2012 OpenERP SA (<http://www.openerp.com>)
|
||||
# Copyright (C) 2010-2013 OpenERP SA (<http://www.openerp.com>)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
@@ -39,6 +39,7 @@ import openerp.netsvc
|
||||
import openerp.osv
|
||||
from openerp.release import nt_service_name
|
||||
import openerp.tools
|
||||
from openerp.tools.misc import stripped_sys_argv
|
||||
|
||||
#.apidoc title: RPC Services
|
||||
|
||||
@@ -132,9 +133,7 @@ def _reexec():
|
||||
if openerp.tools.osutil.is_running_as_nt_service():
|
||||
subprocess.call('net stop {0} && net start {0}'.format(nt_service_name), shell=True)
|
||||
exe = os.path.basename(sys.executable)
|
||||
strip_args = ['-d', '-u']
|
||||
a = sys.argv[:]
|
||||
args = [x for i, x in enumerate(a) if x not in strip_args and a[max(i - 1, 0)] not in strip_args]
|
||||
args = stripped_sys_argv()
|
||||
if not args or args[0] != exe:
|
||||
args.insert(0, exe)
|
||||
os.execv(sys.executable, args)
|
||||
|
||||
+20
-2
@@ -3,7 +3,7 @@
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||
# Copyright (C) 2010-2012 OpenERP s.a. (<http://openerp.com>).
|
||||
# Copyright (C) 2010-2013 OpenERP s.a. (<http://openerp.com>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
@@ -38,7 +38,7 @@ import time
|
||||
import zipfile
|
||||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
from itertools import islice, izip
|
||||
from itertools import islice, izip, groupby
|
||||
from lxml import etree
|
||||
from which import which
|
||||
from threading import local
|
||||
@@ -1075,4 +1075,22 @@ class CountingStream(object):
|
||||
raise StopIteration()
|
||||
return val
|
||||
|
||||
def stripped_sys_argv(*strip_args):
|
||||
"""Return sys.argv with some arguments stripped, suitable for reexecution or subprocesses"""
|
||||
strip_args = sorted(set(strip_args) | set(['-s', '--save', '-d', '--database', '-u', '--update', '-i', '--init']))
|
||||
assert all(config.parser.has_option(s) for s in strip_args)
|
||||
takes_value = dict((s, config.parser.get_option(s).takes_value()) for s in strip_args)
|
||||
|
||||
longs, shorts = list(tuple(y) for _, y in groupby(strip_args, lambda x: x.startswith('--')))
|
||||
longs_eq = tuple(l + '=' for l in longs if takes_value[l])
|
||||
|
||||
args = sys.argv[:]
|
||||
|
||||
def strip(args, i):
|
||||
return args[i].startswith(shorts) \
|
||||
or args[i].startswith(longs_eq) or (args[i] in longs) \
|
||||
or (i >= 1 and (args[i - 1] in strip_args) and takes_value[args[i - 1]])
|
||||
|
||||
return [x for i, x in enumerate(args) if not strip(args, i)]
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
Reference in New Issue
Block a user