(self)
Create an entry for the marked group
Create an entry for the marked group
Create an entry for the marked group
def create_entry(self):
        '''Create an entry for the marked group'''

        if self.groups:
            if self.entries:
                old_entry = self.entries[self.e_highlight]
            else:
                old_entry = None
            self.control.draw_text(self.changed,
                                   (1, 0, 'At least one of the following '
                                    'attributes must be given. Press any key'))
            if self.control.any_key() == -1:
                self.close()

            pass_title = False
            pass_url = False
            pass_username = False
            pass_password = False
            pass_comment = False
            goto_last = False
            while True:
                if pass_title is False:
                    title = Editor(self.control.stdscr, max_text_size=1,
                                   win_location=(0, 1),
                                   win_size=(1, 80), title="Title: ")()
                if title is False:
                    break
                elif title == -1:
                    self.close()
                pass_title = True

                if pass_url is False:
                    url = Editor(self.control.stdscr, max_text_size=1,
                                 win_location=(0, 1),
                                 win_size=(1, 80), title="URL: ")()
                if url is False:
                    pass_title = False
                    continue
                elif url == -1:
                    self.close()
                pass_url = True

                if pass_username is False:
                    username = Editor(self.control.stdscr, max_text_size=1,
                                      win_location=(0, 1),
                                      win_size=(1, 80), title="Username: ")()
                if username is False:
                    pass_url = False
                    continue
                elif username == -1:
                    self.close()
                pass_username = True

                if pass_password is False:
                    nav = self.control.gen_menu(1,
                        ((1, 0, 'Use password generator (1)'),
                         (2, 0, 'Type password by hand (2)'),
                         (3, 0, 'No password (3)')))
                    if nav == 1:
                        password = self.control.gen_pass()
                        if password is False:
                            continue
                        elif password == -1:
                            self.close()
                    elif nav == 2:
                        while True:
                            password = self.control.get_password('Password: ',
                                                                 False)
                            if password is False:
                                break
                            elif password == -1:
                                self.close()
                            confirm = self.control.get_password('Confirm: ',
                                                                False)
                            if confirm is False:
                                continue
                            elif confirm == -1:
                                self.close()

                            if password != confirm:
                                self.control.draw_text(self.changed,
                                                    (3, 0,
                                                    "Passwords didn't match"),
                                                    (5, 0, 'Press any key.'))
                                if self.control.any_key() == -1:
                                    self.close()
                            else:
                                break
                        if password is False:
                            continue
                    elif nav == -1:
                        self.close()
                    else:
                        password = ''
                if nav is False:
                    pass_username = False
                    continue
                pass_password = True

                if pass_comment is False:
                    comment = Editor(self.control.stdscr, win_location=(0, 1),
                                     title="Comment: ", quick_help="   (F2: Save, F5: Cancel)")()
                if comment is False:
                    pass_password = False
                    continue
                elif comment == -1:
                    self.close()
                pass_comment = True

                exp_date = self.control.get_exp_date()
                if goto_last is True:
                    goto_last = False
                    continue
                if exp_date is False:
                    pass_comment = False
                    continue
                elif exp_date == -1:
                    self.close()

                if self.remote is True:
                    root = self.groups[self.g_highlight].id_

                    db_buf = self.client().create_entry(title.encode(),
                                                 url.encode(),
                                                 username.encode(),
                                                 password.encode(),
                                                 comment.encode(),
                                                 str(exp_date[0]).encode(),
                                                 str(exp_date[1]).encode(),
                                                 str(exp_date[2]).encode(),
                                                 str(root).encode())
                    if self.check_answer(db_buf) is not False:
                        self.reload_remote_db(db_buf)
                    break
                else:
                    try:
                        self.groups[self.g_highlight].create_entry(title, 1, 
                                                                   url,
                                                                   username,
                                                                   password,
                                                                   comment,
                                                                   exp_date[0],
                                                                   exp_date[1],
                                                                   exp_date[2])
                    except KPError as err:
                        self.control.draw_text(self.changed,
                                               (1, 0, err.__str__()),
                                               (4, 0, 'Press any key.'))
                        if self.control.any_key() == -1:
                            self.close()
                    else:
                        self.changed = True

                    self.sort_tables(True, True)
                    if (self.entries and
                        self.entries[self.e_highlight] is not old_entry and
                            old_entry is not None):
                        self.e_highlight = self.entries.index(old_entry)
                    break
def create_entry ( self ) : if self . groups : if self . entries : old_entry = self . entries [ self . e_highlight ] else : old_entry = None self . control . draw_text ( self . changed , ( 1 , 0 , 'At least one of the following ' 'attributes must be given. Press any key' ) ) if self . control . any_key ( ) == - 1 : self . close ( ) pass_title = False pass_url = False pass_username = False pass_password = False pass_comment = False goto_last = False while True : if pass_title is False : title = Editor ( self . control . stdscr , max_text_size = 1 , win_location = ( 0 , 1 ) , win_size = ( 1 , 80 ) , title = "Title: " ) ( ) if title is False : break elif title == - 1 : self . close ( ) pass_title = True if pass_url is False : url = Editor ( self . control . stdscr , max_text_size = 1 , win_location = ( 0 , 1 ) , win_size = ( 1 , 80 ) , title = "URL: " ) ( ) if url is False : pass_title = False continue elif url == - 1 : self . close ( ) pass_url = True if pass_username is False : username = Editor ( self . control . stdscr , max_text_size = 1 , win_location = ( 0 , 1 ) , win_size = ( 1 , 80 ) , title = "Username: " ) ( ) if username is False : pass_url = False continue elif username == - 1 : self . close ( ) pass_username = True if pass_password is False : nav = self . control . gen_menu ( 1 , ( ( 1 , 0 , 'Use password generator (1)' ) , ( 2 , 0 , 'Type password by hand (2)' ) , ( 3 , 0 , 'No password (3)' ) ) ) if nav == 1 : password = self . control . gen_pass ( ) if password is False : continue elif password == - 1 : self . close ( ) elif nav == 2 : while True : password = self . control . get_password ( 'Password: ' , False ) if password is False : break elif password == - 1 : self . close ( ) confirm = self . control . get_password ( 'Confirm: ' , False ) if confirm is False : continue elif confirm == - 1 : self . close ( ) if password != confirm : self . control . draw_text ( self . changed , ( 3 , 0 , "Passwords didn't match" ) , ( 5 , 0 , 'Press any key.' ) ) if self . control . any_key ( ) == - 1 : self . close ( ) else : break if password is False : continue elif nav == - 1 : self . close ( ) else : password = '' if nav is False : pass_username = False continue pass_password = True if pass_comment is False : comment = Editor ( self . control . stdscr , win_location = ( 0 , 1 ) , title = "Comment: " , quick_help = "   (F2: Save, F5: Cancel)" ) ( ) if comment is False : pass_password = False continue elif comment == - 1 : self . close ( ) pass_comment = True exp_date = self . control . get_exp_date ( ) if goto_last is True : goto_last = False continue if exp_date is False : pass_comment = False continue elif exp_date == - 1 : self . close ( ) if self . remote is True : root = self . groups [ self . g_highlight ] . id_ db_buf = self . client ( ) . create_entry ( title . encode ( ) , url . encode ( ) , username . encode ( ) , password . encode ( ) , comment . encode ( ) , str ( exp_date [ 0 ] ) . encode ( ) , str ( exp_date [ 1 ] ) . encode ( ) , str ( exp_date [ 2 ] ) . encode ( ) , str ( root ) . encode ( ) ) if self . check_answer ( db_buf ) is not False : self . reload_remote_db ( db_buf ) break else : try : self . groups [ self . g_highlight ] . create_entry ( title , 1 , url , username , password , comment , exp_date [ 0 ] , exp_date [ 1 ] , exp_date [ 2 ] ) except KPError as err : self . control . draw_text ( self . changed , ( 1 , 0 , err . __str__ ( ) ) , ( 4 , 0 , 'Press any key.' ) ) if self . control . any_key ( ) == - 1 : self . close ( ) else : self . changed = True self . sort_tables ( True , True ) if ( self . entries and self . entries [ self . e_highlight ] is not old_entry and old_entry is not None ) : self . e_highlight = self . entries . index ( old_entry ) break