From dc8e7037e56f64c762b005a8f613d64818b9e817 Mon Sep 17 00:00:00 2001 From: Yunus Emre <49655146+yedhrab@users.noreply.github.com> Date: Fri, 21 Feb 2020 12:46:04 +0300 Subject: [PATCH] Merge branch 'master' of https://github.com/yedhrab/YPackage --- CHANGELOG.md | 6 +++++ setup.py | 6 +++-- ypackage/background.py | 37 ++++++++++++++++++++++++++ ypackage/cli/file_renamer.py | 8 +++--- ypackage/cli/gdrive.py | 3 ++- ypackage/cli/gsearch.py | 3 ++- ypackage/cli/integrate_into_gitbook.py | 5 ++-- ypackage/cli/theme_creator.py | 2 +- ypackage/common.py | 19 +++++++------ ypackage/gitbook.py | 4 +-- 10 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 ypackage/background.py diff --git a/CHANGELOG.md b/CHANGELOG.md index c370480..4e4ec18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 👀 What's New +## 🏷️ 2.7.3 + +- 🌃 Background package added +- 🎨 Colorful log added +- ✨ Logging improved + ## 🏷️ 2.7.2 - 👨‍🔧 Package names fixed diff --git a/setup.py b/setup.py index 91aec89..41fcb8b 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ README_PATH = "docs/README.md" DYNAMIC_VERSION = False -VERSION = "2.7.2" +VERSION = "2.7.3" if DYNAMIC_VERSION: version = "" @@ -28,6 +28,7 @@ author_email="yemreak.com@gmail.com", license='Apache Software License 2.0', url='https://github.com/yedhrab/YPackage', + download_url=f'https://github.com/yedhrab/YPackage/archive/{version}.tar.gz', keywords=[ 'ypackage', 'yedhrab', 'yemreak', 'gitbook', 'github', 'google-search', "google", "link", "drive", "renamer", "bulk" @@ -35,7 +36,8 @@ install_requires=[ "google", "requests", - "pydriller" + "pydriller", + "coloredlogs" ], classifiers=[ # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" diff --git a/ypackage/background.py b/ypackage/background.py new file mode 100644 index 0000000..e382576 --- /dev/null +++ b/ypackage/background.py @@ -0,0 +1,37 @@ +from threading import Thread, Timer + + +def do_background(func, args=(), kwargs={}): + return Thread(target=func, args=args, kwargs=kwargs).start() + + +def do_delayed(func, duration, args=(), kwargs={}): + return Timer(duration, func, args, kwargs).start() + + +def background(func): + + def inner(*args, **kwargs): + do_background(func, args=args, kwargs=kwargs) + + return inner + + +def delayed(duration): + def background(func): + + def inner(*args, **kwargs): + do_delayed(func, duration, args=args, kwargs=kwargs) + + return inner + return background + + +if __name__ == "__main__": + + @delayed(1) + def test(val1, val2): + for i in range(val1, val2): + print(i) + + test(3, 20) diff --git a/ypackage/cli/file_renamer.py b/ypackage/cli/file_renamer.py index 638702f..5d3c5a9 100644 --- a/ypackage/cli/file_renamer.py +++ b/ypackage/cli/file_renamer.py @@ -70,10 +70,10 @@ def main(): PATTERN, TO = args.pattern, args.to SILENT = args.silent - initialize_logging() + logger = logging.getLogger(__name__) - if SILENT: - logging.basicConfig(level=logging.ERROR) + log_level = logging.ERROR if SILENT else logging.DEBUG + initialize_logging(level=log_level) for path in PATHS: function = rename_folders if DIR_MODE else rename_files @@ -86,7 +86,7 @@ def main(): ) if not result: - logging.info(f"{PATTERN=} {RECURSIVE=} için değişiklik yapılmadı") + logger.warning(f"{PATTERN=} {RECURSIVE=} için değişiklik yapılmadı") if __name__ == "__main__": diff --git a/ypackage/cli/gdrive.py b/ypackage/cli/gdrive.py index c2c13ce..e26e14d 100644 --- a/ypackage/cli/gdrive.py +++ b/ypackage/cli/gdrive.py @@ -63,7 +63,8 @@ def main(): args = initialize_parser().parse_args() URLS, REVERSE, DEBUG = args.urls, args.revers, args.debug - initialize_logging(detailed=DEBUG) + log_level = logging.DEBUG if DEBUG else logging.INFO + initialize_logging(level=log_level) function = drive_to_direct if not REVERSE else direct_to_drive for url in URLS: diff --git a/ypackage/cli/gsearch.py b/ypackage/cli/gsearch.py index 79bfad2..f4226a2 100644 --- a/ypackage/cli/gsearch.py +++ b/ypackage/cli/gsearch.py @@ -93,7 +93,8 @@ def main(): QUERIES, STATUS_CODE, EXCLUDE = args.queries, args.status_code, args.exclude OUTPUT, DEBUG = args.output, args.debug - initialize_logging(detailed=DEBUG) + log_level = logging.DEBUG if DEBUG else logging.INFO + initialize_logging(level=log_level) for query in QUERIES: filename = re.sub(r"[^\w ]", "_", query) + ".txt" if not OUTPUT else OUTPUT diff --git a/ypackage/cli/integrate_into_gitbook.py b/ypackage/cli/integrate_into_gitbook.py index 52538dd..39aeea6 100644 --- a/ypackage/cli/integrate_into_gitbook.py +++ b/ypackage/cli/integrate_into_gitbook.py @@ -7,7 +7,7 @@ from pathlib import Path from typing import Dict -from .ort common, filesystem, gitbook, github, markdown +from .. import common, filesystem, gitbook, github, markdown logger = logging.getLogger(__name__) @@ -366,7 +366,8 @@ def main(): register_args(parser, register_all=True) - common.initialize_logging(detailed=DEBUG) + log_level = logging.DEBUG if DEBUG else logging.INFO + common.initialize_logging(level=log_level) override_config = any([GENERATE, RECREATE, UPDATE, CHANGELOG]) for pathstr in PATHSTR_LIST: diff --git a/ypackage/cli/theme_creator.py b/ypackage/cli/theme_creator.py index b3b3899..01587a0 100644 --- a/ypackage/cli/theme_creator.py +++ b/ypackage/cli/theme_creator.py @@ -111,7 +111,7 @@ def main(): # Gettings args PATHS, DEBUG = args.paths, args.debug - initialize_logging(detailed=DEBUG) + initialize_logging(level=DEBUG) for path in PATHS: path = Path(path) diff --git a/ypackage/common.py b/ypackage/common.py index a11b699..c59eb2e 100644 --- a/ypackage/common.py +++ b/ypackage/common.py @@ -1,16 +1,19 @@ -import re import logging +import re + +logger = logging.getLogger(__name__) + +def initialize_logging(level=logging.INFO): + import coloredlogs -def initialize_logging(detailed=False): - if detailed: - logformat = r"%(levelname)s:%(filename)s %(message)s" - loglevel = logging.DEBUG + if level == logging.DEBUG: + log_format = r"%(name)s[%(process)d] %(levelname)s %(message)s" else: - logformat = r"%(message)s" - loglevel = logging.INFO + log_format = r"%(levelname)s %(message)s" - logging.basicConfig(format=logformat, level=loglevel) + coloredlogs.install(fmt=log_format, level=level) + logger.debug("Rekli raporlayıcı aktif edildi") def exit_if_not(condition, message=None): diff --git a/ypackage/gitbook.py b/ypackage/gitbook.py index 1d0f620..b3787de 100644 --- a/ypackage/gitbook.py +++ b/ypackage/gitbook.py @@ -23,7 +23,7 @@ SUMMARY_FILE = "SUMMARY.md" SUMMARY_FILE_HEADER = "# Summary" -CHANGELOG_FILE = "CHANGELOG.md" +CHANGELOG_FILE = "changelog.md" CHANGELOG_HEADER = u"👀 Neler değişti" CONTRIBUTING_HEADER = u"💖 Katkıda Bulunma Rehberi" GITHUB_USERNAME = "yedhrab" @@ -301,7 +301,7 @@ def create_changelog( cpath = path / CHANGELOG_FILE - filestr = "# ✨ Değişiklikler" + filestr = "# " + CHANGELOG_HEADER filestr += "\n\n" filestr += "## 📋 Tüm Değişiklikler" filestr += "\n\n"