def on_new(self, button, data):
   (dialog,enabled,name,command) = self._create_command_dialog()
   res = dialog.run()
   item = {}
   if res == Gtk.ResponseType.ACCEPT:
     item['enabled'] = enabled.get_active()
     item['name'] = name.get_text()
     item['command'] = command.get_text()
     if item['name'] == '' or item['command'] == '':
       err = Gtk.MessageDialog(dialog,
                               Gtk.DialogFlags.MODAL,
                               Gtk.MessageType.ERROR,
                               Gtk.ButtonsType.CLOSE,
                               _("You need to define a name and command")
                             )
       err.run()
       err.destroy()
     else:
       # we have a new command
       store = data['treeview'].get_model()
       iter = store.get_iter_first()
       name_exist = False
       while iter != None:
         if store.get_value(iter,CC_COL_NAME) == item['name']:
           name_exist = True
           break
         iter = store.iter_next(iter)
       if not name_exist:
         store.append((item['enabled'], item['name'], item['command']))
       else:
         self._err(_("Name *%s* already exist") % item['name'])
   dialog.destroy()
Exemple #2
0
 def on_new(self, button, data):
     (dialog, enabled, name, command) = self._create_command_dialog()
     res = dialog.run()
     item = {}
     if res == Gtk.ResponseType.ACCEPT:
         item['enabled'] = enabled.get_active()
         item['name'] = name.get_text()
         item['command'] = command.get_text()
         if item['name'] == '' or item['command'] == '':
             err = Gtk.MessageDialog(
                 dialog, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR,
                 Gtk.ButtonsType.CLOSE,
                 _("You need to define a name and command"))
             err.run()
             err.destroy()
         else:
             # we have a new command
             store = data['treeview'].get_model()
             iter = store.get_iter_first()
             name_exist = False
             while iter != None:
                 if store.get_value(iter, CC_COL_NAME) == item['name']:
                     name_exist = True
                     break
                 iter = store.iter_next(iter)
             if not name_exist:
                 store.append(
                     (item['enabled'], item['name'], item['command']))
             else:
                 gerr(_("Name *%s* already exist") % item['name'])
     dialog.destroy()
 def _error(self, msg):
   err = Gtk.MessageDialog(dialog,
                           Gtk.DialogFlags.MODAL,
                           Gtk.MessageType.ERROR,
                           Gtk.ButtonsType.CLOSE,
                           msg
                         )
   err.run()
   err.destroy()
 def _error(self, msg):
   err = gtk.MessageDialog(dialog,
                           gtk.DIALOG_MODAL,
                           gtk.MESSAGE_ERROR,
                           gtk.BUTTONS_CLOSE,
                           msg
                         )
   err.run()
   err.destroy()
    def on_edit(self, button, data):
      treeview = data['treeview']
      selection = treeview.get_selection()
      (store, iter) = selection.get_selected()
      
      if not iter:
        return
       
      (dialog,enabled,name,command) = self._create_command_dialog(
                                                enabled_var = store.get_value(iter, CC_COL_ENABLED),
                                                name_var = store.get_value(iter, CC_COL_NAME),
                                                command_var = store.get_value(iter, CC_COL_COMMAND)
                                                                  )
      res = dialog.run()
      item = {}
      if res == Gtk.ResponseType.ACCEPT:
        item['enabled'] = enabled.get_active()
        item['name'] = name.get_text()
        item['command'] = command.get_text()
        if item['name'] == '' or item['command'] == '':
          err = Gtk.MessageDialog(dialog,
                                  Gtk.DialogFlags.MODAL,
                                  Gtk.MessageType.ERROR,
                                  Gtk.ButtonsType.CLOSE,
                                  _("You need to define a name and command")
                                )
          err.run()
          err.destroy()
        else:
          tmpiter = store.get_iter_first()
          name_exist = False
          while tmpiter != None:
            if store.get_path(tmpiter) != store.get_path(iter) and store.get_value(tmpiter,CC_COL_NAME) == item['name']:
              name_exist = True
              break
            tmpiter = store.iter_next(tmpiter)
          if not name_exist:
            store.set(iter,
                      CC_COL_ENABLED,item['enabled'],
                      CC_COL_NAME, item['name'],
                      CC_COL_COMMAND, item['command']
                      )
          else:
            self._err(_("Name *%s* already exist") % item['name'])

      dialog.destroy()
    def on_edit(self, button, data):
      treeview = data['treeview']
      selection = treeview.get_selection()
      (store, iter) = selection.get_selected()
      
      if not iter:
        return
       
      (dialog,enabled,name,command) = self._create_command_dialog(
                                                enabled_var = store.get_value(iter, CC_COL_ENABLED),
                                                name_var = store.get_value(iter, CC_COL_NAME),
                                                command_var = store.get_value(iter, CC_COL_COMMAND)
                                                                  )
      res = dialog.run()
      item = {}
      if res == Gtk.ResponseType.ACCEPT:
        item['enabled'] = enabled.get_active()
        item['name'] = name.get_text()
        item['command'] = command.get_text()
        if item['name'] == '' or item['command'] == '':
          err = Gtk.MessageDialog(dialog,
                                  Gtk.DialogFlags.MODAL,
                                  Gtk.MessageType.ERROR,
                                  Gtk.ButtonsType.CLOSE,
                                  _("You need to define a name and command")
                                )
          err.run()
          err.destroy()
        else:
          tmpiter = store.get_iter_first()
          name_exist = False
          while tmpiter != None:
            if store.get_path(tmpiter) != store.get_path(iter) and store.get_value(tmpiter,CC_COL_NAME) == item['name']:
              name_exist = True
              break
            tmpiter = store.iter_next(tmpiter)
          if not name_exist:
            store.set(iter,
                      CC_COL_ENABLED,item['enabled'],
                      CC_COL_NAME, item['name'],
                      CC_COL_COMMAND, item['command']
                      )
          else:
            gerr(_("Name *%s* already exist") % item['name'])

      dialog.destroy()
Exemple #7
0
    def on_new(self, button, data):
      (dialog,ip,user,port,passwd) = self._create_command_dialog()
      res = dialog.run()
      item = {}
      if res == Gtk.ResponseType.ACCEPT:
        item['ip'] = ip.get_text()
        item['user'] = user.get_text()
        item['port'] = port.get_text()
        item['passwd'] = encrypt_passwd(passwd.get_text()) 
        if item['ip'] == '' or item['user'] == '' or item['port'] == '':
          err = Gtk.MessageDialog(dialog,
                                  Gtk.DialogFlags.MODAL,
                                  Gtk.MessageType.ERROR,
                                  Gtk.ButtonsType.CLOSE,
                                  _("You need input ip and user and port")
                                )
          err.run()
          err.destroy()
        else:
          # we have a new command
          filter_store = data['treeview'].get_model()
          store = filter_store.get_model()

          ssh_key = item['user'] + '@' + item['ip']
          ssh_exist = False
          iter = store.get_iter_first()
          while iter != None:
            if store.get_path(iter) != store.get_path(iter) :
              temp_user = store.get_value(iter,CC_COL_USER)
              temp_ip = store.get_value(iter,CC_COL_IP)
              temp_key = temp_user + '@' + temp_ip

              if ssh_key == temp_key:
                ssh_exist = True
                break

            iter = store.iter_next(iter)
          if not ssh_exist:
            store.insert(0, (item['ip'], item['user'], item['port'], nowTime(), item['passwd']))
            self.update_cmd_list(store)
            self._save_config()
          else:
            gerr(_("ssh config *%s* already exist") % ssh_key)
      dialog.destroy()
 def _error(self, msg):
     err = Gtk.MessageDialog(dialog, Gtk.DialogFlags.MODAL,
                             Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE,
                             msg)
     err.run()
     err.destroy()
Exemple #9
0
    def on_edit(self, button, data):
      treeview = data['treeview']
      selection = treeview.get_selection()
      (store_filter, filter_iter) = selection.get_selected()
      
      store = store_filter.get_model()
      iter = store_filter.convert_iter_to_child_iter(filter_iter)

      if not iter:
        return
      
      old_ssh_key =  store.get_value(iter, CC_COL_USER) + '@' + store.get_value(iter, CC_COL_IP)
      (dialog,ip,user,port,passwd) = self._create_command_dialog(
                                                ip_var = store.get_value(iter, CC_COL_IP),
                                                user_var = store.get_value(iter, CC_COL_USER),
                                                port_var = store.get_value(iter, CC_COL_PORT),
                                                passwd_var = decrypt_passwd(store.get_value(iter, CC_COL_PASSWD))
                                                                  )
      res = dialog.run()
      item = {}
      if res == Gtk.ResponseType.ACCEPT:
        item['ip'] = ip.get_text()
        item['user'] = user.get_text()
        item['port'] = port.get_text()
        item['passwd'] = encrypt_passwd(passwd.get_text())
        if item['ip'] == '' or item['user'] == '' or item['port'] == '':
          err = Gtk.MessageDialog(dialog,
                                  Gtk.DialogFlags.MODAL,
                                  Gtk.MessageType.ERROR,
                                  Gtk.ButtonsType.CLOSE,
                                  _("You need input ip and user and port")
                                )
          err.run()
          err.destroy()
        else:
          ssh_key = item['user'] + '@' + item['ip']
          ssh_exist = False

          tmpiter = store.get_iter_first()
          while tmpiter != None:
            if store.get_path(tmpiter) != store.get_path(iter) :
              temp_user = store.get_value(tmpiter,CC_COL_USER)
              temp_ip = store.get_value(tmpiter,CC_COL_IP)
              temp_key = temp_user + '@' + temp_ip

              if ssh_key == temp_key:
                ssh_exist = True
                break

            tmpiter = store.iter_next(tmpiter)

          if not ssh_exist:
            store.set(iter,
                      CC_COL_IP,   item['ip'],
                      CC_COL_USER, item['user'],
                      CC_COL_PORT, item['port'],
                      CC_COL_TIME, nowTime(),
                      CC_COL_PASSWD, item['passwd']
                      )

            self.update_cmd_list(store)
            self._save_config()
          else:
            gerr(_("ssh config *%s* already exist") % ssh_key)

      dialog.destroy()