Skip to content

Commit

Permalink
Log name format changed, added some strings of localization, menu fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danila-schelkov committed Oct 17, 2021
1 parent 6efce6b commit 7dd4ab6
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

while True:
try:
clear()
handler = menu.choice()
if handler is not None:
start_time = time.time()
with logger.catch():
handler()
logger.opt(colors=True).info(f'<green>{locale.done % (time.time() - start_time)}</green>')
input(locale.to_continue)
clear()
except KeyboardInterrupt:
if Console.question(locale.want_exit):
clear()
Expand Down
4 changes: 2 additions & 2 deletions system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run(command: str, output_path: str = null_output):
logger.exception(e)

def clear():
run('cls')
os.system('cls')
else:
def clear():
run('clear')
os.system('clear')
7 changes: 5 additions & 2 deletions system/languages/en-EU.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"crt_workspace": "Creating workspace directories...",
"verifying": "Verifying installation...",
"installed": "%s was successfully installed!",
"update_done": "The update was downloaded successfully! Please move all files from directory %s to script directory",
"update_done": "The update was downloaded successfully! Please move all files from directory%s to script directory",
"not_installed": "%s wasn't installed!",
"clear_qu": "Are you sure you want to clear the dirs?",
"done": "Completed in %.2f seconds!",
"done_qu": "Done?",
"choice": "Your choice: ",
"to_continue": "Press Enter to continue...",
"experimental": "Experimental feature",
Expand Down Expand Up @@ -86,5 +87,7 @@
"stp": "Installing...",
"margin_qu": "Consider edge margins?",
"enabled": "Enabled",
"disabled": "Disabled"
"disabled": "Disabled",

"install_to_unlock": "Install \"%s\" to unlock more functions!"
}
7 changes: 5 additions & 2 deletions system/languages/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"crt_workspace": "Создаются рабочие папки...",
"verifying": "Проверка установки...",
"installed": "%s успешно установлен!",
"update_done": "Обновление успешно скачалось! Пожалуйста, переместите все файлы из каталога %s в каталог скрипта",
"update_done": "Обновление успешно скачалось! Пожалуйста, переместите все файлы из каталога%s в каталог скрипта",
"not_installed": "%s не установлен!",
"clear_qu": "Вы действительно хотите очистить папки?",
"done": "Выполнено за %.2f секунд!",
"done_qu": "Сделано?",
"choice": "ВАШЕ ДЕЙСТВИЕ: ",
"to_continue": "Нажмите Enter для продолжения...",
"experimental": "Экспериментальная функция",
Expand Down Expand Up @@ -86,5 +87,7 @@
"stp": "Установка...",
"margin_qu": "Учитывать отступы от краев?",
"enabled": "Включено",
"disabled": "Выключено"
"disabled": "Выключено",

"install_to_unlock": "Установите \"%s\" чтобы открыть больше функций!"
}
29 changes: 15 additions & 14 deletions system/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from system import clear
from system.lib.config import config
from system.lib.console import Console
from system.lib.features.csv.compress import compress_csv
from system.lib.features.csv.decompress import decompress_csv
from system.lib.features.directories import clear_directories
from system.lib.features.initialization import initialize
from system.lib.features.update.check import check_update, check_for_outdated, get_tags
Expand All @@ -16,13 +14,13 @@

logger.remove()
logger.add(
'./logs/info/{time:YYYY-dd-MM_HH-mm-ss}.log',
'./logs/info/{time:YYYY-dd-MM}.log',
format='[{time:HH:mm:ss}] [{level}]: {message}',
encoding="utf8",
level='INFO'
)
logger.add(
'./logs/errors/{time:YYYY-dd-MM_HH-mm-ss}.log',
'./logs/errors/{time:YYYY-dd-MM}.log',
format='[{time:HH:mm:ss}] [{level}]: {message}',
backtrace=True,
diagnose=True,
Expand All @@ -45,8 +43,8 @@
config.dump()

if config.has_update:
logger.opt(colors=True).info(f'<green>{locale.update_done}</green>')
if Console.question(locale.done[:-1] + '?'):
logger.opt(colors=True).info(f'<green>{locale.update_done % ""}</green>')
if Console.question(locale.done_qu):
latest_tag = get_tags('vorono4ka', 'xcoder')[0]
latest_tag_name = latest_tag['name'][1:]

Expand All @@ -56,8 +54,8 @@
config.dump()
else:
exit()
except ImportError as exception:
logger.error(exception)
except ImportError:
pass


@logger.catch()
Expand All @@ -68,6 +66,9 @@ def refill_menu():
import sc_compression
del sc_compression

from system.lib.features.csv.compress import compress_csv
from system.lib.features.csv.decompress import decompress_csv

try:
import PIL
del PIL
Expand Down Expand Up @@ -104,8 +105,8 @@ def refill_menu():
lambda: sc1_encode(True)
))
menu.add_category(sc_category)
except ImportError as e:
logger.exception(e)
except ImportError:
logger.warning(locale.install_to_unlock % 'PILLOW')

csv_category = Menu.Category(1, locale.csv_label)
csv_category.add(Menu.Item(
Expand All @@ -119,8 +120,8 @@ def refill_menu():
compress_csv
))
menu.add_category(csv_category)
except ImportError as exception:
logger.exception(exception)
except ImportError:
logger.warning(locale.install_to_unlock % 'sc-compression')

other = Menu.Category(10, locale.other_features_label)
try:
Expand All @@ -132,8 +133,8 @@ def refill_menu():
locale.version % config.version,
check_update
))
except ImportError as exception:
logger.exception(exception)
except ImportError:
logger.warning(locale.install_to_unlock % 'requests')

other.add(Menu.Item(
locale.check_for_outdated,
Expand Down
16 changes: 9 additions & 7 deletions system/lib/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def print_category(text):
return print(colorama.Back.GREEN + colorama.Fore.BLACK + text + ' ' * (10 - len(text)) + colorama.Style.RESET_ALL)


def print_line(console_width):
print((console_width - 1) * '-')


class Menu:
class Item:
def __init__(self, name, description=None, handler=None):
Expand Down Expand Up @@ -46,23 +50,21 @@ def add_category(self, category):
return category

def choice(self):
config.load()

console_width = shutil.get_terminal_size().columns
print((
colorama.Back.BLACK + colorama.Fore.GREEN +
locale.xcoder_header % config.version +
colorama.Style.RESET_ALL
).center(console_width + 14))
print('github.com/Vorono4ka/XCoder'.center(console_width))
print(console_width * '-')
).center(console_width + 12))
print('github.com/Vorono4ka/XCoder'.center(console_width - 1))
print_line(console_width)

for category in self.categories:
print_category(category.name)
for item_index in range(len(category.items)):
item = category.items[item_index]
print_feature(f' {category.id * 10 + item_index + 1} {item.name}', item.description, console_width)
print(console_width * '-')
print_line(console_width)

choice = input(locale.choice)
try:
Expand All @@ -71,7 +73,7 @@ def choice(self):
return None
except ValueError:
return None
print(console_width * '-')
print_line(console_width)

category_id = choice // 10
item_index = choice % 10
Expand Down
3 changes: 3 additions & 0 deletions system/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(self):
self.not_installed = None
self.clear_qu = None
self.done = None
self.done_qu = None
self.choice = None
self.to_continue = None
self.experimental = None
Expand Down Expand Up @@ -94,6 +95,8 @@ def __init__(self):
self.enabled = None
self.disabled = None

self.install_to_unlock = None

def load(self, language: str):
language_filepath = './system/languages/' + language + '.json'
english_language_filepath = './system/languages/en-EU.json'
Expand Down

0 comments on commit 7dd4ab6

Please sign in to comment.