Exemplo n.º 1
0
 def single_file_check(self, _):
     result = dialogs.file_dialog()
     if detection_method == "v1":
         self.p2 = mp.Process(target=one_file, args = (result,))
     elif detection_method == "v2":
         self.p2 = mp.Process(target=one_file_v2, args = (result,)) #to initialize the second method of detecting viruses
     self.p2.start()
    def add_data_cb(self, b):
        iter = self.get_iter_at_selected_row()

        if not (iter):
            xmldatadialog.message_dialog(
                self.window, gtk.MESSAGE_WARNING,
                'Select a script and then try adding data file.')
        else:
            if self.iter_isa_script(iter):
                open_dialog = dialogs.file_dialog('Open...', self.window,
                                                  gtk.FILE_CHOOSER_ACTION_OPEN)

                response = open_dialog.run()

                if response == gtk.RESPONSE_OK:
                    data = open_dialog.get_filename()
                    open_dialog.destroy()
                    data_file = os.path.split(data)[1]
                    self.treestore.set_value(iter, 1, data_file)
                else:
                    open_dialog.destroy()
            else:
                xmldatadialog.message_dialog(
                    self.window, gtk.MESSAGE_WARNING,
                    'Data file can be added only if a script is selected.')
    def add_script_cb(self, b):
        iter = self.get_iter_at_selected_row()

        if not (iter):
            xmldatadialog.message_dialog(
                self.window, gtk.MESSAGE_WARNING,
                'Select a group and then try adding a script.')
        else:
            if self.iter_isa_group(iter):
                open_dialog = dialogs.file_dialog('Open...',
                                                  self.window,
                                                  gtk.FILE_CHOOSER_ACTION_OPEN,
                                                  multiple_selection=True)

                response = open_dialog.run()

                if response == gtk.RESPONSE_OK:
                    scripts = open_dialog.get_filenames()
                    open_dialog.destroy()

                    for i in range(0, len(scripts)):
                        file = os.path.split(scripts[i])[1]
                        self.treestore.append(iter, [file, None])
                else:
                    open_dialog.destroy()

                self.treeview.expand_all()
            else:
                xmldatadialog.message_dialog(
                    self.window, gtk.MESSAGE_WARNING,
                    'Script can be added only if a group is selected.')
    def browse_file(self, button, entry, type):
        if type == 'appmap':
            dialog = dialogs.file_dialog('Select appmap file...', None,
                                         gtk.FILE_CHOOSER_ACTION_OPEN)
        elif type == 'log':
            dialog = dialogs.file_dialog('Save log file as...',
                                         None,
                                         gtk.FILE_CHOOSER_ACTION_SAVE,
                                         default_file='Untitled.xml')

        response = dialog.run()

        if response == gtk.RESPONSE_OK:
            file = dialog.get_filename()
            dialog.destroy()
            entry.set_text(file)
        else:
            dialog.destroy()
    def create_xml_data_file_cb(self, b):
        save_dialog = dialogs.file_dialog('Save XML Data file As...',
                                          self.window,
                                          gtk.FILE_CHOOSER_ACTION_SAVE,
                                          default_file='Untitled.xml')

        file, replace = self.get_file_to_save(save_dialog)

        if file:
            xmldatadialog.data_xml_cb(file, replace)
    def open_cb(self, b):
        # Open File chooser dialog
        open_dialog = dialogs.file_dialog('Open...', self.window,
                                          gtk.FILE_CHOOSER_ACTION_OPEN)
        response = open_dialog.run()

        if response == gtk.RESPONSE_OK:
            file = open_dialog.get_filename()
            infile = open(file, 'r')

            if infile:
                file_content = infile.read()
            infile.close()

            self.new_cb(None)

            sourceview = self.get_sourceview()
            txtbuf = sourceview.get_buffer()
            page = self.notebook.get_current_page()
            widget = self.notebook.get_nth_page(page)
            hbox = self.notebook.get_tab_label(widget)
            hbox_children = hbox.get_children()

            # Get the file name and set it as the label of page
            file_name = os.path.split(file)[1]
            self.add_file_name(page, file)
            self.window.set_title(file + ' - LDTP Editor')

            prev_label = self.get_label()

            self.check_and_release_number(prev_label)

            hbox_children[0].set_label(file_name)
            self.notebook.set_tab_label(widget, hbox)
            txtbuf.set_text(file_content)
            txtbuf.set_modified(False)
            txtbuf.place_cursor(txtbuf.get_start_iter())
            open_dialog.destroy()
        else:
            open_dialog.destroy()
    def saveas_cb(self, b):
        sourceview = self.get_sourceview()

        if sourceview:
            txtbuf = sourceview.get_buffer()
            prev_label = self.get_label()

            save_dialog = dialogs.file_dialog('Save As...',
                                              self.window,
                                              gtk.FILE_CHOOSER_ACTION_SAVE,
                                              default_file=prev_label)

            file, replace = self.get_file_to_save(save_dialog)

            if file:
                fp = open(file, 'w')
                text = txtbuf.get_text(txtbuf.get_start_iter(),
                                       txtbuf.get_end_iter(),
                                       include_hidden_chars=True)
                fp.write(text)
                txtbuf.set_modified(False)
                fp.close()

                page = self.notebook.get_current_page()
                widget = self.notebook.get_nth_page(page)
                hbox = self.notebook.get_tab_label(widget)
                hbox_children = hbox.get_children()

                self.check_and_release_number(prev_label)

                # Get the file name and set it as the label of page
                file_name = os.path.split(file)[1]
                self.add_file_name(page, file)
                self.window.set_title(file + ' - LDTP Editor')
                hbox_children[0].set_label(file_name)
                self.notebook.set_tab_label(widget, hbox)
    def generate_xml_cb(self, b):
        parent = self.treestore.get_iter_first()
        log_file_name = None
        appmap_name = None
        overwrite_log_file = True

        if parent:
            gladefile_path = '.'
            if '/usr/lib/ldtpeditor' in sys.path:
                gladefile_path = '/usr/lib/ldtpeditor'

            gladefile = gladefile_path + "/log_file.glade"
            glade_xml_object = gtk.glade.XML(gladefile, "dialog")

            dialog = glade_xml_object.get_widget("dialog")
            log_file_entry = glade_xml_object.get_widget("log_file_entry")
            appmap_entry = glade_xml_object.get_widget("appmap_entry")
            browse_log_file = glade_xml_object.get_widget("browse_log_file")
            browse_appmap = glade_xml_object.get_widget("browse_appmap")
            check_overwrite = glade_xml_object.get_widget("overwrite")

            browse_log_file.connect('clicked', self.browse_file,
                                    log_file_entry, 'log')
            browse_appmap.connect('clicked', self.browse_file, appmap_entry,
                                  'appmap')

            while True:
                response = dialog.run()
                if response == gtk.RESPONSE_OK:
                    log_file_name = os.path.split(log_file_entry.get_text())[1]
                    appmap_name = os.path.split(appmap_entry.get_text())[1]
                    overwrite_log_file = check_overwrite.get_active()
                    if not (log_file_name):
                        xmldatadialog.message_dialog(
                            dialog, gtk.MESSAGE_WARNING,
                            'Enter a valid log file name')
                    else:
                        break

                else:
                    break

            dialog.destroy()

        if log_file_name:
            file = None
            save_dialog = dialogs.file_dialog('Save XML file As...',
                                              self.window,
                                              gtk.FILE_CHOOSER_ACTION_SAVE,
                                              default_file='Untitled.xml')

            file, replace = self.get_file_to_save(save_dialog)

            if file:
                fp = open(file, 'w')

                parent = self.treestore.get_iter_first()
                model = self.treeview.get_model()
                xml = '<?xml version="1.0"?>\n<ldtp>\n'

                if overwrite_log_file:
                    xml = xml + ' <logfileoverwrite>1</logfileoverwrite>\n'
                if not (overwrite_log_file):
                    xml = xml + ' <logfileoverwrite>0</logfileoverwrite>\n'

                xml = xml + ' <logfile>' + log_file_name + '</logfile>\n'
                if appmap_name:
                    xml = xml + ' <appmapfile>' + appmap_name + '</appmapfile>\n'

                while parent:
                    xml = xml + ' <group>\n'
                    child = self.treestore.iter_children(parent)

                    while child:
                        xml = xml + '  <script>\n'
                        xml = xml + '   <name>' + model.get_value(
                            child, 0) + '</name>\n'

                        data_file = model.get_value(child, 1)
                        if data_file:
                            xml = xml + '   <data>' + data_file + '</data>\n'

                        xml = xml + '  </script>\n'
                        child_next = self.treestore.iter_next(child)
                        child = child_next

                    xml = xml + ' </group>\n'
                    parent_next = self.treestore.iter_next(parent)
                    parent = parent_next

                xml = xml + '</ldtp>\n'

                fp.write(xml)
                fp.close()