Skip to content

Commit

Permalink
add ^C message, fix time at logs
Browse files Browse the repository at this point in the history
  • Loading branch information
vinzekatze committed Feb 2, 2024
1 parent 2dfc097 commit 9f72839
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img src="https://raw.githubusercontent.com/vinzekatze/bashmator/main/static/bashmator.png" alt="bshm" width="500px">
<br>
<a href="https://github.com/vinzekatze/bashmator"><img src="https://img.shields.io/github/release/vinzekatze/bashmator?style=flat-square"></a>
<a href="http://www.python.org/download/"><img src="https://img.shields.io/badge/python-3.7+-blue.svg?style=flat-square&logo=python"></a>
<a href="http://www.python.org/download/"><img src="https://img.shields.io/badge/python-3.10+-blue.svg?style=flat-square&logo=python"></a>
<a href="https://github.com/vinzekatze/bashmator"><img src="https://img.shields.io/badge/linux-✔️-green.svg?style=flat-square&logo=linux&logoColor=white"></a>
<a href="https://github.com/vinzekatze/bashmator"><img src="https://img.shields.io/badge/macos-✔️-green.svg?style=flat-square&logo=macos&logoColor=white"></a>
<a href="https://github.com/vinzekatze/bashmator"><img src="https://img.shields.io/badge/win-✔️%20%5Bnot%20tested%20enough%5D-orange.svg?style=flat-square&logo=windows"></a>
Expand All @@ -26,7 +26,7 @@ YAML файлы хранятся в папке (библиотеке). Для к
# Установка

```
pip install bashmator
pip install --upgrade bashmator
```
В комадной строке станет доступен под короткими названиям `bashmator` и `bshm`.

Expand Down
Empty file added bshm/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion bshm/bashmator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from bshm.bones.config import Configuration

def main():
__version__ = "1.1.7"
__version__ = "1.1.8"
__programm_location__ = os.path.dirname(os.path.realpath(__file__))
__default_lib_path__ = os.path.join(__programm_location__,'library')
__config_location__ = user_config_dir('bashmator')
Expand Down
Empty file added bshm/bones/__init__.py
Empty file.
8 changes: 2 additions & 6 deletions bshm/bones/funcs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import datetime
from datetime import datetime
from bshm.bones.msg import style_line, style_line2


Expand All @@ -13,11 +13,7 @@ def make_lines(text):
return (s1+s2+s3)

def get_local_time():
now = datetime.datetime.now(datetime.timezone.utc)
form_now = now.strftime("%Y-%m-%d %H:%M:%S")
local_tz = datetime.timezone.utc
out=f'{form_now} ({local_tz})'
return(out)
return(datetime.now().astimezone())

def get_code_print_header(shell: str, item: int):
s1 = style_line2
Expand Down
30 changes: 16 additions & 14 deletions bshm/bones/yamlscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from bshm.bones.funcs import get_main_header, get_local_time, get_code_log, get_alt_code_cog, get_log_header, get_log_end, get_code_print_header
from bshm.bones.validate import YamlValidator, re_compile

breaker_time = 1
breaker_time = 2

class YamlScript:
def __shell_collector__(self, item: int, shell: str):
Expand Down Expand Up @@ -155,7 +155,7 @@ def __init__(self, path: str,
self.has_main_script = False
self.has_files = False
self.only_fags_mode = False
self.interrupt_time = time()
self.interrupt_time = time() - 2*breaker_time
self.interrupt_count = 0
# Параметры аргументов
self.items_launch_set = [0]
Expand Down Expand Up @@ -500,6 +500,18 @@ def __build_log_header__(self, script: str, shell: str, item: int, new_log):
headerstr += get_log_header()
return headerstr

def __keyboard_interrupt_stoper__(self):
out = False
if time() - self.interrupt_time < breaker_time:
self.interrupt_count += 1
else:
self.interrupt_count = 0
self.interrupt_time = time()
self.msg.warning('Interrupted by user', 'Script execution was interrupted. Press 3 times to abort completely.')
if self.interrupt_count > 2:
out = True
return(out)

def execute(self, show_log: bool, popen_cmd: list, item: int, new_log=True, last_log=True):
if show_log:
headerstr = self.__build_log_header__(script=popen_cmd[-1], shell=' '.join(popen_cmd[:-1]), item=item, new_log=new_log)
Expand All @@ -511,12 +523,7 @@ def execute(self, show_log: bool, popen_cmd: list, item: int, new_log=True, las
self.msg.warning_file(' '.join(popen_cmd[:-1]))
sys.exit(1)
except KeyboardInterrupt:
if time() - self.interrupt_time < breaker_time:
self.interrupt_count += 1
else:
self.interrupt_count = 0
self.interrupt_time = time()
if self.interrupt_count > 2:
if self.__keyboard_interrupt_stoper__():
raise
finally:
if show_log:
Expand Down Expand Up @@ -547,12 +554,7 @@ def execute_and_log(self, logging: str, show_log: bool, popen_cmd: list, shell_e
self.msg.warning_file(' '.join(popen_cmd[:-1]))
sys.exit(1)
except KeyboardInterrupt:
if time() - self.interrupt_time < breaker_time:
self.interrupt_count += 1
else:
self.interrupt_count = 0
self.interrupt_time = time()
if self.interrupt_count > 2:
if self.__keyboard_interrupt_stoper__():
raise
finally:
# Запись и отображение последнего заголовка логера
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bashmator"
version = "1.1.7"
version = "1.1.8"
description = "Console script manager based on YAML format"
authors = ["vinzekatze <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 9f72839

Please sign in to comment.