diff --git a/CHANGES.md b/CHANGES.md index 56c5444..d510155 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,8 @@ ## 2024 +4.4.5 checking new version of FotoKilof + 4.4.4 logging in proper way 4.4.3 entrypoint to easier run by execution fotokilof diff --git a/README.md b/README.md index 2db8fd5..c4a71a2 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ python3 -m pip install fotokilof #### Windows Download and install requirements: -- [Python3](https://www.python.org/) - add path into `%PATH%` environment variable, +- [Python3.9+](https://www.python.org/) - add path into `%PATH%` environment variable, - [ImageMagick](https://imagemagick.org/script/download.php#windows) - add path into `%PATH%` environment variable, enable install libraries! ```bash diff --git a/fotokilof/__main__.py b/fotokilof/__main__.py index 0d4a00f..9ddba67 100644 --- a/fotokilof/__main__.py +++ b/fotokilof/__main__.py @@ -59,6 +59,7 @@ DISABLED, NORMAL, HORIZONTAL # my modules +import check_new_version import convert import convert_wand import common @@ -908,6 +909,7 @@ def ini_read_wraper(): logging.INFO ) img_custom_on.set(ini_entries['img_custom_on']) + check_version.set(ini_entries['check_version']) # resize ini_entries = ini_read.resize(FILE_INI) img_resize_on.set(ini_entries['img_resize_on']) @@ -1052,20 +1054,21 @@ def ini_save_wraper(): # main config = {'section': 'Main', 'path': file_in_path.get(), - 'custom_on': img_custom_on.get(), 'work_dir': work_dir.get(), 'file_dir': file_dir_selector.get(), 'exif': img_exif_on.get(), - 'preview_new': co_preview_selector_new.get(), + 'custom_on': img_custom_on.get(), 'preview_orig': co_preview_selector_orig.get(), - 'log': log_level.get()} + 'preview_new': co_preview_selector_new.get(), + 'log_level': log_level.get(), + 'check_version': check_version.get()} # resize resize = {'section': 'Resize', 'on': img_resize_on.get(), 'resize': img_resize.get(), - 'size_percent': e2_resize.get(), 'size_pixel_x': e1_resize_x.get(), - 'size_pixel_y': e1_resize_y.get()} + 'size_pixel_y': e1_resize_y.get(), + 'size_percent': e2_resize.get()} # text text = {'section': 'Text', 'on': img_text_on.get(), @@ -1621,6 +1624,7 @@ def text_tool_hide_show(): FILE_INI = os.path.join(os.path.expanduser("~"), ".fotokilof.ini") PWD = os.getcwd() log_level = StringVar() # E(rror), W(arning), M(essage) +check_version = IntVar() # allow to check new version work_dir = StringVar() # default: "FotoKilof" work_sub_dir = StringVar() # subdir for resized pictures work_sub_dir.set("") # default none @@ -2817,6 +2821,12 @@ def text_tool_hide_show(): b_file_select_screenshot.configure(state=DISABLED) root.deiconify() + +if check_version.get(): + if check_new_version.check_version(version.__version__)[0]: + Messagebox.show_warning(_('New version of FotoKilof is available.\nCurrent: ' + version.__version__ +', New: ' + check_new_version.check_version(version.__version__)[1] + '\nRun command:\npython3 -m pip install --upgrade fotokilof'), + title=_('New version of FotoKilof is available')) + root.mainloop() # EOF diff --git a/fotokilof/check_new_version.py b/fotokilof/check_new_version.py new file mode 100644 index 0000000..67bce32 --- /dev/null +++ b/fotokilof/check_new_version.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- + +""" +Copyright (c) 2024 Tomasz Łuczak, TeaM-TL + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +From https://stackoverflow.com/questions/28774852/pypi-api-how-to-get-stable-package-version +""" + +import json +import requests + +try: + from packaging.version import parse +except ImportError: + from pip._vendor.packaging.version import parse + + +URL_PATTERN = 'https://pypi.python.org/pypi/{package}/json' + +def get_version(url_pattern=URL_PATTERN): + """Return version of package on pypi.python.org using json.""" + + package = 'FotoKilof' + version = parse('0') + try: + req = requests.get(url_pattern.format(package=package), timeout=2.50) + request_success = 1 + except: + request_success = 0 + + if request_success and req.status_code == requests.codes.ok: + j = json.loads(req.text.encode(req.encoding)) + releases = j.get('releases', []) + for release in releases: + ver = parse(release) + if not ver.is_prerelease: + version = max(version, ver) + return (request_success, str(version)) + +def check_version(current_version): + """ + Check version of FotoKilof in PyPi + return 1 - get new + return 0 - there are no new + """ + result = 0 + if get_version()[0] and get_version()[1] > current_version: + result = 1 + + return (result, get_version()[1]) diff --git a/fotokilof/ini_read.py b/fotokilof/ini_read.py index 6972efc..5a471a5 100644 --- a/fotokilof/ini_read.py +++ b/fotokilof/ini_read.py @@ -107,6 +107,12 @@ def main(file_ini, preview_size_list): ("E", "W", "M"), "E") + try: + check_version = config.getint('Main', 'check_version') + except: + check_version = 1 + dict_return['check_version'] = entries.parse_list(check_version, (0, 1), 0) + return dict_return diff --git a/fotokilof/ini_save.py b/fotokilof/ini_save.py index a5b0ca4..eda0c7c 100644 --- a/fotokilof/ini_save.py +++ b/fotokilof/ini_save.py @@ -40,9 +40,9 @@ """ import configparser +import logging import common -import logging def save(ini_data): @@ -73,7 +73,8 @@ def save(ini_data): config.set(main['section'], 'custom', str(main['custom_on'])) config.set(main['section'], 'preview_orig', main['preview_orig']) config.set(main['section'], 'preview_new', main['preview_new']) - config.set(main['section'], 'log', main['log']) + config.set(main['section'], 'log_level', main['log_level']) + config.set(main['section'], 'check_version', main['check_version']) # resize config.add_section(resize['section']) config.set(resize['section'], 'on', str(resize['on'])) diff --git a/fotokilof/version.py b/fotokilof/version.py index 615e51a..dea2140 100644 --- a/fotokilof/version.py +++ b/fotokilof/version.py @@ -22,7 +22,7 @@ THE SOFTWARE. """ -__version__ = "4.4.4" +__version__ = "4.4.5" __author__ = "Tomasz Łuczak" __email__ = "tlu@team-tl.pl" __appname__ = "FotoKilof"