ConDict

Check-in [8d99f26ef3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:add change name possible
Timelines: family | ancestors | descendants | both | testing
Files: files | file ages | folders
SHA1:8d99f26ef3608cbc18e9cea30641a8a77fb6a0b9
User & Date: zorro 2012-09-03 18:45:22
Context
2012-09-04
06:11
change password function check-in: b23c0a7e72 user: alzay tags: testing
2012-09-03
18:45
add change name possible check-in: 8d99f26ef3 user: zorro tags: testing
18:23
small edit check-in: 12d2a8d10e user: zorro tags: testing
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to aside.py.

9
10
11
12
13
14
15
16
17
18
19
    try:
        config.read(filename)
        result['database'] = config['database']['dbname']
        result['defuser'] = config['user']['default_user']
    except (KeyError, IndexError, TypeError) as er:
        pass
    return result

def help_command(commands):
    for key, item in commands.items():
        print("{0:.<30}{1}".format(key, item[0]))







<
<
<
<
9
10
11
12
13
14
15




    try:
        config.read(filename)
        result['database'] = config['database']['dbname']
        result['defuser'] = config['user']['default_user']
    except (KeyError, IndexError, TypeError) as er:
        pass
    return result




Changes to condt.py.

1
2
3
4
5
6


7
8
9
10
11
12
13
..
18
19
20
21
22
23
24
25
26
27



28
29
30
31
32
33
34
..
45
46
47
48
49
50
51

52
53
54
55
56
57
58
...
125
126
127
128
129
130
131
132
133





















134
135
136
#!/usr/bin/env python3
#-*- coding: utf-8 -*-

import sqlite3, hashlib, getpass
DEBUG = True



class BaseConDict(object):
    """Base Console Dictionary class"""
    def __init__(self, name, dbfile):
        self.connect = sqlite3.connect(dbfile)
        self.name = name
    def __repr__(self):
        return "<ConDict object for {0}>".format(self.name)
................................................................................
        return valid
    def __del__(self):
        self.connect.close()

class Condt(BaseConDict):
    """Condt - class for ConDict"""
    COMMANDS = {'.help': {'desc': 'list commands', 'command': None}, 
        # '.chname': {'desc': 'change current user name', 'command': None}, 
        # '.chpassword': {'desc': 'change current password', 'command': None},
        # '.list': {'desc': 'list users words', 'command': None},



        '.exit': {'desc': 'quit from program', 'command': None},
        }
    def __init__(self, name, dbfile):
        super().__init__(name, dbfile)       
        self.__pcounter = 3
        self.init_command()
        self.user_id = self.get_user()
................................................................................
            user_id = self.handling_add(cur)
        cur.close()
        return user_id

    def init_command(self):
        self.COMMANDS['.help']['command'] = self.command_help
        self.COMMANDS['.exit']['command'] = self.command_exit


    def hash_pass(self, password):
        result = bytes(password.strip(), 'utf-8')
        return hashlib.sha1(result).hexdigest()

    def check_name(self, cur):
        try:
................................................................................
        for key, item in self.COMMANDS.items():
            print("{0:.<30}{1}".format(key, item['desc']))
        return '.help'

    def command_exit(self):
        return 0

    def chname(self):
        pass





















    def chpassword(self):
        pass







>
>







 







|


>
>
>







 







>







 







|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
...
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
#!/usr/bin/env python3
#-*- coding: utf-8 -*-

import sqlite3, hashlib, getpass
DEBUG = True

class IncorrectDbData(Exception): pass

class BaseConDict(object):
    """Base Console Dictionary class"""
    def __init__(self, name, dbfile):
        self.connect = sqlite3.connect(dbfile)
        self.name = name
    def __repr__(self):
        return "<ConDict object for {0}>".format(self.name)
................................................................................
        return valid
    def __del__(self):
        self.connect.close()

class Condt(BaseConDict):
    """Condt - class for ConDict"""
    COMMANDS = {'.help': {'desc': 'list commands', 'command': None}, 
        '.chname': {'desc': 'change current user name', 'command': None},
        # '.chpassword': {'desc': 'change current password', 'command': None},
        # '.list': {'desc': 'list users words', 'command': None},
        # '.add': {'desc': 'add new words', 'command': None},
        # '.edit': {'desc': 'edit words', 'command': None},
        # '.del': {'desc': 'delete words', 'command': None},
        '.exit': {'desc': 'quit from program', 'command': None},
        }
    def __init__(self, name, dbfile):
        super().__init__(name, dbfile)       
        self.__pcounter = 3
        self.init_command()
        self.user_id = self.get_user()
................................................................................
            user_id = self.handling_add(cur)
        cur.close()
        return user_id

    def init_command(self):
        self.COMMANDS['.help']['command'] = self.command_help
        self.COMMANDS['.exit']['command'] = self.command_exit
        self.COMMANDS['.chname']['command'] = self.command_chname

    def hash_pass(self, password):
        result = bytes(password.strip(), 'utf-8')
        return hashlib.sha1(result).hexdigest()

    def check_name(self, cur):
        try:
................................................................................
        for key, item in self.COMMANDS.items():
            print("{0:.<30}{1}".format(key, item['desc']))
        return '.help'

    def command_exit(self):
        return 0

    def command_chname(self):
        cur = self.connect.cursor()
        while(True):
            name = input("You login:")
            fullname = input("You full name (optional):")
            try:
                if name == '':
                    raise IncorrectDbData()
                cur.execute("UPDATE user SET name=(?), full=(?) WHERE id=(?)", (name, fullname, self.user_id))
            except (sqlite3.DatabaseError, IncorrectDbData) as er:
                print('Incorrect information, change data')
                e = input('Exit from name update [N/y]')
                if e in ('y', 'Y'):
                    break
                continue
            else:
                self.connect.commit()
                self.name = name
                print("You name updated successfully")
                break
        cur.close()
        return 'chname'

    def chpassword(self):
        pass

Changes to db.sqlite.

cannot compute difference between binary files

Changes to main.py.

23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
    user = config['defuser'] if config['defuser'] else input("User name:")
    # create object
    account = Condt(user, config['database'])
    if not account:
        print('Validation error, bye...')
        return 0
    print(WELCOM)
    prefix = PREFIX.format(account.name)
    while (True):

        command = input(prefix)
        get_command = account.handling_command(command)
        if get_command is None:
            print('Sorry, unknown command: "{0}"\nuse ".help" for more information'.format(command))
            continue
        if not get_command:
            print("Bye {0}!".format(account.name))







<

>







23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
    user = config['defuser'] if config['defuser'] else input("User name:")
    # create object
    account = Condt(user, config['database'])
    if not account:
        print('Validation error, bye...')
        return 0
    print(WELCOM)

    while (True):
        prefix = PREFIX.format(account.name)
        command = input(prefix)
        get_command = account.handling_command(command)
        if get_command is None:
            print('Sorry, unknown command: "{0}"\nuse ".help" for more information'.format(command))
            continue
        if not get_command:
            print("Bye {0}!".format(account.name))