Added --force to odoo deploy
Will force --init mode even if module is already installed
This commit is contained in:
parent
97a5c043b5
commit
c1e6e70870
|
@ -34,6 +34,7 @@ class ImportModule(Controller):
|
||||||
|
|
||||||
@route('/base_import_module/upload', type='http', auth='user', methods=['POST'])
|
@route('/base_import_module/upload', type='http', auth='user', methods=['POST'])
|
||||||
@webservice
|
@webservice
|
||||||
def upload(self, mod_file=None, **kw):
|
def upload(self, mod_file=None, force='', **kw):
|
||||||
self.check_user()
|
self.check_user()
|
||||||
return request.registry['ir.module.module'].import_zipfile(request.cr, request.uid, mod_file, context=request.context)[0]
|
force = True if force == '1' else False
|
||||||
|
return request.registry['ir.module.module'].import_zipfile(request.cr, request.uid, mod_file, force=force, context=request.context)[0]
|
||||||
|
|
|
@ -12,10 +12,12 @@ class base_import_module(osv.TransientModel):
|
||||||
'module_file': fields.binary('Module .ZIP file', required=True),
|
'module_file': fields.binary('Module .ZIP file', required=True),
|
||||||
'state':fields.selection([('init','init'),('done','done')], 'Status', readonly=True),
|
'state':fields.selection([('init','init'),('done','done')], 'Status', readonly=True),
|
||||||
'import_message': fields.char('Import message'),
|
'import_message': fields.char('Import message'),
|
||||||
|
'force': fields.boolean('Force init', help="Force init mode even if installed. (will update `noupdate='1'` records)"),
|
||||||
}
|
}
|
||||||
|
|
||||||
_defaults = {
|
_defaults = {
|
||||||
'state': 'init',
|
'state': 'init',
|
||||||
|
'force': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
def import_module(self, cr, uid, ids, context=None):
|
def import_module(self, cr, uid, ids, context=None):
|
||||||
|
@ -24,7 +26,7 @@ class base_import_module(osv.TransientModel):
|
||||||
zip_data = base64.decodestring(data.module_file)
|
zip_data = base64.decodestring(data.module_file)
|
||||||
fp = BytesIO()
|
fp = BytesIO()
|
||||||
fp.write(zip_data)
|
fp.write(zip_data)
|
||||||
res = module_obj.import_zipfile(cr, uid, fp, context=context)
|
res = module_obj.import_zipfile(cr, uid, fp, force=data.force, context=context)
|
||||||
self.write(cr, uid, ids, {'state': 'done', 'import_message': res[0]}, context=context)
|
self.write(cr, uid, ids, {'state': 'done', 'import_message': res[0]}, context=context)
|
||||||
context = dict(context, module_name=res[1])
|
context = dict(context, module_name=res[1])
|
||||||
# Return wizard otherwise it will close wizard and will not show result message to user.
|
# Return wizard otherwise it will close wizard and will not show result message to user.
|
||||||
|
|
|
@ -16,7 +16,7 @@ MAX_FILE_SIZE = 100 * 1024 * 1024 # in megabytes
|
||||||
class view(osv.osv):
|
class view(osv.osv):
|
||||||
_inherit = "ir.module.module"
|
_inherit = "ir.module.module"
|
||||||
|
|
||||||
def import_module(self, cr, uid, module, path, context=None):
|
def import_module(self, cr, uid, module, path, force=False, context=None):
|
||||||
known_mods = self.browse(cr, uid, self.search(cr, uid, []))
|
known_mods = self.browse(cr, uid, self.search(cr, uid, []))
|
||||||
known_mods_names = dict([(m.name, m) for m in known_mods])
|
known_mods_names = dict([(m.name, m) for m in known_mods])
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class view(osv.osv):
|
||||||
|
|
||||||
if mod:
|
if mod:
|
||||||
self.write(cr, uid, mod.id, values)
|
self.write(cr, uid, mod.id, values)
|
||||||
mode = 'update'
|
mode = 'update' if not force else 'init'
|
||||||
else:
|
else:
|
||||||
assert terp.get('installable', True), "Module not installable"
|
assert terp.get('installable', True), "Module not installable"
|
||||||
self.create(cr, uid, dict(name=module, state='uninstalled', **values))
|
self.create(cr, uid, dict(name=module, state='uninstalled', **values))
|
||||||
|
@ -73,7 +73,7 @@ class view(osv.osv):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def import_zipfile(self, cr, uid, module_file, context=None):
|
def import_zipfile(self, cr, uid, module_file, force=False, context=None):
|
||||||
if not module_file:
|
if not module_file:
|
||||||
raise Exception("No file sent.")
|
raise Exception("No file sent.")
|
||||||
if not zipfile.is_zipfile(module_file):
|
if not zipfile.is_zipfile(module_file):
|
||||||
|
@ -95,7 +95,7 @@ class view(osv.osv):
|
||||||
try:
|
try:
|
||||||
# assert mod_name.startswith('theme_')
|
# assert mod_name.startswith('theme_')
|
||||||
path = opj(module_dir, mod_name)
|
path = opj(module_dir, mod_name)
|
||||||
self.import_module(cr, uid, mod_name, path, context=context)
|
self.import_module(cr, uid, mod_name, path, force=force, context=context)
|
||||||
success.append(mod_name)
|
success.append(mod_name)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
errors[mod_name] = str(e)
|
errors[mod_name] = str(e)
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
<group states="init" col="4">
|
<group states="init" col="4">
|
||||||
<label string="Select module package to import (.zip file):" colspan="4"/>
|
<label string="Select module package to import (.zip file):" colspan="4"/>
|
||||||
<field name="module_file" colspan="4"/>
|
<field name="module_file" colspan="4"/>
|
||||||
|
|
||||||
|
<field name="force"/>
|
||||||
</group>
|
</group>
|
||||||
<group states="done" col="4">
|
<group states="done" col="4">
|
||||||
<field name="import_message" colspan="4" nolabel="1" readonly="1"/>
|
<field name="import_message" colspan="4" nolabel="1" readonly="1"/>
|
||||||
|
|
|
@ -15,20 +15,21 @@ class Deploy(Command):
|
||||||
super(Deploy, self).__init__()
|
super(Deploy, self).__init__()
|
||||||
self.session = requests.session()
|
self.session = requests.session()
|
||||||
|
|
||||||
def deploy_module(self, module_path, url, login, password, db=''):
|
def deploy_module(self, module_path, url, login, password, db='', force=False):
|
||||||
url = url.rstrip('/')
|
url = url.rstrip('/')
|
||||||
self.authenticate(url, login, password, db)
|
self.authenticate(url, login, password, db)
|
||||||
module_file = self.zip_module(module_path)
|
module_file = self.zip_module(module_path)
|
||||||
try:
|
try:
|
||||||
return self.upload_module(url, module_file)
|
return self.upload_module(url, module_file, force=force)
|
||||||
finally:
|
finally:
|
||||||
os.remove(module_file)
|
os.remove(module_file)
|
||||||
|
|
||||||
def upload_module(self, server, module_file):
|
def upload_module(self, server, module_file, force=False):
|
||||||
print("Uploading module file...")
|
print("Uploading module file...")
|
||||||
url = server + '/base_import_module/upload'
|
url = server + '/base_import_module/upload'
|
||||||
files = dict(mod_file=open(module_file, 'rb'))
|
files = dict(mod_file=open(module_file, 'rb'))
|
||||||
res = self.session.post(url, files=files)
|
force = '1' if force else ''
|
||||||
|
res = self.session.post(url, files=files, data=dict(force=force))
|
||||||
if res.status_code != 200:
|
if res.status_code != 200:
|
||||||
raise Exception("Could not authenticate on server '%s'" % server)
|
raise Exception("Could not authenticate on server '%s'" % server)
|
||||||
return res.text
|
return res.text
|
||||||
|
@ -75,6 +76,7 @@ class Deploy(Command):
|
||||||
parser.add_argument('--login', dest='login', default="admin", help='Login (default=admin)')
|
parser.add_argument('--login', dest='login', default="admin", help='Login (default=admin)')
|
||||||
parser.add_argument('--password', dest='password', default="admin", help='Password (default=admin)')
|
parser.add_argument('--password', dest='password', default="admin", help='Password (default=admin)')
|
||||||
parser.add_argument('--verify-ssl', action='store_true', help='Verify SSL certificate')
|
parser.add_argument('--verify-ssl', action='store_true', help='Verify SSL certificate')
|
||||||
|
parser.add_argument('--force', action='store_true', help='Force init even if module is already installed. (will update `noupdate="1"` records)')
|
||||||
if not cmdargs:
|
if not cmdargs:
|
||||||
sys.exit(parser.print_help())
|
sys.exit(parser.print_help())
|
||||||
|
|
||||||
|
@ -86,7 +88,7 @@ class Deploy(Command):
|
||||||
try:
|
try:
|
||||||
if not args.url.startswith(('http://', 'https://')):
|
if not args.url.startswith(('http://', 'https://')):
|
||||||
args.url = 'https://%s' % args.url
|
args.url = 'https://%s' % args.url
|
||||||
result = self.deploy_module(args.path, args.url, args.login, args.password, args.db)
|
result = self.deploy_module(args.path, args.url, args.login, args.password, args.db, force=args.force)
|
||||||
print(result)
|
print(result)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
sys.exit("ERROR: %s" % e)
|
sys.exit("ERROR: %s" % e)
|
||||||
|
|
Loading…
Reference in New Issue