示例#1
0
文件: note.py 项目: doopath/doondler
 def __init__(self, author, message, deadline=None, full_deadline=None):
     self.author = author
     self.message = message
     self.deadline = full_deadline or deadline
     self.fixed_deadline = bool(full_deadline)
     self.home_dir = get_path("home")
     logger.log("An instance of the modules.note.Note class was created.")
示例#2
0
文件: user.py 项目: doopath/doondler
def check_if_config_exists():
    """ Check if required configuration file exists. """
    if not os.path.isfile(get_path("config")):
        logger.log(
            Warning(
                "✘ You haven't initialized! Execute doondler --init to create a"
                " user config file and continue!"))
        raise InitializationError(
            "Initialization error! Initialize and try again!")
示例#3
0
    def __init__(self):
        self.default = {
            "username":
            getpass.getuser(),
            "home_dir":
            get_path("home"),
            "city":
            "moscow",
            "handler":
            yuigahama.Handler,
            "package_manager":
            DefaultManager().get_default_manager(ask_if_not_found=False).name
        }
        self.username = {
            "value": "",
            "main_question":
            f"Do you want to change your name to call you or keep default={self.default['username']}?",
            "confirm_question": "Ok, then enter a new name",
            "default": self.default["username"]
        }
        self.home_dir = {
            "value": "",
            "main_question":
            f"Do you want to change your home dir or keep default={self.default['home_dir']}?",
            "confirm_question": "Ok, then enter a path",
            "default": self.default["home_dir"]
        }
        self.city = {
            "value": "",
            "main_question":
            f"Do you want to change your home dir or keep default={self.default['city']}?",
            "confirm_question":
            "Ok, so enter your city like <los-angeles> or <nizhny-novgorod>",
            "default": self.default["city"]
        }
        self.handler = {
            "value": "",
            "main_question":
            f"Do you want to change your home dir or keep default={self.default['handler'].name}?",
            "confirm_question": "Ok, then enter a handler's name",
            "default": self.default["handler"].name
        }
        self.package_manager = {
            "value": "",
            "main_question":
            f"Do you want to change your package manager or keep default={self.default['package_manager']}?",
            "confirm_question": "Ok, then enter your package manager",
            "default": self.default["package_manager"]
        }

        del self.__dict__["default"]
示例#4
0
文件: user.py 项目: doopath/doondler
""" There is basic user info """
import os
import sys

from modules.config_reader import ConfigReader
from modules.logger import logger
from modules.paths import get_path
from modules.errors import *

home = get_path("home")
config_reader = ConfigReader(get_path("config"))


def check_if_config_exists():
    """ Check if required configuration file exists. """
    if not os.path.isfile(get_path("config")):
        logger.log(
            Warning(
                "✘ You haven't initialized! Execute doondler --init to create a"
                " user config file and continue!"))
        raise InitializationError(
            "Initialization error! Initialize and try again!")


class User:
    """ Main user class """
    def __init__(self):
        self.username = ""
        self.city = ""
        self.home_dir = ""
        self.handler = ""
示例#5
0
 def __init__(self):
     super().__init__()
     self.user = {}
     self.main_path = get_path("config")
     self.copy_path = get_path("config-copy")
     logger.log("Created an instance of the modules.config.Config class")
示例#6
0
 def _create_logfile(self):
     logfile = open(get_path("logs"), "w+")
     logfile.close()
示例#7
0
 def __init__(self):
     self.city = ConfigReader(get_path("config")).read()["city"]
     self.api_url = f"https://yandex.com/pogoda/{self.city}"
     self.headers = {'User-Agent': UserAgent().chrome}
     logger.log(
         "An instance of the modules.synoptic.Synoptic class was made.")
示例#8
0
"""
import os
from time import time
from time import sleep

from modules.yuigahama import Handler
from modules.user import User
from modules.paths import get_path
from tests.test_box import test_box
from tests.success import success

user = User()
user.create()
handler = Handler(user)
DEADLINE = round(time()) + 3
NOTE_PATH = get_path("note") + str(DEADLINE)


def check_if_file_exists(path: str):
    """ Check if file exists. """
    existence = os.path.isfile(path)
    test_name = f"Test of file {path}"

    assert existence, test_name
    success(test_name)


def wait_note_deleting(deadline: int):
    """ Wait while note is alive. """
    while time() * 1000 < deadline:
        sleep(1)
示例#9
0
 def __init__(self, path=None):
     self.path = path or get_path("config")
     logger.log(
         "Created an instance of the modules.config_reader.ConfigReader class."
     )
示例#10
0
 def __init__(self, log_path: str = get_path("logs")):
     self.log_path = log_path
     self.log_level = 2
     self.enable_traceback = True
示例#11
0
"""
    Config reader module tests.
    These tests require correct working of the config_writer module.
"""

import os
import sys
from modules.config_reader import ConfigReader
from modules.config_writer import ConfigWriter
from modules.paths import get_path
from tests.test_box import test_box
from tests.success import success


CONFIG_PATH = get_path("config")
config_reader = ConfigReader(CONFIG_PATH)


def check_config_size(config_content: str):
    """ Check if config size is correct. """
    config_size = sys.getsizeof(config_content)
    assert config_size > 50, "Incorrect config size (less than 50 bytes)"

    success("Config size test")


def check_config_length(config_content: str):
    """ Check config length is correct. """
    assert len(config_content) >= 4, "Incorrect config length!"

    success("Config length test")
示例#12
0
""" Testing of the config handler file. """
import os
import sys

from modules.config import Config
from modules.paths import get_path
from tests.success import success
from tests.test_box import test_box

config = Config()

CONFIG_PATH = get_path("config")
LOGS_PATH = get_path("logs")


def warn_before_testing():
    """ Ask user if he wants to continue. """
    question = "Your config file will be removed while testing, "\
        "do you want to continue? (y/n): "
    answer = input(question).upper()

    if answer == "N":
        print("Testing was interrupted.")
        sys.exit()
    elif answer != "N" and answer != "Y":
        print("Please, answer y or n.")
        warn_before_testing()


def remove_file(path: str):
    """ Remove file if it exists. """
示例#13
0
 def __init__(self, path=get_path("config")):
     self.path = path
     self.config_reader = ConfigReader(self.path)
     logger.log("Created an instance of the modules.config_writer.ConfigWriter class.")
示例#14
0
""" Testing of the note module. """
from time import time
from time import sleep
import os
import sys

from modules.note import Note
from modules.paths import get_path
from tests.success import success
from tests.test_box import test_box

TIMEOUT = 3  # Seconds
DEADLINE = round(time()) + TIMEOUT
NOTE_PATH = get_path("note") + str(DEADLINE)
LOG_PATH = get_path("note") + f"{DEADLINE}_output"

TIMEOUT_2 = 7
DEADLINE_2 = round(time()) + TIMEOUT_2
NOTE_PATH_2 = get_path("note") + str(DEADLINE_2)
LOG_PATH_2 = get_path("note") + f"{DEADLINE_2}_output"


def check_if_file_exists(path: str):
    """ Check if created note exists. """
    exists = os.path.isfile(path)

    if exists:
        success(f"Test of the {path} file existing.")

    return os.path.isfile(path)