Ejemplo n.º 1
0
def test_invalid_input():
    with pytest.raises(ValueError):
        _ = liteconfig.Config(14)
    with pytest.raises(ValueError):
        _ = liteconfig.Config(True)
    with pytest.raises(ValueError):
        _ = liteconfig.Config((23,))
    with pytest.raises(ValueError):
        _ = liteconfig.Config({'we': 'they'})
Ejemplo n.º 2
0
 def __init__(self, creds_file):
     creds = liteconfig.Config(creds_file)
     oauth = Credentials(creds.access_token,
                         refresh_token=creds.refresh_token,
                         token_uri=creds.token_uri,
                         client_id=creds.client_id,
                         client_secret=creds.client_secret)
     self.worker = GoogleDriveFS(oauth)
Ejemplo n.º 3
0
def test_write(simple_config):
    simple_config.write('tests/fixtures/out.ini')
    test_read = liteconfig.Config('tests/fixtures/out.ini')
    os.remove('tests/fixtures/out.ini')
    assert simple_config._Config__properties == test_read._Config__properties
    assert len(test_read._Config__properties) == 3
    assert simple_config._Config__sections == test_read._Config__sections
    assert len(test_read._Config__sections) == 2
    assert simple_config.property == test_read.property
    assert simple_config.section.first == test_read.section.first, 1
    assert simple_config.partition.second == test_read.partition.second, 2
Ejemplo n.º 4
0
def encodings(request):
    return liteconfig.Config(koi8r_file, encoding=request.param)
Ejemplo n.º 5
0
def parse_booleans(request):
    return liteconfig.Config(
        ['a = yes', 'b = no', 'c = True', 'd = False', 'e = on', 'f = off'],
        parse_booleans=request.param)
Ejemplo n.º 6
0
def parse_numbers(request):
    return liteconfig.Config(['rough_pi = 3', 'pi = 3.14'],
                             parse_numbers=request.param)
Ejemplo n.º 7
0
def comment_markers():
    return liteconfig.Config(['-property: is here', '=property: is here'],
                             comment_markers='-=')
Ejemplo n.º 8
0
def delimiter_configs(request):
    return liteconfig.Config([f'property{request.param} is here'],
                             delimiter=request.param)
Ejemplo n.º 9
0
def simple_config():
    return liteconfig.Config([
        'property = value', '[section]', 'first = 1', '[partition]',
        'second = 2'
    ])
Ejemplo n.º 10
0
    authorization_url, _ = session.authorization_url(authorization_base_url,
                                                     access_type="offline")
    print(
        f"Go to the following URL and authorize the app. When you'll authorize it, your browser will"
        f"try to redirect you to https://localhost?state=BLABLABLA page. It will fail, of course, because"
        f"such an URL your computer does not serve. Please copy it and paste a moment later: {authorization_url}"
    )
    redirectResponse = input("Paste the full redirect URL here:")
    tokenUrl = "https://oauth2.googleapis.com/token"
    token = session.fetch_token(tokenUrl,
                                client_secret=client_secret,
                                authorization_response=redirectResponse)

    if 'access_token' in token.keys() and 'refresh_token' in token.keys():
        print(
            "Everything seems to be OK! Credentials are saved to 'mediums/googledrive-credentials' file."
            "Please make sure you save this in your .ini file in section 'upload' under 'creds' keyword, like"
            "creds = mediums/googledrive-credentials")
        cfg = [
            f"token_uri = https://www.googleapis.com/oauth2/v4/token",
            f"client_id = {client_id}", f"client_secret = {client_secret}",
            f"access_token = {token['access_token']}",
            f"refresh_token = {token['refresh_token']}"
        ]
        google_creds = liteconfig.Config(cfg)
        google_creds.write('googledrive-credentials')
    else:
        print(
            "Something went wrong. Try again, and if problem persists, please contact developer."
        )
Ejemplo n.º 11
0
def test_write_with_comments(comments_list):
    liteconfig.Config(comments_list).write('tests/fixtures/out.ini')
    with open('tests/fixtures/out.ini', 'r', encoding='utf-8') as f:
        config_with_comments = f.read().split('\n')
    os.remove('tests/fixtures/out.ini')
    assert config_with_comments == comments_list
Ejemplo n.º 12
0
def test_not_implemented():
    with pytest.raises(NotImplementedError):
        _ = liteconfig.Config(['hierarchy = test'], hierarchy=1)
Ejemplo n.º 13
0
def test_file_not_found():
    with pytest.raises(FileNotFoundError):
        _ = liteconfig.Config('nonexistent.ini')
Ejemplo n.º 14
0
def exceptions(request):
    return liteconfig.Config(['stray = cats', '[section]', 'truth = lie'],
                             exceptions=request.param)
Ejemplo n.º 15
0
def common_configs(request):
    return liteconfig.Config(request.param)
Ejemplo n.º 16
0
 def __init__(self, creds_file):
     creds = liteconfig.Config(creds_file)
     self.worker = FTPFS(creds.host,
                         user=creds.user,
                         passwd=creds.passwd,
                         port=creds.port or 21)
Ejemplo n.º 17
0
import logging

import smtp_handler


class Singleton(type):
    """Singleton realization via metaclass https://stackoverflow.com/questions/6760685/creating-a-singleton-in-python"""
    _instances = {}

    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
        return cls._instances[cls]


config = liteconfig.Config('camp-my.ini')
# TODO: check config sanity.

if __name__ == '__main__':
    # TODO: make it running as windows service

    # import os
    # os.remove('camp.log')

    logging.basicConfig(filename='camp.log',
                        format='%(asctime)s | %(funcName)s, %(lineno)d: %(message)s',
                        datefmt='%m/%b/%Y %H:%M:%S')
    logging.getLogger().setLevel(config.main.loglevel)
    loop = asyncio.get_event_loop()
    loop.create_task(smtp_handler.smtp_server(config.server.ip, config.server.port))
    try: