예제 #1
0
 def accept(self):
     if self.key_ledit.text().isEmpty() or unicode(
             self.key_ledit.text()).isspace():
         errmsg = u"Key name field cannot be empty!"
         return error_dialog(None,
                             "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
                             _(errmsg),
                             show=True,
                             show_copy_button=False)
     if len(self.key_ledit.text()) < 4:
         errmsg = u"Key name must be at <i>least</i> 4 characters long!"
         return error_dialog(None,
                             "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
                             _(errmsg),
                             show=True,
                             show_copy_button=False)
     if uStrCmp(self.key_ledit.text(),
                self.parent.listy.currentItem().text()):
         # Same exact name ... do nothing.
         return QDialog.reject(self)
     for k in self.parent.plugin_keys.keys():
         if (uStrCmp(self.key_ledit.text(), k, True) and
                 not uStrCmp(k,
                             self.parent.listy.currentItem().text(), True)):
             errmsg = u"The key name <strong>{0}</strong> is already being used.".format(
                 self.key_ledit.text())
             return error_dialog(None,
                                 "{0} {1}".format(PLUGIN_NAME,
                                                  PLUGIN_VERSION),
                                 _(errmsg),
                                 show=True,
                                 show_copy_button=False)
     QDialog.accept(self)
예제 #2
0
    def migrate_files(self):
        unique_dlg_name = PLUGIN_NAME + "import {0} keys".format(self.key_type_name).replace(' ', '_') #takes care of automatically remembering last directory
        caption = "Select {0} files to import".format(self.key_type_name)
        filters = [("{0} files".format(self.key_type_name), [self.keyfile_ext])]
        files = choose_files(self, unique_dlg_name, caption, filters, all_files=False)
        counter = 0
        skipped = 0
        if files:
            for filename in files:
                fpath = os.path.join(config_dir, filename)
                filename = os.path.basename(filename)
                new_key_name = os.path.splitext(os.path.basename(filename))[0]
                with open(fpath,'rb') as keyfile:
                    new_key_value = keyfile.read()
                if self.binary_file:
                    new_key_value = codecs.encode(new_key_value,'hex')
                elif self.json_file:
                    new_key_value = json.loads(new_key_value)
                elif self.android_file:
                    # convert to list of the keys in the string
                    new_key_value = new_key_value.splitlines()
                match = False
                for key in self.plugin_keys.keys():
                    if uStrCmp(new_key_name, key, True):
                        skipped += 1
                        msg = "A key with the name <strong>{0}</strong> already exists!\nSkipping key file  <strong>{1}</strong>.\nRename the existing key and import again".format(new_key_name,filename)
                        inf = info_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
                                _(msg), show_copy_button=False, show=True)
                        match = True
                        break
                if not match:
                    if new_key_value in self.plugin_keys.values():
                        old_key_name = [name for name, value in self.plugin_keys.items() if value == new_key_value][0]
                        skipped += 1
                        info_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
                                            "The key in file {0} is the same as the existing key <strong>{1}</strong> and has been skipped.".format(filename,old_key_name), show_copy_button=False, show=True)
                    else:
                        counter += 1
                        self.plugin_keys[new_key_name] = new_key_value

            msg = ""
            if counter+skipped > 1:
                if counter > 0:
                    msg += "Imported <strong>{0:d}</strong> key {1}. ".format(counter, "file" if counter == 1 else "files")
                if skipped > 0:
                    msg += "Skipped <strong>{0:d}</strong> key {1}.".format(skipped, "file" if counter == 1 else "files")
                inf = info_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
                                    _(msg), show_copy_button=False, show=True)
        return counter > 0
예제 #3
0
    def migrate_files(self):
        dynamic[PLUGIN_NAME + u"config_dir"] = config_dir
        files = choose_files(
            self, PLUGIN_NAME + u"config_dir",
            u"Select {0} files to import".format(self.key_type_name),
            [(u"{0} files".format(self.key_type_name), [self.keyfile_ext])],
            False)
        counter = 0
        skipped = 0
        if files:
            for filename in files:
                fpath = os.path.join(config_dir, filename)
                filename = os.path.basename(filename)
                new_key_name = os.path.splitext(os.path.basename(filename))[0]
                with open(fpath, 'rb') as keyfile:
                    new_key_value = keyfile.read()
                if self.binary_file:
                    new_key_value = new_key_value.encode('hex')
                elif self.json_file:
                    new_key_value = json.loads(new_key_value)
                match = False
                for key in self.plugin_keys.keys():
                    if uStrCmp(new_key_name, key, True):
                        skipped += 1
                        msg = u"A key with the name <strong>{0}</strong> already exists!\nSkipping key file  <strong>{1}</strong>.\nRename the existing key and import again".format(
                            new_key_name, filename)
                        inf = info_dialog(None,
                                          "{0} {1}".format(
                                              PLUGIN_NAME, PLUGIN_VERSION),
                                          _(msg),
                                          show_copy_button=False,
                                          show=True)
                        match = True
                        break
                if not match:
                    if new_key_value in self.plugin_keys.values():
                        old_key_name = [
                            name
                            for name, value in self.plugin_keys.iteritems()
                            if value == new_key_value
                        ][0]
                        skipped += 1
                        info_dialog(
                            None,
                            "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
                            u"The key in file {0} is the same as the existing key <strong>{1}</strong> and has been skipped."
                            .format(filename, old_key_name),
                            show_copy_button=False,
                            show=True)
                    else:
                        counter += 1
                        self.plugin_keys[new_key_name] = new_key_value

            msg = u""
            if counter + skipped > 1:
                if counter > 0:
                    msg += u"Imported <strong>{0:d}</strong> key {1}. ".format(
                        counter, u"file" if counter == 1 else u"files")
                if skipped > 0:
                    msg += u"Skipped <strong>{0:d}</strong> key {1}.".format(
                        skipped, u"file" if counter == 1 else u"files")
                inf = info_dialog(None,
                                  "{0} {1}".format(PLUGIN_NAME,
                                                   PLUGIN_VERSION),
                                  _(msg),
                                  show_copy_button=False,
                                  show=True)
        return counter > 0