Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Refactored by Vorono4ka
# Finished ~99%

import time

Expand All @@ -9,7 +8,14 @@
raise RuntimeError("Please, install loguru using pip")

from system import clear
from system.lib import config, locale, refill_menu, menu
from system.lib import (
config,
locale,
refill_menu,
menu,
check_auto_update,
check_files_updated,
)
from system.lib.features.initialization import initialize


Expand All @@ -21,6 +27,9 @@ def main():
initialize(True)
exit()

check_auto_update()
check_files_updated()

refill_menu()

while True:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
sc-compression
requests
colorama
pylzham
zstandard
Expand Down
27 changes: 6 additions & 21 deletions system/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@
locale.load(config.language)


try:
# noinspection PyUnresolvedReferences
import requests

del requests

def check_auto_update():
if config.auto_update and time.time() - config.last_update > 60 * 60 * 24 * 7:
check_update()
config.last_update = int(time.time())
config.dump()


def check_files_updated():
if config.has_update:
logger.opt(colors=True).info(f'<green>{locale.update_done % ""}</green>')
if Console.question(locale.done_qu):
Expand All @@ -56,8 +53,6 @@
config.dump()
else:
exit()
except ImportError:
pass


# noinspection PyUnresolvedReferences
Expand Down Expand Up @@ -131,19 +126,9 @@ def refill_menu():
logger.warning(locale.install_to_unlock % "sc-compression")

other = Menu.Category(10, locale.other_features_label)
try:
import requests

del requests

other.add(
Menu.Item(
locale.check_update, locale.version % config.version, check_update
)
)
except ImportError:
logger.warning(locale.install_to_unlock % "requests")

other.add(
Menu.Item(locale.check_update, locale.version % config.version, check_update)
)
other.add(Menu.Item(locale.check_for_outdated, None, check_for_outdated))
other.add(
Menu.Item(
Expand Down
9 changes: 1 addition & 8 deletions system/lib/features/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,7 @@ def initialize(first_init=False):
logger.info(locale.verifying)

config.initialized = True
try:
# noinspection PyUnresolvedReferences
import requests

del requests
config.version = get_tags("vorono4ka", "xcoder")[0]["name"][1:]
except ImportError as exception:
logger.exception(exception)
config.version = get_tags("vorono4ka", "xcoder")[0]["name"][1:]
config.dump()

if first_init:
Expand Down
24 changes: 12 additions & 12 deletions system/lib/features/update/check.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os

from loguru import logger
Expand Down Expand Up @@ -38,21 +39,20 @@ def get_pip_info(outdated: bool = False) -> list:

def get_tags(owner: str, repo: str):
api_url = "https://api.github.com"
tags = []

import requests
import urllib.request

try:
tags = requests.get(
tags = json.loads(
urllib.request.urlopen(
api_url + "/repos/{owner}/{repo}/tags".format(owner=owner, repo=repo)
).json()
tags = [
{key: v for key, v in tag.items() if key in ["name", "zipball_url"]}
for tag in tags
]
except Exception:
pass
del requests
)
.read()
.decode()
)
tags = [
{key: v for key, v in tag.items() if key in ["name", "zipball_url"]}
for tag in tags
]

return tags

Expand Down
4 changes: 2 additions & 2 deletions system/lib/features/update/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def download_update(zip_url):
os.mkdir("updates")

try:
import requests
import urllib.request

with open("updates/update.zip", "wb") as f:
f.write(requests.get(zip_url).content)
f.write(urllib.request.urlopen(zip_url).read())
f.close()

import zipfile
Expand Down