示例#1
0
 def test_show(self):
     try:
         actions.execute('show', ['today'])
         actions.execute('show', ['today', 'apple'])
     except:
         raise
         self.fail()
示例#2
0
def run():
    print "Starting output loop."
    while True:
        m = messagequeue.main.receive()
        if m == STOPMSG:
            break
        actions.execute(m)
示例#3
0
    def button_action(self, **kw):
        params, data = TinyDict.split(kw)
        error = None
        reload = (params.context or {}).get('reload', False)
        result = {}

        name = params.button_name
        btype = params.button_type
        ctx = dict((params.context or {}), **rpc.session.context)

        id = params.id
        model = params.model

        id = (id or False) and int(id)
        ids = (id or []) and [id]
        list_grid = params.list_grid or '_terp_list'
        try:

            if btype == 'workflow':
                res = rpc.session.execute('object', 'exec_workflow', model, name, id)
                if isinstance(res, dict):
                    import actions
                    return actions.execute(res, ids=[id])
                else:
                    return dict(reload=True, list_grid=list_grid)

            elif btype == 'object':
                ctx = params.context or {}
                ctx.update(rpc.session.context.copy())
                if list_grid != '_terp_list':
                    ctx['from_list_grid'] = list_grid
                res = rpc.session.execute('object', 'execute', model, name, ids, ctx)

                if isinstance(res, dict):
                    import actions
                    return actions.execute(res, ids=[id])
                else:
                    return dict(reload=True, list_grid=list_grid)

            elif btype == 'action':
                import actions

                action_id = int(name)
                action_type = actions.get_action_type(action_id)

                if action_type == 'ir.actions.wizard':
                    cherrypy.session['wizard_parent_form'] = '/form'
                    cherrypy.session['wizard_parent_params'] = params

                res = actions.execute_by_id(action_id, type=action_type, model=model, id=id, ids=ids, context=ctx or {})

                if res:
                    return res
                else:
                    return dict(reload=True, list_grid=list_grid)

            else:
                return dict(error = "Unallowed button type")
        except Exception, e:
            return dict(error = ustr(e))
示例#4
0
def parse_input(args):
    try:
        action_name, args = action_name_with_arguments(args)
        actions.execute(action_name, args)
    except (MissingArgumentException, InvalidInputException):
        print usage_info()
    except actions.ActionException as e:
        print e.message
示例#5
0
 def button_action_workflow(self, name, params):
     model, id, _, _ = self._get_button_infos(params)
     res = rpc.Workflow(model)[name](id)
     if isinstance(res, dict):
         import actions
         return actions.execute(res, ids=[id])
     params.button = None
示例#6
0
 def button_action_workflow(self, name, params):
     model, id, _, _ = self._get_button_infos(params)
     res = rpc.session.execute('object', 'exec_workflow', model, name, id)
     if isinstance(res, dict):
         import actions
         return actions.execute(res, ids=[id])
     params.button = None
示例#7
0
 def index(self, payload):
     decoded_payload = ast.literal_eval(
         zlib.decompress(
             base64.urlsafe_b64decode(str(payload))))
     action, data = decoded_payload['action'], decoded_payload['data']
     cherrypy.request.params.update(decoded_payload)
     return actions.execute(action, **data)
示例#8
0
 def button_action_workflow(self, name, params):
     model, id, _, _ = self._get_button_infos(params)
     res = rpc.session.execute('object', 'exec_workflow', model, name, id)
     if isinstance(res, dict):
         import actions
         return actions.execute(res, ids=[id])
     params.button = None
示例#9
0
    def manage_filter(self, **kw):
        act={'name':'Manage Filters',
                 'res_model':'ir.filters',
                 'type':'ir.actions.act_window',
                 'view_type':'form',
                 'view_mode':'tree,form',
                 'domain':'[(\'model_id\',\'=\',\''+kw.get('model')+'\'),(\'user_id\',\'=\','+str(rpc.session.uid)+')]'}

        return actions.execute(act, context=rpc.session.context)
示例#10
0
    def action_submenu(self, **kw):
        params, data = TinyDict.split(kw)

        import actions

        act_id = rpc.session.execute('object', 'execute', 'ir.model.data', 'search', [('name','=', params.action_id)])
        res_model = rpc.session.execute('object', 'execute', 'ir.model.data', 'read', act_id, ['res_id'])

        res = rpc.session.execute('object', 'execute', 'ir.actions.act_window', 'read', res_model[0]['res_id'], False)

        if res:
            return actions.execute(res, model=params.model, id=params.id, context=rpc.session.context.copy())
示例#11
0
    def action_submenu(self, **kw):
        params, data = TinyDict.split(kw)

        import actions
        ModelData = rpc.RPCProxy('ir.model.data')
        res_model = ModelData.read(
            ModelData.search(['name', '=', params.action_id]),
            ['res_id'])

        res = rpc.RPCProxy('ir.actions.act_window').read(res_model[0]['res_id'], False)

        if res:
            return actions.execute(res, model=params.model, id=params.id, context=rpc.get_session().context.copy())
示例#12
0
    def action(self, **kw):
        params, data = TinyDict.split(kw)
        context_menu = kw.get('context_menu') or False

        id = params.id or False
        ids = params.selection or []

        if not ids and id:
            ids = [id]

        if not id and ids:
            id = ids[0]

        domain = params.domain or []
        context = params.context or {}
        action = {}

        if data.get('datas'):
            action = eval(data.get('datas'))
        type = action.get('type')
        act_id = params.action

        if not act_id:
            return self.do_action('client_action_multi', datas=kw)

        if type is None:
            action_type = rpc.RPCProxy('ir.actions.actions').read(
                act_id, ['type'], context)['type']
            tmp_ctx = dict(context)
            if action_type == 'ir.actions.report.xml':
                # avoid reading large binary values that we won't even care about
                tmp_ctx['bin_size'] = True
            action = rpc.session.execute('object', 'execute', action_type,
                                         'read', act_id, False, tmp_ctx)

        if domain:
            if isinstance(domain, basestring):
                domain = eval(domain)
            domain.extend(expr_eval(action.get('domain', '[]'), context))
            action['domain'] = ustr(domain)

        if context.get('search_view'):
            context.pop('search_view')
        action['form_context'] = context or {}
        import actions
        return actions.execute(action,
                               model=params.model,
                               id=id,
                               ids=ids,
                               report_type='pdf',
                               context_menu=context_menu)
示例#13
0
    def button_action_object(self, name, params):
        model, id, ids, ctx = self._get_button_infos(params)

        res = rpc.RPCProxy(model)[name](ids, ctx)
        # after installation of modules (esp. initial) we may
        # need values from the global context for some contexts & domains (e.g.
        # leads) => installer wizards are generally postfixed by '.installer'
        # so use this characteristic to setup context reloads
        if model.endswith('.installer'):
            rpc.get_session().context_reload()
        if isinstance(res, dict):
            import actions
            return actions.execute(res, ids=[id], context=ctx)
        params.button = None
示例#14
0
    def button_action_object(self, name, params):
        model, id, ids, ctx = self._get_button_infos(params)

        res = rpc.session.execute('object', 'execute', model, name, ids, ctx)
        # after installation of modules (esp. initial) we may
        # need values from the global context for some contexts & domains (e.g.
        # leads) => installer wizards are generally postfixed by '.installer'
        # so use this characteristic to setup context reloads
        if model.endswith('.installer'):
            rpc.session.context_reload()
        if isinstance(res, dict):
            import actions
            return actions.execute(res, ids=[id], context=ctx)
        params.button = None
示例#15
0
    def action(self, **kw):
        params, data = TinyDict.split(kw)

        action = params.data

        if not action:
            return self.do_action('tree_but_action', datas=kw)

        import actions

        ids = params.selection or []
        id = (ids or False) and ids[0]

        return actions.execute(action, model=params.model, id=id, ids=ids, report_type='pdf')
示例#16
0
    def index(self, model, id):

        id = int(id)

        if id:
            ctx = dict(rpc.get_session().context)

            action = dict(
                rpc.RPCProxy('ir.attachment').action_get(ctx),
                domain=[('res_model', '=', model), ('res_id', '=', id)],
                context=dict(ctx,
                             default_res_model=model,
                             default_res_id=id
            ))

            return actions.execute(action)
        else:
            raise common.message(_('No record selected, You can only attach to existing record...'))
示例#17
0
    def action(self, **kw):
        params, data = TinyDict.split(kw)

        action = params.data

        if not action:
            return self.do_action('tree_but_action', datas=kw)

        import actions

        ids = params.selection or []
        id = (ids or False) and ids[0]

        return actions.execute(action,
                               model=params.model,
                               id=id,
                               ids=ids,
                               report_type='pdf')
示例#18
0
    def action(self, **kw):
        params, data = TinyDict.split(kw)
        context_menu = kw.get('context_menu') or False

        id = params.id or False
        ids = params.selection or []

        if not ids and id:
            ids = [id]

        if not id and ids:
            id = ids[0]

        domain = params.domain or []
        context = params.context or {}
        action = {}

        if data.get('datas'):
            action = eval(data.get('datas'))
        type = action.get('type')
        act_id = params.action

        if not act_id:
            return self.do_action('client_action_multi', datas=kw)

        if type is None:
            action_type = rpc.RPCProxy('ir.actions.actions').read(act_id, ['type'], context)['type']
            tmp_ctx = dict(context)
            if action_type == 'ir.actions.report.xml':
                # avoid reading large binary values that we won't even care about
                tmp_ctx['bin_size'] = True
            action = rpc.session.execute('object', 'execute', action_type, 'read', act_id, False, tmp_ctx)

        if domain:
            if isinstance(domain, basestring):
                domain = eval(domain)
            domain.extend(expr_eval(action.get('domain', '[]'), context))
            action['domain'] = ustr(domain)

        if context.get('search_view'):
            context.pop('search_view')
        action['form_context'] = context or {}
        import actions
        return actions.execute(action, model=params.model, id=id, ids=ids, report_type='pdf', context_menu=context_menu)
示例#19
0
    def action_submenu(self, **kw):
        params, data = TinyDict.split(kw)

        import actions

        act_id = rpc.session.execute('object', 'execute', 'ir.model.data',
                                     'search',
                                     [('name', '=', params.action_id)])
        res_model = rpc.session.execute('object', 'execute', 'ir.model.data',
                                        'read', act_id, ['res_id'])

        res = rpc.session.execute('object', 'execute', 'ir.actions.act_window',
                                  'read', res_model[0]['res_id'], False)

        if res:
            return actions.execute(res,
                                   model=params.model,
                                   id=params.id,
                                   context=rpc.session.context.copy())
示例#20
0
    def index(self, model, id):

        id = int(id)

        if id:
            ctx = dict(rpc.session.context)

            action = dict(rpc.RPCProxy('ir.attachment').action_get(ctx),
                          domain=[('res_model', '=', model),
                                  ('res_id', '=', id)],
                          context=dict(ctx,
                                       default_res_model=model,
                                       default_res_id=id))

            return actions.execute(action)
        else:
            raise common.message(
                _('No record selected, You can only attach to existing record...'
                  ))
示例#21
0
文件: form.py 项目: hectord/unifield
    def action(self, **kw):
        params, data = TinyDict.split(kw)
        context_menu = kw.get('context_menu')

        id = params.id or False
        ids = params.selection or []

        if not ids and id:
            ids = [id]

        if not id and ids:
            id = ids[0]

        domain = params.domain or []
        context = params.context or {}
        if not context and rpc.session.context:
            context['lang'] = rpc.session.context.get('lang')
        action = {}

        if data.get('datas'):
            action = eval(data.get('datas'))
        type = action.get('type')
        act_id = params.action

        if not act_id:
            return self.do_action('client_action_multi', datas=kw)

        if type is None:
            action_type = rpc.RPCProxy('ir.actions.actions').read(act_id, ['type'], context)['type']
            action = rpc.session.execute('object', 'execute', action_type, 'read', act_id, False, context)

        if domain:
            if isinstance(domain, basestring):
                domain = eval(domain)
            domain.extend(expr_eval(action.get('domain', '[]'), context))
            action['domain'] = ustr(domain)

        action['form_context'] = context or {}
        import actions
        return actions.execute(action, model=params.model, id=id, ids=ids, report_type='pdf', context_menu=context_menu)
示例#22
0
    def execute(self, params):

        action = params.name
        model = params.model
        state = params.state
        datas = params.datas

        form = None
        buttons = []

        if model:
            action = model.replace("wizard.", "", 1)
        else:
            model = "wizard." + action

        params.name = action
        params.model = model
        params.view_mode = []

        if "form" not in datas:
            datas["form"] = {}

        wiz_id = params.wiz_id or rpc.Wizard().create(action)

        while state != "end":

            ctx = rpc.get_session().context.copy()
            ctx.update(datas.get("context" or {}) or {})

            res = rpc.Wizard().execute(wiz_id, datas, state, ctx)

            if "datas" in res:
                datas["form"].update(res["datas"])
            else:
                res["datas"] = {}

            if res["type"] == "form":

                fields = res["fields"]
                form_values = {}

                for f in fields:
                    if "value" in fields[f]:
                        form_values[f] = fields[f]["value"]

                    if f in datas["form"] and fields[f]["type"] == "one2many":
                        datas["form"][f] = [(1, d, {}) for d in datas["form"][f]]

                form_values.update(datas["form"])

                datas["form"] = form_values

                res["datas"].update(datas["form"])

                params.is_wizard = True
                params.view_mode = ["form"]
                params.view_type = "form"
                params.views = {"form": res}

                # keep track of datas and some other required information
                params.hidden_fields = [
                    tw.form.Hidden(name="_terp_datas", default=ustr(datas)),
                    tw.form.Hidden(name="_terp_state2", default=state),
                    tw.form.Hidden(name="_terp_wiz_id", default=wiz_id),
                ]

                form = tw.form_view.ViewForm(params, name="view_form", action="/openerp/wizard/action")

                buttons = []
                for x in res.get("state", []):
                    x = list(x)
                    x[1] = re.sub("_(?!_)", "", x[1])  # remove mnemonic

                    if len(x) >= 3:
                        x[2] = icons.get_icon(x[2])

                    buttons.append(tuple(x))

                params.state = state
                return dict(form=form, buttons=buttons)

            elif res["type"] == "action":
                import actions

                # If configuration is done
                if res.get("action") and res.get("action").get("res_model") == "ir.ui.menu" and res["state"] == "end":
                    return self.end()

                act_res = actions.execute(res["action"], **datas)
                if act_res:
                    return act_res

                state = res["state"]

            elif res["type"] == "print":
                import actions

                datas["report_id"] = res.get("report_id", False)
                if res.get("get_id_from_action", False):
                    backup_ids = datas["ids"]
                    datas["ids"] = datas["form"]["ids"]

                return actions.execute_report(res["report"], **datas)

            elif res["type"] == "state":
                state = res["state"]

        raise redirect("/openerp/wizard/end")
 def index(self, payload):
     decoded_payload = ast.literal_eval(
         zlib.decompress(base64.urlsafe_b64decode(str(payload))))
     action, data = decoded_payload['action'], decoded_payload['data']
     cherrypy.request.params.update(decoded_payload)
     return actions.execute(action, **data)
示例#24
0
    def button_action(self, **kw):
        params, data = TinyDict.split(kw)
        error = None
        reload = (params.context or {}).get('reload', False)
        result = {}

        name = params.button_name
        btype = params.button_type
        ctx = dict((params.context or {}), **rpc.session.context)

        id = params.id
        model = params.model

        id = (id or False) and int(id)
        ids = (id or []) and [id]
        list_grid = params.list_grid or '_terp_list'

        try:

            if btype == 'workflow':
                res = rpc.session.execute('object', 'exec_workflow', model,
                                          name, id)
                if isinstance(res, dict):
                    import actions
                    return actions.execute(res, ids=[id])
                else:
                    return dict(reload=True, list_grid=list_grid)

            elif btype == 'object':
                ctx = params.context or {}
                ctx.update(rpc.session.context.copy())
                res = rpc.session.execute('object', 'execute', model, name,
                                          ids, ctx)

                if isinstance(res, dict):
                    import actions
                    return actions.execute(res, ids=[id])
                else:
                    return dict(reload=True, list_grid=list_grid)

            elif btype == 'action':
                import actions

                action_id = int(name)
                action_type = actions.get_action_type(action_id)

                if action_type == 'ir.actions.wizard':
                    cherrypy.session['wizard_parent_form'] = '/form'
                    cherrypy.session['wizard_parent_params'] = params

                res = actions.execute_by_id(action_id,
                                            type=action_type,
                                            model=model,
                                            id=id,
                                            ids=ids,
                                            context=ctx or {})

                if res:
                    return res
                else:
                    return dict(reload=True, list_grid=list_grid)

            else:
                return dict(error="Unallowed button type")
        except Exception, e:
            return dict(error=ustr(e))
示例#25
0
    def action(self, **kw):
        params, data = TinyDict.split(kw)

        import actions
        return actions.execute(params.action, **params.data)
    def execute(self, params):

        action = params.name
        model = params.model
        state = params.state
        datas = params.datas

        form = None
        buttons = []

        if model:
            action = model.replace('wizard.', '', 1)
        else:
            model = 'wizard.' + action

        params.name = action
        params.model = model
        params.view_mode = []

        if 'form' not in datas:
            datas['form'] = {}

        wiz_id = params.wiz_id or rpc.session.execute('wizard', 'create',
                                                      action)

        while state != 'end':

            ctx = rpc.session.context.copy()
            ctx.update(datas.get('context' or {}) or {})

            res = rpc.session.execute('wizard', 'execute', wiz_id, datas,
                                      state, ctx)

            if 'datas' in res:
                datas['form'].update(res['datas'])
            else:
                res['datas'] = {}

            if res['type'] == 'form':

                fields = res['fields']
                form_values = {}

                for f in fields:
                    if 'value' in fields[f]:
                        form_values[f] = fields[f]['value']

                    if f in datas['form'] and fields[f]['type'] == "one2many":
                        datas['form'][f] = [(1, d, {})
                                            for d in datas['form'][f]]

                form_values.update(datas['form'])

                datas['form'] = form_values

                res['datas'].update(datas['form'])

                params.is_wizard = True
                params.view_mode = ['form']
                params.view_type = 'form'
                params.views = {'form': res}

                # keep track of datas and some other required information
                params.hidden_fields = [
                    tw.form.Hidden(name='_terp_datas', default=ustr(datas)),
                    tw.form.Hidden(name='_terp_state2', default=state),
                    tw.form.Hidden(name='_terp_wiz_id', default=wiz_id)
                ]

                form = tw.form_view.ViewForm(params,
                                             name="view_form",
                                             action="/openerp/wizard/action")

                buttons = []
                for x in res.get('state', []):
                    x = list(x)
                    x[1] = re.sub('_(?!_)', '', x[1])  # remove mnemonic

                    if len(x) >= 3:
                        x[2] = icons.get_icon(x[2])

                    buttons.append(tuple(x))

                params.state = state
                return dict(form=form, buttons=buttons)

            elif res['type'] == 'action':
                import actions
                # If configuration is done
                if res.get('action') and res.get('action').get(
                        'res_model') == 'ir.ui.menu' and res['state'] == 'end':
                    return self.end()

                act_res = actions.execute(res['action'], **datas)
                if act_res:
                    return act_res

                state = res['state']

            elif res['type'] == 'print':
                import actions

                datas['report_id'] = res.get('report_id', False)
                if res.get('get_id_from_action', False):
                    backup_ids = datas['ids']
                    datas['ids'] = datas['form']['ids']

                return actions.execute_report(res['report'], **datas)

            elif res['type'] == 'state':
                state = res['state']

        raise redirect('/openerp/wizard/end')
示例#27
0
文件: cmd.py 项目: jhburns/db-final
            if choice == 1:
                print("Choose a table to insert into.")
                for (i, table) in enumerate(tables):
                    print("\t{}. {}".format(i, table))

                choice2 = int(input("\tYour choice: "))
                if choice2 < 0 or choice2 > len(tables) - 1:
                    raise ValueError
                print()

                table_name = list(tables.keys())[choice2]
                schema = tables[table_name]
                response1 = tuple(prompt_insert(schema))

                execute(
                    connection,
                    generate_insert(table_name, remove_primary_int(schema)),
                    response1)
            elif choice == 2:
                print("Choose a table to delete from.")

                primaries = primary_only(tables)
                for (i, table) in enumerate(primaries):
                    print("\t{}. {}".format(i, table))

                choice2 = int(input("\tYour choice: "))
                if choice2 < 0 or choice2 > len(primaries) - 1:
                    raise ValueError
                print()

                table_name = list(primaries.keys())[choice2]
                attribute = primaries[table_name]
示例#28
0
 def test_set(self):
     try:
         actions.execute('set', ['8', 'today', 'apple'])
     except:
         raise
         self.fail()
示例#29
0
    def execute(self, params):

        action = params.name
        model = params.model
        state = params.state
        datas = params.datas

        form = None
        buttons = []

        if model:
            action = model.replace('wizard.', '', 1)
        else:
            model = 'wizard.' + action

        params.name = action
        params.model = model
        params.view_mode = []

        if 'form' not in datas:
            datas['form'] = {}

        wiz_id = params.wiz_id or rpc.session.execute('wizard', 'create', action)

        while state != 'end':

            ctx = rpc.session.context.copy()
            ctx.update(datas.get('context' or {}) or {})

            res = rpc.session.execute('wizard', 'execute', wiz_id, datas, state, ctx)

            if 'datas' in res:
                datas['form'].update(res['datas'])
            else:
                res['datas'] = {}

            if res['type']=='form':

                fields = res['fields']
                form_values = {}

                for f in fields:
                    if 'value' in fields[f]:
                        form_values[f] = fields[f]['value']
                    
                    if f in datas['form'] and fields[f]['type'] == "one2many":
                        datas['form'][f] = [(1, d, {}) for d in datas['form'][f]]

                form_values.update(datas['form'])

                datas['form'] = form_values

                res['datas'].update(datas['form'])

                params.is_wizard = True
                params.view_mode = ['form']
                params.view_type = 'form'
                params.views = {'form': res}

                # keep track of datas and some other required information
                params.hidden_fields = [tw.form.Hidden(name='_terp_datas', default=ustr(datas)),
                                        tw.form.Hidden(name='_terp_state2', default=state),
                                        tw.form.Hidden(name='_terp_wiz_id', default=wiz_id)]

                form = tw.form_view.ViewForm(params, name="view_form", action="/openerp/wizard/action")

                buttons = []
                for x in res.get('state', []):
                    x = list(x)
                    x[1] = re.sub('_(?!_)', '', x[1]) # remove mnemonic

                    if len(x) >= 3:
                        x[2] = icons.get_icon(x[2])

                    buttons.append(tuple(x))

                params.state = state
                return dict(form=form, buttons=buttons)

            elif res['type']=='action':
                import actions
                # If configuration is done 
                if res.get('action') and res.get('action').get('res_model') == 'ir.ui.menu' and res['state'] == 'end':
                    return self.end()
                
                act_res = actions.execute(res['action'], **datas)
                if act_res:
                    return act_res
                
                state = res['state']

            elif res['type']=='print':
                import actions

                datas['report_id'] = res.get('report_id', False)
                if res.get('get_id_from_action', False):
                    backup_ids = datas['ids']
                    datas['ids'] = datas['form']['ids']

                return actions.execute_report(res['report'], **datas)

            elif res['type']=='state':
                state = res['state']

        raise redirect('/openerp/wizard/end')
示例#30
0
r = sr.Recognizer()
engine_tts = tts.init()
print("Finished initializing. Say something into the microphone!")

while True:
    # Speech recognition
    with sr.Microphone() as source:
      audio = r.listen(source)

    try:
        input = r.recognize_sphinx(audio)

        if len(input) == 0:
            continue

        print(f"You: {input.capitalize()}")
    except sr.UnknownValueError:
        print(f"{BOT_NAME} could not understand what you said.")
    except sr.RequestError as e:
        print(f"Internal {BOT_NAME} error: {e}")

    # Query / command processing
    if input == "stop" or input == "end":
        break
    response = actions.execute(input)

    # Text to speech output
    print(f"{BOT_NAME}: {response}")
    engine_tts.say(str(response))
    engine_tts.runAndWait()
    def action(self, **kw):
        params, data = TinyDict.split(kw)

        import actions
        return actions.execute(params.action, **params.data)