This file is indexed.

/usr/share/pyshared/chirpui/clone.py is in chirp 0.1.12-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
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
#!/usr/bin/python
#
# Copyright 2008 Dan Smith <dsmith@danplanet.com>
#
# 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, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.

import threading
import os

import gtk
import gobject

from chirp import platform, directory, detect, chirp_common
from chirpui import miscwidgets, cloneprog, inputdialog, common, config

AUTO_DETECT_STRING = "Auto Detect (Icom Only)"

class CloneSettings:
    def __init__(self):
        self.port = None
        self.radio_class = None

    def __str__(self):
        s = ""
        if self.radio_class:
            return "%s %s on %s" % (self.radio_class.VENDOR,
                                    self.radio_class.MODEL,
                                    self.port)
        else:
            return "Detect %s on %s" % (self.detect_fn, self.port)

class CloneSettingsDialog(gtk.Dialog):
    def __make_field(self, label, widget):
        l = gtk.Label(label)
        self.__table.attach(l, 0, 1, self.__row, self.__row+1)
        self.__table.attach(widget, 1, 2, self.__row, self.__row+1)
        self.__row += 1

        l.show()
        widget.show()

    def __make_port(self, port):
        conf = config.get("state")

        ports = platform.get_platform().list_serial_ports()
        if not port:
            if conf.get("last_port"):
                port = conf.get("last_port")
            elif ports:
                port = ports[0]

        return miscwidgets.make_choice(ports, True, port)

    def __make_model(self):
        return miscwidgets.make_choice([], False)

    def __make_vendor(self, model):
        vendors = {}
        for rclass in sorted(directory.DRV_TO_RADIO.values()):
            if rclass.VENDOR == "Generic":
                continue

            if not vendors.has_key(rclass.VENDOR):
                vendors[rclass.VENDOR] = []

            if rclass.VENDOR not in detect.DETECT_FUNCTIONS:
                vendors[rclass.VENDOR].append(rclass)

        self.__vendors = vendors

        conf = config.get("state")
        if not conf.get("last_vendor"):
            conf.set("last_vendor", sorted(vendors.keys())[0])

        last_vendor = conf.get("last_vendor")
        if last_vendor not in vendors.keys():
            last_vendor = vendors.keys()[0]

        v = miscwidgets.make_choice(vendors.keys(), False, last_vendor)

        def _changed(box, vendors, model):
            models = vendors[box.get_active_text()]

            added_models = []

            model.get_model().clear()
            for rclass in models:
                if rclass.MODEL not in added_models:
                    model.append_text(rclass.MODEL)
                    added_models.append(rclass.MODEL)
            if not models:
                model.append_text("Detect")

            model_names = [x.MODEL for x in models]
            if conf.get("last_model") in model_names:
                model.set_active(added_models.index(conf.get("last_model")))
            else:
                model.set_active(0)

        v.connect("changed", _changed, vendors, model)
        _changed(v, vendors, model)

        return v

    def __make_ui(self, settings):
        self.__table = gtk.Table(3, 2)
        self.__table.set_row_spacings(3)
        self.__table.set_col_spacings(10)
        self.__row = 0

        self.__port = self.__make_port(settings and settings.port or None)
        self.__modl = self.__make_model()
        self.__vend = self.__make_vendor(self.__modl)

        self.__make_field("Port", self.__port)
        self.__make_field("Vendor", self.__vend)
        self.__make_field("Model", self.__modl)

        if settings and settings.radio_class:
            common.combo_select(self.__vend, settings.radio_class.VENDOR)
            self.__modl.get_model().clear()
            self.__modl.append_text(settings.radio_class.MODEL)
            common.combo_select(self.__modl, settings.radio_class.MODEL)
            self.__vend.set_sensitive(False)
            self.__modl.set_sensitive(False)

        self.__table.show()
        self.vbox.pack_start(self.__table, 1, 1, 1)

    def __init__(self, settings=None, parent=None, title="Radio"):
        buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                   gtk.STOCK_OK, gtk.RESPONSE_OK)
        gtk.Dialog.__init__(self, title,
                            parent=parent,
                            flags=gtk.DIALOG_MODAL)
        self.__make_ui(settings)
        self.__cancel_button = self.add_button(gtk.STOCK_CANCEL,
                                               gtk.RESPONSE_CANCEL)
        self.__okay_button = self.add_button(gtk.STOCK_OK,
                                             gtk.RESPONSE_OK)
        self.__okay_button.grab_default()
        self.__okay_button.grab_focus()

    def run(self):
        r = gtk.Dialog.run(self)
        if r != gtk.RESPONSE_OK:
            return None

        vendor = self.__vend.get_active_text()
        model = self.__modl.get_active_text()

        cs = CloneSettings()
        cs.port = self.__port.get_active_text()
        if model == "Detect":
            try:
                cs.radio_class = detect.DETECT_FUNCTIONS[vendor](cs.port)
                if not cs.radio_class:
                    raise Exception("Unable to detect radio on %s" % cs.port)
            except Exception, e:
                d = inputdialog.ExceptionDialog(e)
                d.run()
                d.destroy()
                return None
        else:
            for rclass in directory.DRV_TO_RADIO.values():
                if rclass.MODEL == model:
                    cs.radio_class = rclass
                    break
            if not cs.radio_class:
                common.show_error("Internal error: Unable to upload to %s" % model)
                print self.__vendors
                return None

        conf = config.get("state")
        conf.set("last_port", cs.port)
        conf.set("last_vendor", cs.radio_class.VENDOR)
        conf.set("last_model", cs.radio_class.MODEL)

        return cs

class CloneCancelledException(Exception):
    pass

class CloneThread(chirp_common.KillableThread):
    def __status(self, status):
        gobject.idle_add(self.__progw.status, status)

    def __init__(self, radio, direction, cb=None, parent=None):
        threading.Thread.__init__(self)

        self.__radio = radio
        self.__out = direction == "out"
        self.__cback = cb
        self.__cancelled = False

        self.__progw = cloneprog.CloneProg(parent=parent, cancel=self.cancel)

    def cancel(self):
        self.__cancelled = True
        self.kill(CloneCancelledException)

    def run(self):
        print "Clone thread started"

        gobject.idle_add(self.__progw.show)

        self.__radio.status_fn = self.__status
        
        try:
            if self.__out:
                self.__radio.sync_out()
            else:
                self.__radio.sync_in()

            emsg = None
        except Exception, e:
            common.log_exception()
            print "Clone failed: %s" % e
            emsg = e

        gobject.idle_add(self.__progw.hide)

        # NB: Compulsory close of the radio's serial connection
        self.__radio.pipe.close()

        print "Clone thread ended"

        if self.__cback and not self.__cancelled:
            gobject.idle_add(self.__cback, self.__radio, emsg)

if __name__ == "__main__":
    d = CloneSettingsDialog("/dev/ttyUSB0")
    r = d.run()
    print r