def execute(datas): result = {} for p in plugins_repository: if not 'model_re' in plugins_repository[p]: plugins_repository[p]['model_re'] = re.compile(plugins_repository[p]['model']) res = plugins_repository[p]['model_re'].search(datas['model']) if res: result[plugins_repository[p]['string']] = p if not len(result): common.message(_('No available plugin for this resource !')) return False sel = common.selection(_('Choose a Plugin'), result, alwaysask=True) if sel: plugins_repository[sel[1]]['action'](datas) return True
def execute(datas): result = {} for p in plugins_repository: if not 'model_re' in plugins_repository[p]: plugins_repository[p]['model_re'] = re.compile( plugins_repository[p]['model']) res = plugins_repository[p]['model_re'].search(datas['model']) if res: result[plugins_repository[p]['string']] = p if not len(result): common.message(_('No available plugin for this resource !')) return False sel = common.selection(_('Choose a Plugin'), result, alwaysask=True) if sel: plugins_repository[sel[1]]['action'](datas) return True
class main(service.Service): def __init__(self, name='action.main'): service.Service.__init__(self, name) def exec_report(self, name, data, context={}): datas = data.copy() ids = datas['ids'] del datas['ids'] if not ids: ids = rpc.session.rpc_exec_auth('/object', 'execute', datas['model'], 'search', []) if ids == []: common.message(_('Nothing to print!')) return False datas['id'] = ids[0] ctx = rpc.session.context.copy() ctx.update(context) report_id = rpc.session.rpc_exec_auth('/report', 'report', name, ids, datas, ctx) state = False attempt = 0 max_attemps = int(options.options.get('client.timeout') or 0) while not state: val = rpc.session.rpc_exec_auth('/report', 'report_get', report_id) if not val: return False state = val['state'] if not state: time.sleep(1) attempt += 1 if attempt > max_attemps: common.message(_('Printing aborted, too long delay !')) return False printer.print_data(val) return True def execute(self, act_id, datas, type=None, context={}): act_id = int(act_id) ctx = rpc.session.context.copy() ctx.update(context) if type is None: res = rpc.session.rpc_exec_auth('/object', 'execute', 'ir.actions.actions', 'read', int(act_id), ['type'], ctx) if not (res and len(res)): raise Exception, 'ActionNotFound' type = res['type'] res = rpc.session.rpc_exec_auth('/object', 'execute', type, 'read', act_id, False, ctx) self._exec_action(res, datas, context) def _exec_action(self, action, datas, context={}): if isinstance(action, bool) or 'type' not in action: return # Update context, adding the dynamic context of the action context.update( tools.expr_eval(action.get('context', '{}'), context.copy())) if action['type'] == 'ir.actions.act_window': for key in ('res_id', 'res_model', 'view_type', 'view_mode', 'limit', 'auto_refresh'): datas[key] = action.get(key, datas.get(key, None)) if datas['limit'] is None or datas['limit'] == 0: datas['limit'] = 80 view_ids = False if action.get('views', []): if isinstance(action['views'], list): view_ids = [x[0] for x in action['views']] datas['view_mode'] = ",".join( [x[1] for x in action['views']]) else: # view_ids=[(action['view_type']=='tree') and 1 or False,(action['view_type']=='form') and 1 or False] if action.get('view_id', False): view_ids = [action['view_id'][0]] elif action.get('view_id', False): view_ids = [action['view_id'][0]] if not action.get('domain', False): action['domain'] = '[]' ctx = context.copy() ctx.update({ 'active_id': datas.get('id', False), 'active_ids': datas.get('ids', []) }) ctx.update(tools.expr_eval(action.get('context', '{}'), ctx.copy())) a = ctx.copy() a['time'] = time a['datetime'] = datetime domain = tools.expr_eval(action['domain'], a) if datas.get('domain', False): domain.append(datas['domain']) if action.get('target', False) == 'new': dia = dialog(datas['res_model'], id=datas.get('res_id', None), window=datas.get('window', None), domain=domain, context=ctx, view_ids=view_ids, target=True, view_type=datas.get('view_mode', 'tree').split(',')) if dia.dia.get_has_separator(): dia.dia.set_has_separator(False) dia.run() dia.destroy() else: obj = service.LocalService('gui.window') obj.create(view_ids, datas['res_model'], datas['res_id'], domain, action['view_type'], datas.get('window', None), ctx, datas['view_mode'], name=action.get('name', False), limit=datas['limit'], auto_refresh=datas['auto_refresh']) elif action['type'] == 'ir.actions.server': ctx = context.copy() ctx.update({ 'active_id': datas.get('id', False), 'active_ids': datas.get('ids', []) }) res = rpc.session.rpc_exec_auth('/object', 'execute', 'ir.actions.server', 'run', [action['id']], ctx) if res: if not isinstance(res, list): res = [res] for r in res: self._exec_action(r, datas, context) elif action['type'] == 'ir.actions.wizard': win = None if 'window' in datas: win = datas['window'] del datas['window'] wizard.execute(action['wiz_name'], datas, parent=win, context=context) elif action['type'] == 'ir.actions.report.custom': if 'window' in datas: win = datas['window'] del datas['window'] datas.update(action.get('datas', {})) datas['report_id'] = action['report_id'] self.exec_report('custom', datas, context) elif action['type'] == 'ir.actions.report.xml': if 'window' in datas: win = datas['window'] del datas['window'] datas.update(action.get('datas', {})) self.exec_report(action['report_name'], datas, context) elif action['type'] == 'ir.actions.act_url': tools.launch_browser(action.get('url', '')) def exec_keyword(self, keyword, data={}, adds={}, context={}, warning=True): actions = None if 'id' in data: try: id = data.get('id', False) actions = rpc.session.rpc_exec_auth('/object', 'execute', 'ir.values', 'get', 'action', keyword, [(data['model'], id)], False, rpc.session.context) actions = map(lambda x: x[2], actions) except rpc.rpc_exception, e: # common.error(_('Error: ')+str(e.type), e.message, e.data) return False keyact = {} for action in actions: keyact[action['name'].encode('utf8')] = action keyact.update(adds) res = common.selection(_('Select your action'), keyact) if res: (name, action) = res self._exec_action(action, data, context=context) return (name, action) return False
strLayer = 'tmp_i095' relLayer = 'tmp_i043' with common.runtool(7) as parameters: interLayer, strengthFld, lengthFld, minStrengthStr, minRelStrengthStr, maxLengthStr, output = parameters if minStrengthStr or maxLengthStr: queries = [] if minStrengthStr: common.progress('assembling absolute strength exclusion') minStrength = common.toFloat(minStrengthStr, 'minimum absolute interaction strength') queries.append(common.query(interLayer, '[%s] >= %g', strengthFld, minStrength)) if maxLengthStr: common.progress('assembling absolute length exclusion') maxLength = common.toFloat(maxLengthStr, 'maximum absolute interaction length') queries.append(common.query(interLayer, '[%s] <= %g', lengthFld, maxLength)) common.selection(interLayer, strLayer, ' OR '.join(queries)) else: strLayer = interLayer if minRelStrengthStr: common.progress('performing relative strength exclusion') minRelStrength = common.toFloat(minRelStrengthStr, 'minimum relative interaction strength') relQuery = common.query(interLayer, '[%s] > 0 AND ([%s] / [%s] * 1000) >= %g', lengthFld, strengthFld, lengthFld, minRelStrength) common.select(strLayer, relLayer, relQuery) else: relLayer = strLayer common.progress('counting selected interactions') common.message('%i interactions selected.' % common.count(relLayer)) common.progress('writing output') common.copy(relLayer, output)
if regDict['id'] in coreIDs: coreIDs.remove(regDict['id']) coreIDs.insert(0, regDict['id']) for nameFld in nameFlds: regDict[nameFld] = [] for regid in coreIDs: regDict[nameFld].append(zoneData[regid][nameFld]) regDict[nameFld] = u'-'.join(unicode(name if isinstance(name, str) else str(name), 'utf8') for name in regDict[nameFld]) del regDict['coreids'] print regionData ## DISSOLVE # whole region statstics # allStats = createStats(sumAllFlds, idFld, [], common.toBool(countAll, 'zone count switch')) common.progress('selecting regions') common.selection(zones, ASSIGNED, '{} IS NOT NULL'.format(regionFld)) # exclude unassigned common.progress('dissolving') arcpy.Dissolve_management(ASSIGNED, outPath, [regionFld]) # and update # create slots outSlots = {fld : fld for fld in regTransFlds + nameFlds + outSumFlds} if countCores: outSlots['CORE_COUNT'] = 'CORE_COUNT' if countAll: outSlots['ALL_COUNT'] = 'ALL_COUNT' # outSlots.update(coreTrans) # outSlots.update(allTrans) # common.debug(outSlots, coreTrans, allTrans, regTransFlds, nameFlds) loaders.ObjectMarker(outPath, {'id' : regionFld}, outSlots, outTypes=loaders.inferFieldTypes(regionData.values(), outSlots)).mark(regionData, 'writing names and statistics')
class main(service.Service): def __init__(self, name='action.main'): service.Service.__init__(self, name) def exec_report(self, name, data, context={}): datas = data.copy() ids = datas['ids'] del datas['ids'] if not ids: ids = rpc.session.rpc_exec_auth('/object', 'execute', datas['model'], 'search', datas.get('_domain', [])) if ids == []: common.message(_('Nothing to print!')) return False datas['id'] = ids[0] ctx = rpc.session.context.copy() ctx.update(context) report_id = rpc.session.rpc_exec_auth('/report', 'report', name, ids, datas, ctx) state = False attempt = 0 max_attemps = int(options.options.get('client.timeout') or 0) while not state: val = rpc.session.rpc_exec_auth('/report', 'report_get', report_id) if not val: return False state = val['state'] if not state: time.sleep(1) attempt += 1 if attempt > max_attemps: common.message(_('Printing aborted, too long delay !')) return False printer.print_data(val) return True def execute(self, act_id, datas, type=None, context={}): act_id = int(act_id) ctx = rpc.session.context.copy() ctx.update(context) if type is None: res = rpc.session.rpc_exec_auth('/object', 'execute', 'ir.actions.actions', 'read', int(act_id), ['type'], ctx) if not (res and len(res)): raise Exception, 'ActionNotFound' type = res['type'] if type == 'ir.actions.report.xml': # avoid reading large binary values that we won't even care about ctx['bin_size'] = True res = rpc.session.rpc_exec_auth('/object', 'execute', type, 'read', act_id, False, ctx) self._exec_action(res, datas, context) def _exec_action(self, action, datas, context={}): if isinstance(action, bool) or 'type' not in action: return # Updating the context : Adding the context of action in order to use it on Views called from buttons if datas.get('id', False): context.update({ 'active_id': datas.get('id', False), 'active_ids': datas.get('ids', []), 'active_model': datas.get('model', False) }) context.update( tools.expr_eval(action.get('context', '{}'), context.copy())) if action['type'] in ['ir.actions.act_window', 'ir.actions.submenu']: for key in ('res_id', 'res_model', 'view_type', 'view_mode', 'limit', 'auto_refresh', 'search_view', 'auto_search', 'search_view_id'): datas[key] = action.get(key, datas.get(key, None)) datas['auto_search'] = action.get('auto_search', True) if not datas['search_view'] and datas['search_view_id']: datas['search_view'] = str( rpc.session.rpc_exec_auth( '/object', 'execute', datas['res_model'], 'fields_view_get', isinstance(datas['search_view_id'], (tuple, list)) and datas['search_view_id'][0] or datas['search_view_id'], 'search', context)) if datas['limit'] is None or datas['limit'] == 0: datas['limit'] = 100 view_ids = False if action.get('views', []): if isinstance(action['views'], list): view_ids = [x[0] for x in action['views']] datas['view_mode'] = ",".join( [x[1] for x in action['views']]) else: if action.get('view_id', False): view_ids = [action['view_id'][0]] elif action.get('view_id', False): view_ids = [action['view_id'][0]] if not action.get('domain', False): action['domain'] = '[]' domain_ctx = context.copy() domain_ctx['time'] = time domain_ctx['datetime'] = datetime domain = tools.expr_eval(action['domain'], domain_ctx) help = {} if action.get('display_menu_tip', False): msg = action.get('help', False) title = action.get('name', False) if msg and len(msg): help['msg'] = msg help['title'] = title or '' if datas.get('domain', False): domain.append(datas['domain']) if action.get('target', False) == 'new': dia = dialog(datas['res_model'], id=datas.get('res_id', None), window=datas.get('window', None), domain=domain, context=context, view_ids=view_ids, target=True, view_type=datas.get('view_mode', 'tree').split(','), help=help) if dia.dia.get_has_separator(): dia.dia.set_has_separator(False) dia.run() dia.destroy() else: obj = service.LocalService('gui.window') obj.create(view_ids, datas['res_model'], datas['res_id'], domain, action['view_type'], datas.get('window', None), context, datas['view_mode'], name=action.get('name', False), help=help, limit=datas['limit'], auto_refresh=datas['auto_refresh'], auto_search=datas['auto_search'], search_view=datas['search_view']) elif action['type'] == 'ir.actions.server': res = rpc.session.rpc_exec_auth('/object', 'execute', 'ir.actions.server', 'run', [action['id']], context) if res: if not isinstance(res, list): res = [res] for r in res: self._exec_action(r, datas, context) elif action['type'] == 'ir.actions.wizard': win = None if 'window' in datas: win = datas['window'] del datas['window'] wizard.execute(action['wiz_name'], datas, parent=win, context=context) elif action['type'] == 'ir.actions.report.custom': if 'window' in datas: win = datas['window'] del datas['window'] datas['report_id'] = action['report_id'] self.exec_report('custom', datas, context) elif action['type'] == 'ir.actions.report.xml': if 'window' in datas: win = datas['window'] del datas['window'] if not datas: datas = action.get('datas', []) self.exec_report(action['report_name'], datas, context) elif action['type'] == 'ir.actions.act_url': tools.launch_browser(action.get('url', '')) def exec_keyword(self, keyword, data={}, adds={}, context={}, warning=True): actions = None if 'id' in data: try: id = data.get('id', False) actions = rpc.session.rpc_exec_auth('/object', 'execute', 'ir.values', 'get', 'action', keyword, [(data['model'], id)], False, rpc.session.context) actions = map(lambda x: x[2], actions) except rpc.rpc_exception, e: # common.error(_('Error: ')+str(e.type), e.message, e.data) return False keyact = {} for action in actions: action_name = action.get('name') or '' keyact[action_name.encode('utf8')] = action keyact.update(adds) res = common.selection(_('Select your action'), keyact) if res: (name, action) = res context.update(rpc.session.context) self._exec_action(action, data, context=context) return (name, action) return False