Skip to content

Commit

Permalink
Add version show and actual version check from PyPI
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaBeloglazov committed Sep 9, 2023
1 parent 0ada3b4 commit c27772e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#### TODO:
* Change clipboard module
* Desktop notifications support
* Auto-updates feature
* RPM packaging


and more..

# Install
Expand All @@ -49,7 +49,7 @@ pip3 install -r requirements.txt

And then run it
```shell
python3 yt.py
cd src/ytcon && python3 yt.py
```

# Support
Expand Down
82 changes: 79 additions & 3 deletions src/ytcon/yt.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ def delete_after_download_switch(self, _=None, _1=None):
class RenderClass_base:
""" It stores some information about rendering, screen, some functions for working with widgets and some functions that are related to rendering. """
def __init__(self):
self.version = "?.?.?"
self.install_source = "???"
self.pypi_version = "?.?.?"
self.tried_check_pypi_version = False

self.methods = self.MethodsClass()
self.settings_show = False

Expand Down Expand Up @@ -817,7 +822,6 @@ def input_handler(self, text):

InputHandler = InputHandlerClass()


def errorprinter(loop, _):
""" Draws errors in error_widget in red, after some time (specified in the timer) removes error messages """
try:
Expand Down Expand Up @@ -967,6 +971,31 @@ def tick_handler(loop, _):
exit_with_exception(traceback.format_exc())
# - = - = - = - = - = - = - = - = -

# - = - = - = - = - = - = - = - = -
# GET LATEST VERSION NUMBER FROM PYPI
if RenderClass.tried_check_pypi_version is False:
#print("Check updates.. :)")
try:
import requests
RenderClass.pypi_version = requests.get("https://pypi.org/pypi/ytcon/json", timeout=20).json()["info"]["version"]
except:
pass

textt = f"Your YTCON version: {RenderClass.version} (from {RenderClass.install_source}) / Actual YTCON version: {RenderClass.pypi_version}"

if RenderClass.version == "?.?.?" or RenderClass.pypi_version == "?.?.?":
settings_version_text.set_text((RenderClass.yellow, textt))
elif RenderClass.version == RenderClass.pypi_version:
settings_version_text.set_text((RenderClass.green, textt))
elif RenderClass.version != RenderClass.pypi_version:
if RenderClass.install_source == "pip":
textt = textt + "\n\nUpdate using pipx or pip:\n - pipx upgrade ytcon\n OR\n - pip3 install -U ytcon\n"
if RenderClass.install_source == "git":
textt = textt + "\n\nUpdate using git:\n - git clone https://github.com/NikitaBeloglazov/ytcon\n"

settings_version_text.set_text((RenderClass.red, textt))
# - = - = - = - = - = - = - = - = -

# Prevent focus from remaining on footer buttons after pressing them
main_footer.set_focus(input_widget)
# - =
Expand Down Expand Up @@ -1035,6 +1064,52 @@ def get_resolution_ffprobe(file):
return str(i["width"]) + "x" + str(i["height"])
return None

RenderClass = RenderClass_base()
# - = - = -
# YTCON VERSION CHECKER
import importlib.util

try:
# Trying to use relative paths to look at __version__
from .__version__ import __version__
RenderClass.version = __version__
RenderClass.install_source = "pip"
except:
pass

if RenderClass.version == "!!{PLACEHOLDER}!!" or RenderClass.version == "?.?.?":
try:
# Find the directory in which the ytcon startup file is located
ytcon_files_path = os.path.abspath(__file__).replace("yt.py", "")

# Try to load __version__.py from the directory where ytcon is located
spec = importlib.util.spec_from_file_location("version", ytcon_files_path + "__version__.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
RenderClass.version = module.__version__
except:
pass

if RenderClass.version == "!!{PLACEHOLDER}!!" or RenderClass.version == "?.?.?":
try:
# Use GIT to check tags, makes sense if git clone was used to install
tag = subprocess.check_output(f'git -C "{ytcon_files_path}" describe --tags', shell=True, encoding="UTF-8")

# Formating it a little
# v0.0.11-3-g0ada3b4 -->> 0.0.11
tag = tag.replace("\n", "").replace("v", "")
if tag.find("-") > 1:
tag = tag[0:tag.find("-")]

RenderClass.version = tag
RenderClass.install_source = "git"
except:
pass

#print(RenderClass.version) # TODO CLEAN TRASH
#print(RenderClass.install_source)
#print(RenderClass.pypi_version)
#input(">> ")
# - = - = -
ControlClass = ControlClass_base()

Expand All @@ -1051,8 +1126,6 @@ def get_resolution_ffprobe(file):
'ignoreerrors': True # !!! DANGEROUS OPTION !!! # Don't exit if there is private video in playlist
}

RenderClass = RenderClass_base()

top_pile = urwid.Pile([])

#logger.debug(pprint.pformat(top_pile.contents))
Expand Down Expand Up @@ -1123,11 +1196,14 @@ def update_checkboxes():

footer_buttons = urwid.GridFlow([exit_settings_button, save_settings_button, load_settings_button], cell_width=25, h_sep=2, v_sep=1, align="left")

settings_version_text = urwid.Text("YTCON version: " + RenderClass.version)

footer_widget = urwid.Pile([
error_widget,
urwid.Text("- - -"),
log_widget,
urwid.Text("- - -"),
settings_version_text,
footer_buttons
])

Expand Down

0 comments on commit c27772e

Please sign in to comment.