def select_one(p_id=None):
     books = BookinfoDAO.select()
     for book in books:
         if p_id is not None and book.id == p_id:
             logger.info("SELECT BY ID:")
             logger.info(book)
             return book
     return None
 def select_one(p_id=None):
     if p_id is not None and type(p_id) is not int:
         raise ValueError("p_id 参数类型错误.")
     borrows = BorrowregDAO.select()
     for borrow in borrows:
         if p_id is not None and borrow.id == p_id:
             logger.info("SELECT BY ID:")
             logger.info(borrow)
             return borrow
     return None
Exemple #3
0
    def do_action(self):
        if len(self.PAGE_ACTIONS) == 0:
            logger.warning("页面未定义actions")
            return

        elif len(self.PAGE_ACTIONS) == 1:
            action_str = self.PAGE_ACTIONS[0]["ACTION"]
        else:
            command_line = ""
            for action in self.PAGE_ACTIONS:
                if "AUTH" in action and not self.user.is_admin:
                    continue
                if command_line:
                    command_line += ','
                command_line += f'{action["DESC"]}({action["KEY"].upper()})'
            logger.debug(command_line)

            print("您可以选择如下操作:")
            if self.home_page:
                print("首页(H),", end='')
            if self.prev_page and self.prev_page is not self.home_page:
                print("上一页(B),", end='')
            print(command_line)

            actions = [d["KEY"] for d in self.PAGE_ACTIONS] + ['h', 'b']
            while True:
                command = input("请输入:")
                if command.lower() in actions:
                    logger.debug(f"用户输入的命令是:{command}")
                    break
                else:
                    print("输入有误,请重新输入...")

            # 回首页
            if command.lower() == 'h':
                self.home_page.show()
            if command.lower() == 'b':
                self.prev_page.show()

            # 根据用户的指令获取 action 字符串
            for action in self.PAGE_ACTIONS:
                if command.lower() == action["KEY"].lower():
                    action_str = action["ACTION"]
                    logger.debug("找到指令:" + action_str)
                    break
        # 反射调用 登录、注册、退出等方法
        module, funcname = action_str.split('.')
        module = __import__("actions." + module, fromlist=True)
        if hasattr(module, funcname):
            logger.info(f">>> action: {action_str}")
            action_func = getattr(module, funcname)
            action_func(self)
        else:
            print(f"指令{command}的{funcname}方法未定义")
    def insert(p_borrow):
        """
        插入借阅信息
        :param p_borrow: Borrowreg对象
        :return: None
        """
        if type(p_borrow) is not Borrowreg:
            raise TypeError("参数类型必须为Borrowreg对象.")

        if os.path.exists(BorrowregDAO.FILE_NAME):
            r_borrows = BorrowregDAO.select()
            p_borrow.id = r_borrows[-1].id + 1
        else:
            p_borrow.id = 1

        with open(BorrowregDAO.FILE_NAME,
                  'a',
                  encoding=SuperModel.FILE_ENCODING) as af:
            af.write(p_borrow.to_file_str())
        logger.info("INSERT borrow:")
        logger.info(p_borrow)
 def update(p_borrow):
     if p_borrow is not None and p_borrow.id > 0:
         borrows = BorrowregDAO.select()
         for borrow in borrows:
             if borrow.id == p_borrow.id:
                 logger.debug(borrow)
                 logger.debug(p_borrow)
                 borrow.borrow_user_id = p_borrow.borrow_user_id
                 borrow.return_user_id = p_borrow.return_user_id
                 borrow.book_id = p_borrow.book_id
                 borrow.state = p_borrow.state
                 logger.info("UPDATE borrow:")
                 logger.info(borrow)
                 break
         with open(BorrowregDAO.FILE_NAME,
                   'w',
                   encoding=SuperModel.FILE_ENCODING) as wf:
             for borrow in borrows:
                 wf.write(borrow.to_file_str())
     else:
         raise ValueError("借阅信息错误.")
Exemple #6
0
def do_login(page):
    logger.info("用户登录检查")
    username = get_input(message="请输入用户名:", warning="用户名不能为空")
    logger.debug(f"用户名:{username}")

    password = get_input(message="请输入密码:", warning="密码不能为空", is_password=True)

    try:
        user = UserinfoDAO.select_one(username)
        logger.info(f"当前用户 {str(user)}")
        # 检查密码
        if user is None or\
                user.password != encrypt_password(password, username):
            raise PermissionError("用户名或密码错误")
        input("登录成功...按任意键继续")

        # 进入 homepage
        HomePage(user).show()
    except Exception as e:
        logger.exception(e)
        input(str(e) + "...按任意键重新输入")
        page.show()
Exemple #7
0
    def wrapper(page):
        logger.info("管理员权限检查:")
        logger.info(page.user)
        logger.info(page)

        if not page.user.is_admin:
            raise PermissionError("权限不足")
        func(page)
    def insert(p_book):
        """
        插入图书信息
        :param p_book: Bookinfo 对象
        :return: None
        """
        if type(p_book) is not Bookinfo:
            raise TypeError("参数必须为 Bookinfo 对象")
        if os.path.exists(BookinfoDAO.FILE_NAME):
            r_books = BookinfoDAO.select()
            p_book.id = r_book[-1].id + 1
        else:
            p_book.id = 1

        if p_book.state is None:
            p_book.state = Bookinfo.BOOK_STATUS["NORMAL"]

        with open(BookinfoDAO.FILE_NAME,
                  'a',
                  encoding=SuperModel.FILE_ENCODING) as af:
            af.write(p_book.to_file_str())
        logger.info("INSERT book")
        logger.info(p_book)
 def update(p_book):
     if p_book is not None and p_book.id > 0:
         books = BookinfoDAO.select()
         for book in books:
             if book.id == p_book.id:
                 logger.debug(book)
                 logger.debug(p_book)
                 book.bookname = p_book.bookname
                 book.booktype = p_book.booktype
                 book.author = p_book.author
                 book.state = p_book.state
                 book.is_borrow = p_book.is_borrow
                 book.createuser = p_book.createuser
                 logger.info("UPDTE book:")
                 logger.info(book)
                 break
         with open(BookinfoDAO.FILE_NAME,
                   'w',
                   encoding=SuperModel.FILE_ENCODING) as wf:
             for book in books:
                 wf.write(book.to_file_str())
     else:
         raise ValueError("图书信息错误")
Exemple #10
0
    def wrapper(page):
        try:
            logger.info("登录检查:")
            logger.info(page.user)
            logger.info(page)

            if page.user is None:
                raise PermissionError("请登录")
            func(page)
        except Exception as e:
            logger.exception(e)
            print(e)
INFO    logging.info()  20  動作情報表示用
DEBUG   logging.debug() 10  詳細な情報表示用
NOTSET      0   全てを出力。基本的に設定用の値

フォーマット  概要
%(asctime)s 実行時刻
%(filename)s    ファイル名
%(funcName)s    関数名
%(levelname)s   DEBUG、INFO等のレベル名
%(lineno)d  行番号
%(name)s    呼びだしたログの定義名
%(module)s  モジュール名
%(message)s ログメッセージ
%(process)d プロセスID
%(thread)d  スレッドID

Created by 0160929 on 2016/02/04 14:37
"""
__version__ = '0.0'

import os
import sys

from applogger import logger

for i in range(10000):
    logger.error("Error!")  # 40  重大な問題用
    logger.warning("Warning..")  #  30  実行機能で問題が発生した場合用
    logger.info("Hello Logger :D")  # 20  動作情報表示用
    logger.debug("Hello Logger is run...")  # 10  詳細な情報表示用
Exemple #12
0
def sys_exit(page):
    print("再见,欢迎下次使用...")
    logger.info("用户退出系统")
    sys.exit(0)