41
41
from ConfigParser import NoOptionError, NoSectionError
44
TRUE_LIST = (True, 'True', 'true', 'TRUE', 'Yes', 'YES', 'yes')
44
45
def get_lang_list():
45
46
langs = [('en_US', 'English (US)')]
358
359
self.msg = {'message': ustr(_('The option \'%s\' from section \'[%s]\' have to be one of those values: %r. (currently it is \'%s\').') % (option, section, possible_values, value)),
359
360
'title': ustr(_('Wrong option'))}
362
def check_date_time(self, config, section, option, time_format):
363
if not config.has_option(section, option):
365
value = config.get(section, option)
368
time.strptime(value, time_format)
373
def check_datetime(self, config, section, option):
374
if not self.check_date_time(config, section, option, '%Y-%m-%d %H:%M'):
375
self.msg = {'message': ustr(_('The option \'%s\' from section \'[%s]\' datetime format expected YYY-MM-DD HH:MM') % (option, section)),
376
'title': ustr(_('Wrong format'))}
378
def check_time(self, config, section, option):
379
if not self.check_date_time(config, section, option, '%H:%M'):
380
self.msg = {'message': ustr(_('The option \'%s\' from section \'[%s]\' time format expected HH:MM') % (option, section)),
381
'title': ustr(_('Wrong format'))}
361
383
def check_config_file(self, file_path):
363
385
perform some basic checks to avoid crashing later
416
438
('partner', 'external_account_payable'),
417
439
('partner', 'internal_account_receivable'),
418
440
('partner', 'internal_account_payable'),
441
('autosync', 'interval_nb'),
442
('stockmission', 'interval_nb'),
420
444
for section, option in not_empty_int_option_list:
421
445
self.check_mandatory_int(config, section, option)
427
451
('instance', 'instance_level', ('coordo', 'project')),
428
452
('instance', 'lang', ('fr_MF', 'es_MF', 'en_MF')),
429
453
('backup', 'auto_bck_interval_unit', ('minutes', 'hours', 'work_days', 'days', 'weeks', 'months')),
454
('autosync', 'interval_unit', ('minutes', 'hours', 'work_days', 'days', 'weeks', 'months')),
455
('stockmission', 'interval_unit', ('minutes', 'hours', 'work_days', 'days', 'weeks', 'months')),
430
456
('reconfigure', 'delivery_process', ('complex', 'simple')),
432
458
for section, option, possible_values in possible_value_list:
464
('backup', 'auto_bck_next_exec_date', self.check_datetime),
465
('autosync', 'next_exec_date', self.check_datetime),
466
('stockmission', 'next_exec_date', self.check_datetime),
467
('silentupgrade', 'hour_from', self.check_time),
468
('silentupgrade', 'hour_to', self.check_time),
471
for section, option, check_fct in check_format:
472
check_fct(config, section, option)
437
476
if config.get('instance', 'instance_level') == 'project':
438
477
if len(config.get('instance', 'group_names').split(',')) != 3:
504
# silent uprade True only if autosync True
505
if (not config.has_option('silentupgrade', 'active') or config.get('silentupgrade', 'active') in TRUE_LIST) and config.has_option('autosync', 'active') and config.get('autosync', 'active') not in TRUE_LIST:
507
'message': _('Silent Upgrade active value and Autosync active value are not consistent '),
508
'title': _('Auto sync / silent upgrade'),
512
# check date betweens auto patch and sync scheduler
513
if config.has_option('autosync', 'next_exec_date') and config.has_option('silentupgrade', 'hour_to') and config.has_option('silentupgrade', 'hour_from'):
514
if (not config.has_option('autosync', 'active') or config.get('autosync', 'active') in TRUE_LIST) and (not config.has_option('silentupgrade', 'active') or config.get('silentupgrade', 'active') in TRUE_LIST):
515
time_from = time.strptime(config.get('silentupgrade', 'hour_from'), '%H:%M')
516
time_to = time.strptime(config.get('silentupgrade', 'hour_to'), '%H:%M')
517
if not server_rpc.execute('object', 'execute', 'sync.client.sync_server_connection', 'is_automatic_patching_allowed',
518
config.get('autosync', 'next_exec_date'), True, time_from.tm_hour + time_from.tm_min/60. , time_to.tm_hour + time_to.tm_min/60.
521
'message': _('"Scheduler autosync next date" and "Silent Upgrade interval" are not consistent'),
522
'title': _('Auto sync / silent upgrade'),
465
525
config_groups = config.get('instance', 'group_names').split(',')
467
527
groups_ids = server_rpc.execute('object', 'execute', 'sync.server.entity_group', 'search', [('name', 'in', config_groups)])
558
import_path = os.path.join(os.path.dirname(file_path), 'import')
559
if os.path.exists(import_path):
560
for file_name in os.listdir(import_path):
561
if not file_name.endswith('.csv'):
563
'message': 'File to import %s: incorrect name (must end with .csv:' % file_name,
564
'title': 'File name error',
567
import_object = file_name.split('.csv')[0]
568
if not server_rpc.execute('object', 'execute', 'ir.model', 'search', [('model', '=', import_object)]):
570
'message': 'File to import %s: incorrect name object %s does not exist' % (file_name, import_object),
571
'title': 'File name error',
499
576
except NoOptionError as e:
500
577
self.msg = {'message': ustr(_('No option \'%s\' found for the section \'[%s]\' in the config file \'%s\'') % (e.option, e.section, file_path)),