This file is indexed.

/usr/share/pyshared/tryton/action/main.py is in tryton-client 2.2.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#This file is part of Tryton.  The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
import time
import datetime
import tryton.rpc as rpc
from tryton.common import message, error, selection, file_open, mailto
from tryton.gui.window import Window
from tryton.pyson import PYSONDecoder
from tryton.exceptions import TrytonServerError
import gettext
import tempfile
import os
import webbrowser
import tryton.common as common

_ = gettext.gettext

class Action(object):

    @staticmethod
    def exec_report(name, data, direct_print=False, email_print=False,
            email=None, context=None):
        if context is None:
            context = {}
        if email is None:
            email = {}
        data = data.copy()
        ids = data['ids']
        del data['ids']
        ctx = rpc.CONTEXT.copy()
        ctx.update(context)
        ctx['direct_print'] = direct_print
        ctx['email_print'] = email_print
        ctx['email'] = email
        if not ids:
            args = ('model', data['model'], 'search', [], 0, None, None, ctx)
            try:
                ids = rpc.execute(*args)
            except TrytonServerError, exception:
                ids = common.process_exception(exception, *args)
                if not ids:
                    return False
            if ids == []:
                message(_('Nothing to print!'))
                return False
            data['id'] = ids[0]
        args = ('report', name, 'execute', ids, data, ctx)
        rpcprogress = common.RPCProgress('execute', args)
        try:
            res = rpcprogress.run()
        except TrytonServerError, exception:
            common.process_exception(exception)
            return False
        if not res:
            return False
        (type, data, print_p, name) = res
        if not print_p and direct_print:
            print_p = True
        dtemp = tempfile.mkdtemp(prefix='tryton_')
        fp_name = os.path.join(dtemp,
                name.replace(os.sep, '_').replace(os.altsep or os.sep, '_') \
                        + os.extsep + type)
        with open(fp_name, 'wb') as file_d:
            file_d.write(data)
        if email_print:
            mailto(to=email.get('to'), cc=email.get('cc'),
                    subject=email.get('subject'), body=email.get('body'),
                    attachment=fp_name)
        else:
            file_open(fp_name, type, print_p=print_p)
        return True

    @staticmethod
    def execute(act_id, data, action_type=None, context=None):
        if context is None:
            context = {}
        ctx = rpc.CONTEXT.copy()
        ctx.update(context)
        if not action_type:
            res = False
            try:
                res = rpc.execute('model', 'ir.action', 'read', act_id,
                        ['type'], ctx)
            except TrytonServerError, exception:
                common.process_exception(exception)
                return
            if not res:
                raise Exception, 'ActionNotFound'
            action_type = res['type']
        try:
            res = rpc.execute('model', action_type, 'search_read',
                    [('action', '=', act_id)], 0, 1, None, None, ctx)
        except TrytonServerError, exception:
            common.process_exception(exception)
            return
        Action._exec_action(res, data)

    @staticmethod
    def _exec_action(action, data=None, context=None):
        if context is None:
            context = {}
        if data is None:
            data = {}
        else:
            data = data.copy()
        if 'type' not in (action or {}):
            return

        if action['type'] == 'ir.action.act_window':
            view_ids = False
            view_mode = None
            if action.get('views', []):
                view_ids = [x[0] for x in action['views']]
                view_mode = [x[1] for x in action['views']]
            elif action.get('view_id', False):
                view_ids = [action['view_id'][0]]

            action.setdefault('pyson_domain', '[]')
            ctx = {
                'active_id': data.get('id', False),
                'active_ids': data.get('ids', []),
            }
            ctx.update(rpc.CONTEXT)
            eval_ctx = ctx.copy()
            eval_ctx['_user'] = rpc._USER
            action_ctx = PYSONDecoder(eval_ctx).decode(
                    action.get('pyson_context') or '{}')
            ctx.update(action_ctx)
            ctx.update(context)

            domain_context = ctx.copy()
            domain_context['context'] = ctx
            domain_context['_user'] = rpc._USER
            domain = PYSONDecoder(domain_context).decode(action['pyson_domain'])

            search_context = ctx.copy()
            search_context['context'] = ctx
            search_context['_user'] = rpc._USER
            search_value = PYSONDecoder(search_context).decode(
                    action['pyson_search_value'] or '[]')

            name = False
            if action.get('window_name', True):
                name = action.get('name', False)

            res_model = action.get('res_model', data.get('res_model'))
            res_id = action.get('res_id', data.get('res_id'))

            Window.create(view_ids, res_model, res_id, domain,
                    action_ctx, view_mode, name=name,
                    limit=action.get('limit'),
                    auto_refresh=action.get('auto_refresh'),
                    search_value=search_value,
                    icon=(action.get('icon.rec_name') or ''))
        elif action['type'] == 'ir.action.wizard':
            Window.create_wizard(action['wiz_name'], data,
                direct_print=action.get('direct_print', False),
                email_print=action.get('email_print', False),
                email=action.get('email'), name=action.get('name', False),
                context=context, icon=(action.get('icon.rec_name') or ''),
                window=action.get('window', False))

        elif action['type'] == 'ir.action.report':
            Action.exec_report(action['report_name'], data,
                    direct_print=action.get('direct_print', False),
                    email_print=action.get('email_print', False),
                    email=action.get('email'), context=context)

        elif action['type'] == 'ir.action.url':
            if action['url']:
                webbrowser.open(action['url'], new=2)

    @staticmethod
    def exec_keyword(keyword, data=None, context=None, warning=True,
            alwaysask=False):
        actions = []
        if 'id' in data:
            model_id = data.get('id', False)
            try:
                actions = rpc.execute('model', 'ir.action.keyword',
                        'get_keyword', keyword, (data['model'], model_id),
                        rpc.CONTEXT)
            except TrytonServerError, exception:
                common.process_exception(exception)
                return False

        keyact = {}
        for action in actions:
            keyact[action['name'].replace('_', '')] = action

        res = selection(_('Select your action'), keyact, alwaysask=alwaysask)
        if res:
            (name, action) = res
            Action._exec_action(action, data, context=context)
            return (name, action)
        elif not len(keyact) and warning:
            message(_('No action defined!'))
        return False