This file is indexed.

/usr/share/pyshared/gquilt_pkg/text_edit.py is in gquilt 0.25-2build1.

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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
### Copyright (C) 2010 Peter Williams <peter_ono@users.sourceforge.net>

### This program is free software; you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
### the Free Software Foundation; version 2 of the License only.

### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.

### You should have received a copy of the GNU General Public License
### along with this program; if not, write to the Free Software
### Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import os, gtk, gquilt_pkg.sourceview, pango, gobject
from gquilt_pkg import dialogue, ifce, utils, gutils, config

def _edit_files_extern(filelist, edstr=config.DEFAULT_EDITOR):
    if not edstr.split()[0] in config.EDITORS_THAT_NEED_A_TERMINAL:
        cmd = '%s %s' % (edstr, utils.file_list_to_string(filelist))
    else:
        if config.DEFAULT_TERMINAL == "gnome-terminal":
            flag = '-x'
        else:
            flag = '-e'
        cmd = '%s %s %s %s' % (config.DEFAULT_TERMINAL, flag, edstr, utils.file_list_to_string(filelist))
    return utils.run_cmd_in_bgnd(cmd)

def edit_files_extern(file_list):
    ed_assigns = config.assign_extern_editors(file_list)
    for edstr in list(ed_assigns.keys()):
        _edit_files_extern(ed_assigns[edstr], edstr)

def peruse_files_extern(file_list):
    ed_assigns = config.assign_extern_perusers(file_list)
    for edstr in list(ed_assigns.keys()):
        _edit_files_extern(ed_assigns[edstr], edstr)

class SummaryBuffer(gquilt_pkg.sourceview.SourceBuffer):
    def __init__(self, table=None):
        if not table:
            table = gquilt_pkg.sourceview.SourceTagTable()
        gquilt_pkg.sourceview.SourceBuffer.__init__(self, table=table)
        self.action_group = gtk.ActionGroup("summary")
        self.action_group.add_actions(
            [
                ("summary_ack", None, "_Ack", None,
                 "Insert Acked-by tag at cursor position", self._insert_ack_acb),
                ("summary_sign_off", None, "_Sign Off", None,
                 "Insert Signed-off-by tag at cursor position", self._insert_sign_off_acb),
                ("summary_author", None, "A_uthor", None,
                 "Insert Author tag at cursor position", self._insert_author_acb),
            ])
    def _insert_sign_off_acb(self, _action=None):
        data = ifce.ifce.get_author_name_and_email()
        self.insert_at_cursor("Signed-off-by: %s\n" % data)
    def _insert_ack_acb(self, _action=None):
        data = ifce.ifce.get_author_name_and_email()
        self.insert_at_cursor("Acked-by: %s\n" % data)
    def _insert_author_acb(self, _action=None):
        data = ifce.ifce.get_author_name_and_email()
        self.insert_at_cursor("Author: %s\n" % data)

class SummaryView(gquilt_pkg.sourceview.SourceView):
    def __init__(self, text_buffer=None, table=None):
        if not text_buffer:
            text_buffer = SummaryBuffer(table)
        gquilt_pkg.sourceview.SourceView.__init__(self, text_buffer)
        fdesc = pango.FontDescription("mono, 10")
        self.modify_font(fdesc)
        self.set_margin(72)
        self.set_show_margin(True)
        context = self.get_pango_context()
        metrics = context.get_metrics(fdesc)
        width = pango.PIXELS(metrics.get_approximate_char_width() * 81)
        x, y = self.buffer_to_window_coords(gtk.TEXT_WINDOW_TEXT, width, width / 3)
        self.set_size_request(x, y)
        self.set_cursor_visible(True)
        self.set_editable(True)
        self.ui_manager = gutils.UIManager()
        self.ui_manager.insert_action_group(text_buffer.action_group, -1)
    def get_action(self, action_name):
        for action_group in self.ui_manager.get_action_groups():
            action = action_group.get_action(action_name)
            if action:
                return action
        return None
    def get_msg(self):
        text_buffer = self.get_buffer()
        return text_buffer.get_text(text_buffer.get_start_iter(), text_buffer.get_end_iter())

class ChangeSummaryBuffer(SummaryBuffer):
    def __init__(self, table=None, auto_save=True):
        if not table:
            table = gquilt_pkg.sourceview.SourceTagTable()
        SummaryBuffer.__init__(self, table=table)
        self._save_interval = 1000 # milliseconds
        self._save_file_name = ifce.ifce.get_default_commit_save_file()
        if not os.path.exists(self._save_file_name):
            self.save_summary(content="")
        self.action_group.add_actions(
            [
                ("menu_summary", None, "_Summary"),
                ("change_summary_save", gtk.STOCK_SAVE, "_Save", "",
                 "Save commit summary", self._save_summary_acb),
                ("change_summary_save_as", gtk.STOCK_SAVE_AS, "S_ave as", "",
                 "Save commit summary to a file", self.save_summary_as),
                ("change_summary_load", gtk.STOCK_REVERT_TO_SAVED, "_Revert", "",
                 "Load summary from saved file", self._load_summary_acb),
                ("change_summary_load_from", gtk.STOCK_REVERT_TO_SAVED, "_Load from", "",
                 "Load summary from a file", self.load_summary_from),
                ("change_summary_insert_from", gtk.STOCK_PASTE, "_Insert from", "",
                 "Insert contents of a file at cursor position", self.insert_summary_from),
            ])
        self.save_toggle_action = gtk.ToggleAction(
                "summary_toggle_auto_save", "Auto Sa_ve",
                "Automatically/periodically save summary to file", gtk.STOCK_SAVE
            )
        self.save_toggle_action.connect("toggled", self._toggle_auto_save_acb)
        self.save_toggle_action.set_active(auto_save)
        self.action_group.add_action(self.save_toggle_action)
        # Load the saved content before (possibly) turning auto save on or
        # contents of saved file could be wiped out before it's loaded
        self.load_summary(already_checked=True)
        self._toggle_auto_save_acb()
    def save_summary(self, file_name=None, content=None):
        if not file_name:
            file_name = self._save_file_name
        try:
            save_file = open(file_name, 'w')
            if content is None:
                save_file.write(self.get_text(self.get_start_iter(), self.get_end_iter()))
            else:
                save_file.write(content)
            save_file.close()
            self._save_file_name = file_name
            self.set_modified(False)
        except IOError:
            dialogue.alert_user('Save failed!')
    def _save_summary_acb(self, _action=None):
        self.save_summary()
    def save_summary_as(self, _action=None):
        fname = dialogue.ask_file_name("Enter file name", existing=False, suggestion=self._save_file_name)
        if fname and os.path.exists(fname) and not utils.samefile(fname, self._save_file_name):
            if not utils.samefile(fname, ifce.ifce.get_default_commit_save_file()):
                if not dialogue.ask_ok_cancel(os.linesep.join([fname, "\nFile exists. Overwrite?"])):
                    return
        self.save_summary(file_name=fname)
    def _ok_to_overwrite_summary(self):
        if self.get_char_count():
            return dialogue.ask_ok_cancel("Buffer contents will be destroyed. Continue?")
        return True
    def load_summary(self, file_name=None, already_checked=False):
        if not already_checked and not self._ok_to_overwrite_summary():
            return
        if not file_name:
            file_name = self._save_file_name
        try:
            save_file = open(file_name, 'r')
            self.set_text(save_file.read())
            save_file.close()
            self._save_file_name = file_name
            self.set_modified(False)
        except IOError:
            dialogue.alert_user('Load from file failed!')
    def _load_summary_acb(self, _action=None):
        self.load_summary()
    def load_summary_from(self, _action=None):
        if not self._ok_to_overwrite_summary():
            return
        fname = dialogue.ask_file_name("Enter file name", existing=True)
        self.load_summary(file_name=fname, already_checked=True)
    def insert_summary_from(self, _action=None):
        file_name = dialogue.ask_file_name("Enter file name", existing=True)
        try:
            save_file = open(file_name, 'r')
            self.insert_at_cursor(save_file.read())
            save_file.close()
            self.set_modified(True)
        except IOError:
            dialogue.alert_user('Insert at cursor from file failed!')
    def get_auto_save(self):
        return self.save_toggle_action.get_active()
    def set_auto_save(self, active=True):
        self.save_toggle_action.set_active(active)
    def get_auto_save_interval(self):
        return self._save_interval
    def set_auto_save_inerval(self, interval):
        self._save_interval = interval
    def do_auto_save(self):
        if self.get_modified():
            self.save_summary()
        return self.get_auto_save()
    def _toggle_auto_save_acb(self, _action=None):
        if self.get_auto_save():
            gobject.timeout_add(self._save_interval, self.do_auto_save)
    def finish_up(self, clear_save=False):
        if self.get_auto_save():
            self.set_auto_save(False)
            self.do_auto_save()
        if clear_save:
            self.save_summary(file_name=ifce.ifce.get_default_commit_save_file(),
                              content="")

CHANGE_SUMMARY_UI_DESCR = \
'''
<ui>
  <menubar name="change_summary_menubar">
    <menu name="change_summary_menu" action="menu_summary">
      <menuitem action="change_summary_save"/>
      <menuitem action="change_summary_save_as"/>
      <menuitem action="change_summary_load"/>
      <menuitem action="change_summary_load_from"/>
      <menuitem action="change_summary_insert_from"/>
    </menu>
  </menubar>
  <toolbar name="change_summary_toolbar">
    <toolitem action="summary_ack"/>
    <toolitem action="summary_sign_off"/>
    <toolitem action="summary_author"/>
    <toolitem action="summary_toggle_auto_save"/>
  </toolbar>
</ui>
'''

class ChangeSummaryView(SummaryView):
    def __init__(self, text_buffer=None, auto_save=True, table=None):
        if not text_buffer:
            text_buffer = ChangeSummaryBuffer(table, auto_save)
        SummaryView.__init__(self, text_buffer, table)
        self.change_summary_merge_id = self.ui_manager.add_ui_from_string(CHANGE_SUMMARY_UI_DESCR)

class NewPatchSummaryBuffer(SummaryBuffer):
    def __init__(self, table=None):
        if not table:
            table = gquilt_pkg.sourceview.SourceTagTable()
        SummaryBuffer.__init__(self, table=table)
        self.action_group.add_actions(
            [
                ("menu_summary", None, "_Description"),
                ("patch_summary_insert_from", gtk.STOCK_PASTE, "_Insert from", "",
                 "Insert contents of a file at cursor position", self._insert_summary_from_acb),
            ])
    def _insert_summary_from_acb(self, _action=None):
        file_name = dialogue.ask_file_name("Enter file name", existing=True)
        if file_name is not None:
            try:
                save_file = open(file_name, 'r')
                self.insert_at_cursor(save_file.read())
                save_file.close()
                self.set_modified(True)
            except IOError:
                dialogue.alert_user('Insert at cursor from file failed!')

class PatchSummaryBuffer(NewPatchSummaryBuffer):
    def __init__(self, get_summary, set_summary, patch=None, table=None):
        self.patch = patch
        self._set_summary = set_summary
        self._get_summary = get_summary
        if not table:
            table = gquilt_pkg.sourceview.SourceTagTable()
        NewPatchSummaryBuffer.__init__(self, table=table)
        self.action_group.add_actions(
            [
                ("patch_summary_save", gtk.STOCK_SAVE, "_Save", "",
                 "Save commit summary", self._save_summary_acb),
                ("patch_summary_load", gtk.STOCK_REVERT_TO_SAVED, "_Reload", "",
                 "Load summary from saved file", self._load_summary_acb),
            ])
    def _save_summary_acb(self, _action=None):
        text = self.get_text(self.get_start_iter(), self.get_end_iter())
        res, sout, serr = self._set_summary(self.patch, text)
        if res:
            dialogue.alert_user(os.linesep.join([sout, serr]))
        else:
            self.set_modified(False)
    def _ok_to_overwrite_summary(self):
        if self.get_char_count() and self.get_modified():
            return dialogue.ask_ok_cancel("Buffer contents will be destroyed. Continue?")
        return True
    def load_summary(self):
        res, text, serr = self._get_summary(self.patch)
        if res:
            dialogue.alert_user(os.linesep.join([text, serr]))
        else:
            self.set_text(text)
            self.set_modified(False)
    def _load_summary_acb(self, _action=None):
        if self._ok_to_overwrite_summary():
            self.load_summary()

NEW_PATCH_SUMMARY_UI_DESCR = \
'''
<ui>
  <menubar name="patch_summary_menubar">
    <menu name="patch_summary_menu" action="menu_summary">
      <separator/>
      <menuitem action="patch_summary_insert_from"/>
    </menu>
  </menubar>
  <toolbar name="patch_summary_toolbar">
    <toolitem action="summary_ack"/>
    <toolitem action="summary_sign_off"/>
    <toolitem action="summary_author"/>
  </toolbar>
</ui>
'''

class NewPatchSummaryView(SummaryView):
    def __init__(self, text_buffer=None, table=None):
        if not text_buffer:
            text_buffer = NewPatchSummaryBuffer(table)
        SummaryView.__init__(self, text_buffer, table)
        self.patch_summary_merge_id = self.ui_manager.add_ui_from_string(NEW_PATCH_SUMMARY_UI_DESCR)

PATCH_SUMMARY_UI_DESCR = \
'''
<ui>
  <menubar name="patch_summary_menubar">
    <menu name="patch_summary_menu" action="menu_summary">
      <menuitem action="patch_summary_load"/>
      <separator/>
    </menu>
  </menubar>
  <toolbar name="patch_summary_toolbar">
  </toolbar>
</ui>
'''

class PatchSummaryView(NewPatchSummaryView):
    def __init__(self, get_summary, set_summary, patch=None, table=None):
        text_buffer = PatchSummaryBuffer(get_summary, set_summary, patch, table)
        NewPatchSummaryView.__init__(self, text_buffer, table)
        self.patch_summary_merge_id = self.ui_manager.add_ui_from_string(PATCH_SUMMARY_UI_DESCR)
        action = text_buffer.action_group.get_action("patch_summary_save")
        self.save_button = gutils.ActionButton(action, use_underline=False)
    def load_summary(self):
        self.get_buffer().load_summary()