def execute(self, options): ''' Execute update or remove command ''' start_time = datetime.datetime.now() start_time = time.mktime(start_time.timetuple()) is_ok = None is_updated = False action = None try: options.no_log = False if options.update: action = 'update' self.__start_action(options.bank, action) bmaj = Bank(options.bank, options) self.logger.debug('Log file: ' + bmaj.config.log_file) is_ok = bmaj.update(depends=True) is_updated = bmaj.session.get('update') Notify.notifyBankAction(bmaj) self.__end_action() elif options.remove or options.removeall: action = 'remove' self.__start_action(options.bank, action) if options.removeall: bmaj = Bank(options.bank, options, no_log=True) print('Log file: ' + bmaj.config.log_file) is_ok = bmaj.removeAll(options.force) else: bmaj = Bank(options.bank, options) self.logger.debug('Log file: ' + bmaj.config.log_file) is_ok = bmaj.remove(options.release) Notify.notifyBankAction(bmaj) self.__end_action() elif options.removepending: bmaj = Bank(options.bank, options, no_log=True) bmaj.remove_pending(options.release) elif options.repair: action = 'repair' self.__start_action(options.bank, action) bmaj = Bank(options.bank, options) self.logger.debug('Log file: ' + bmaj.config.log_file) is_ok = bmaj.repair() is_updated = bmaj.session.get('update') Notify.notifyBankAction(bmaj) self.__end_action() except Exception as e: self.logger.exception('Exception: ' + str(e)) is_ok = False end_time = datetime.datetime.now() end_time = time.mktime(end_time.timetuple()) execution_time = end_time - start_time return { 'error': not is_ok, 'execution_time': execution_time, 'action': action, 'updated': is_updated }
def biomaj_bank_repair(options, config): ''' Repair a bank ''' if not options.bank: return (False, "Bank name is missing") banks = options.bank.split(',') gres = True msg = '' for bank in banks: options.bank = bank no_log = True if not options.proxy: no_log = False # logging.debug('Options: '+str(options.__dict__)) bmaj = Bank(bank, options=options, no_log=no_log) check_status = bmaj.check() if not check_status: msg += 'Skip bank ' + options.bank + ': wrong config\n' gres = False continue else: msg += 'Bank repair request sent for ' + options.bank + '\n' if not options.proxy: res = bmaj.repair() Notify.notifyBankAction(bmaj) else: res = biomaj_bank_repair_request(options, config) if not res: msg += 'Failed to send repair request for ' + options.bank + '\n' gres = False if not gres: return (False, msg) return (True, msg)