Skip to content

Commit

Permalink
[新增]日志颜色支持notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
longfengpili committed Jul 27, 2023
1 parent 6d4c582 commit 2c71519
Show file tree
Hide file tree
Showing 37 changed files with 150 additions and 131 deletions.
5 changes: 3 additions & 2 deletions pydbapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:20:31
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:35:31
# @github: https://github.com/longfengpili


import os
import logging.config
from pydbapi.conf.logconf import LOGGING_CONFIG
Expand Down
7 changes: 4 additions & 3 deletions pydbapi/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 17:49:13
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:31:46
# @github: https://github.com/longfengpili


from .redshift import RedshiftDB, SqlRedshiftCompile
from .sqlite import SqliteDB, SqliteCompile
from .mysql import MysqlDB, SqlMysqlCompile
Expand Down
7 changes: 4 additions & 3 deletions pydbapi/api/mysql.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 17:49:58
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:31:52
# @github: https://github.com/longfengpili


import re
import threading
import pymysql
Expand Down
7 changes: 4 additions & 3 deletions pydbapi/api/redshift.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 17:50:05
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:32:58
# @github: https://github.com/longfengpili


import threading
import psycopg2

Expand Down
7 changes: 4 additions & 3 deletions pydbapi/api/snowflake.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:05:45
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:33:01
# @github: https://github.com/longfengpili


# import threading
# import snowflake.connector

Expand Down
7 changes: 4 additions & 3 deletions pydbapi/api/sqlite.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:04:44
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:32:24
# @github: https://github.com/longfengpili


import os
import threading
import sqlite3
Expand Down
7 changes: 4 additions & 3 deletions pydbapi/api/trino.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:04:50
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:33:08
# @github: https://github.com/longfengpili


import re
import tqdm
import pandas as pd
Expand Down
7 changes: 4 additions & 3 deletions pydbapi/col/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:04:59
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:33:34
# @github: https://github.com/longfengpili


from .colmodel import ColumnModel, ColumnsModel

__all__ = ['ColumnModel', 'ColumnsModel']
7 changes: 4 additions & 3 deletions pydbapi/col/colmodel.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:05:10
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:33:37
# @github: https://github.com/longfengpili


class ColumnModel(object):

def __init__(self, newname, coltype='varchar', sqlexpr=None, func=None, order=0, desc=None):
Expand Down
7 changes: 4 additions & 3 deletions pydbapi/conf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:05:23
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:34:08
# @github: https://github.com/longfengpili


from .myhandlers import MakeFileHandler
from .logconf import *

Expand Down
17 changes: 9 additions & 8 deletions pydbapi/conf/logconf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# @Author: chunyang.xu
# @Email: [email protected]
# @Date: 2020-06-10 14:14:53
# @Last Modified time: 2022-08-11 11:56:34
# -*- coding: utf-8 -*-
# @Author: longfengpili
# @Date: 2023-07-26 17:46:27
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:38:28
# @github: https://github.com/longfengpili

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

import re
import os
Expand All @@ -17,8 +16,10 @@

# logging settings
USERPATH = os.environ['USERPROFILE'] if 'USERPROFILE' in os.environ else os.environ['HOME'] if 'HOME' in os.environ else ''
LOG_BASE_PATH = os.path.join(USERPATH, '.pydbapilog') # 可以user目录下查看日志
LOG_BASE_PATH = os.path.join(USERPATH, 'snapilog') # 可以user目录下查看日志
PROJECT_NAME = re.sub(':?\\\\', '_', os.getcwd())
PROJECT_NAME = PROJECT_NAME[1:] if PROJECT_NAME.startswith('/') else PROJECT_NAME # linux

LOGGING_CONFIG = {
'version': 1, # 保留字
'disable_existing_loggers': False, # 禁用已经存在的logger实例
Expand Down Expand Up @@ -62,7 +63,7 @@
'level': 'DEBUG',
'filters': [],
'class': 'logging.StreamHandler', #
'formatter': 'color' if sys.stdout.isatty() else 'simple'
'formatter': 'color' if sys.stdout.isatty() or any("jupyter" in arg for arg in sys.argv) else 'simple'
},
# 默认的
'default': {
Expand Down
7 changes: 4 additions & 3 deletions pydbapi/conf/myhandlers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:05:56
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:34:11
# @github: https://github.com/longfengpili


import logging.handlers
import os
import errno
Expand Down
7 changes: 4 additions & 3 deletions pydbapi/db/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:06:06
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:34:41
# @github: https://github.com/longfengpili


from .base import DBMixin
from .fileexec import DBFileExec

Expand Down
7 changes: 4 additions & 3 deletions pydbapi/db/base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:06:11
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:34:43
# @github: https://github.com/longfengpili


import re
import pandas as pd
from tqdm import tqdm
Expand Down
7 changes: 4 additions & 3 deletions pydbapi/db/fileexec.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:06:17
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:34:45
# @github: https://github.com/longfengpili


import os
import time

Expand Down
11 changes: 5 additions & 6 deletions pydbapi/sql/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# @Author: chunyang.xu
# @Email: [email protected]
# @Date: 2020-06-03 10:31:36
# @Last Modified time: 2021-02-01 19:18:38
# -*- coding: utf-8 -*-
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:35:17
# @github: https://github.com/longfengpili

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

from .parse import SqlParse, SqlFileParse
from .compile import SqlCompile
Expand Down
12 changes: 5 additions & 7 deletions pydbapi/sql/compile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# @Author: chunyang.xu
# @Email: [email protected]
# @Date: 2020-06-03 14:04:33
# @Last Modified time: 2022-08-11 14:59:26
# -*- coding: utf-8 -*-
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:35:21
# @github: https://github.com/longfengpili

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


from pydbapi.col import ColumnsModel

Expand Down
11 changes: 5 additions & 6 deletions pydbapi/sql/parse.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# @Author: chunyang.xu
# @Email: [email protected]
# @Date: 2020-06-03 10:51:08
# @Last Modified time: 2023-02-10 15:17:36
# -*- coding: utf-8 -*-
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:35:15
# @github: https://github.com/longfengpili

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

import re
import os
Expand Down
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:19:32
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:43:11
# @github: https://github.com/longfengpili
#


import os
import sys
import shutil
import setuptools

VERSION = '0.0.107'
VERSION = '0.0.108'
PROJECT_NAME = 'pydbapi'

with open('README.md', 'r', encoding='utf-8') as f:
Expand Down
6 changes: 3 additions & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:19:23
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:42:45
# @github: https://github.com/longfengpili
7 changes: 4 additions & 3 deletions tests/base/db_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:22:19
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:41:50
# @github: https://github.com/longfengpili


import pytest

from pydbapi.sql import SqlParse
Expand Down
9 changes: 5 additions & 4 deletions tests/base/sql.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*
* @Author: chunyang.xu
* @Date: 2020-06-04 17:57:10
* @Email: [email protected]
* @Last Modified time: 2020-06-28 14:18:55
* @Author: longfengpili
* @Date: 2023-06-02 15:27:41
* @Last Modified by: longfengpili
* @Last Modified time: 2023-07-27 15:41:50
*/


#【arguments】#
date_min = '2020-02-12'
date_max = '2020-02-13'
Expand Down
6 changes: 3 additions & 3 deletions tests/colmodel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:06:59
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:42:35
# @github: https://github.com/longfengpili
6 changes: 3 additions & 3 deletions tests/colmodel/test_colmodel.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:07:04
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:41:50
# @github: https://github.com/longfengpili


Expand Down
6 changes: 3 additions & 3 deletions tests/mysql/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# @Author: chunyang.xu
# @Author: longfengpili
# @Date: 2023-06-02 15:27:41
# @Last Modified by: chunyang.xu
# @Last Modified time: 2023-07-26 18:07:35
# @Last Modified by: longfengpili
# @Last Modified time: 2023-07-27 15:42:30
# @github: https://github.com/longfengpili
Loading

0 comments on commit 2c71519

Please sign in to comment.