ConDict

Check-in [5a802f40f1]
Login

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

Overview
Comment:add debug on/off in config file
Timelines: family | ancestors | descendants | both | testing
Files: files | file ages | folders
SHA1:5a802f40f14f910be1d777233c66690e51de79ef
User & Date: zorro 2012-10-03 17:57:51
Context
2012-10-03
18:41
add tesinto ticket #063281f6ba check-in: fd1ef2e7e3 user: zorro tags: testing
17:57
add debug on/off in config file check-in: 5a802f40f1 user: zorro tags: testing
17:30
add result row for export/import, ticket #fc6fc735a5 check-in: e9d41199c4 user: zorro tags: testing
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to aside.py.

7
8
9
10
11
12
13
14
15
16
17


18

19

20


21
22
23
24
25
26
27
YANDEX_TRANSLATE_JSON = "http://translate.yandex.net/api/v1/tr.json/translate?"
TEST_CONNECT = "http://ya.ru/"
CHECK_MANY_SPACE = re.compile(r"\s+")
DEFCTEST = 10

def get_config_data(filename):
    global DEFCTEST
    result = {'database': None, 'defuser': None, 'defctest': DEFCTEST}
    config = configparser.ConfigParser()
    try:
        config.read(filename)


        result['database'] = config['database']['dbname']

        result['defuser'] = config['user']['default_user']

        result['defctest'] = int(config['user']['test_count'])


    except (ValueError, KeyError, IndexError, TypeError) as er:
        pass
    return result

def prepare_str(input_str):
    global CHECK_MANY_SPACE
    result = CHECK_MANY_SPACE.sub(" ", input_str.strip())







|



>
>
|
>
|
>
|
>
>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
YANDEX_TRANSLATE_JSON = "http://translate.yandex.net/api/v1/tr.json/translate?"
TEST_CONNECT = "http://ya.ru/"
CHECK_MANY_SPACE = re.compile(r"\s+")
DEFCTEST = 10

def get_config_data(filename):
    global DEFCTEST
    result = {'database': None, 'defuser': None, 'defctest': DEFCTEST, 'debug': False}
    config = configparser.ConfigParser()
    try:
        config.read(filename)
        for sec in config.sections():
            if 'dbname' in config[sec]:
                result['database'] = config[sec]['dbname']
            if 'default_user' in config[sec]:
                result['defuser'] = config[sec]['default_user']
            if 'test_count' in config[sec]:
                result['defctest'] = int(config[sec]['test_count'])
            if 'debug' in config[sec]:
                result['debug'] = config[sec].getboolean('debug')
    except (ValueError, KeyError, IndexError, TypeError) as er:
        pass
    return result

def prepare_str(input_str):
    global CHECK_MANY_SPACE
    result = CHECK_MANY_SPACE.sub(" ", input_str.strip())

Changes to condt.conf.

1
2


3
4
5
6
[database]
dbname=db.sqlite



[user]
default_user=test
test_count=10


>
>




1
2
3
4
5
6
7
8
[database]
dbname=db.sqlite
# developing mode (on/off, 1/0, yes/no)
debug=no

[user]
default_user=test
test_count=10

Changes to condt.py.

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18


19
20
21
22
23
24
25
..
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import sqlite3, hashlib, getpass, datetime, csv, random
from aside import *

# please, change this stirg for your application
SALT = 'r8Uts$jLs74Lgh49_h75&w@dFsS4sgpm3Kqq['
EXPORT_NAME = 'condict_export_'
TEST_NUM = 5
DEBUG = True

class IncorrectDbData(Exception): pass
class DublicationDbData(Exception): pass

class BaseConDict(object):
    """Base Console Dictionary class"""
    def __init__(self, name, dbfile):


        self.connect = sqlite3.connect(dbfile)
        self.online = False
        self.name = name
    def __repr__(self):
        return "<ConDict object for {0}>".format(self.name)
    def __str__(self):
        return "<ConDict object for {0}>".format(self.name)
................................................................................
        '.testmix': {'desc': 'start en-ru test', 'command': None,
            'full': 'start mix test'},
        '.testinfo': {'desc': 'information by test', 'command': None,
            'full': 'full test information by test ID'},
        '.testlist': {'desc': 'list of tests', 'command': None,
            'full': 'this command print list of your tests'},
        }
    def __init__(self, name, dbfile, ctest=10):
        super().__init__(name, dbfile)       
        self.__pcounter = 3
        self.ctest = ctest
        self.init_command()
        self.user_id = self.get_user()
        self.command_connect()

    def get_user(self):







|






|
>
>







 







|
|







4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
..
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import sqlite3, hashlib, getpass, datetime, csv, random
from aside import *

# please, change this stirg for your application
SALT = 'r8Uts$jLs74Lgh49_h75&w@dFsS4sgpm3Kqq['
EXPORT_NAME = 'condict_export_'
TEST_NUM = 5
DEBUG = False

class IncorrectDbData(Exception): pass
class DublicationDbData(Exception): pass

class BaseConDict(object):
    """Base Console Dictionary class"""
    def __init__(self, name, dbfile, debug):
        global DEBUG
        DEBUG = debug
        self.connect = sqlite3.connect(dbfile)
        self.online = False
        self.name = name
    def __repr__(self):
        return "<ConDict object for {0}>".format(self.name)
    def __str__(self):
        return "<ConDict object for {0}>".format(self.name)
................................................................................
        '.testmix': {'desc': 'start en-ru test', 'command': None,
            'full': 'start mix test'},
        '.testinfo': {'desc': 'information by test', 'command': None,
            'full': 'full test information by test ID'},
        '.testlist': {'desc': 'list of tests', 'command': None,
            'full': 'this command print list of your tests'},
        }
    def __init__(self, name, dbfile, debug, ctest=10):
        super().__init__(name, dbfile, debug)       
        self.__pcounter = 3
        self.ctest = ctest
        self.init_command()
        self.user_id = self.get_user()
        self.command_connect()

    def get_user(self):

Changes to dict.csv.

1
2
3
4
"ENGLISH";"RUSSIAN"
"hello";"привет"
"hi";"привет"
"good day";"добрый день"

<
<
<
1



"ENGLISH";"RUSSIAN"



Changes to main.py.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    config = get_config_data(CONF_NAME)
    if not config['database'] or not os.path.exists(config['database']):
        print("Not fount SQLite database")
        return 1
    # get name
    user = config['defuser'] if config['defuser'] else input("User name:")
    # create object
    account = Condt(user, config['database'], config['defctest'])
    if not account:
        print('Validation error, by...')
        return 0
    print(WELCOM)
    while (True):
        conn_status = 'online' if account.online else 'offline'
        prefix = PREFIX.format(account.name, conn_status)







|







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    config = get_config_data(CONF_NAME)
    if not config['database'] or not os.path.exists(config['database']):
        print("Not fount SQLite database")
        return 1
    # get name
    user = config['defuser'] if config['defuser'] else input("User name:")
    # create object
    account = Condt(user, config['database'], config['debug'], config['defctest'])
    if not account:
        print('Validation error, by...')
        return 0
    print(WELCOM)
    while (True):
        conn_status = 'online' if account.online else 'offline'
        prefix = PREFIX.format(account.name, conn_status)