mirror of
https://github.com/paul-nameless/tg
synced 2024-11-22 11:53:08 +00:00
Update linter dependencies and fix lints
Use t to rename f since it has the type for TextIOWrapper, which is different from the original f being _TemporaryFileWrapper.
This commit is contained in:
parent
ba552df613
commit
9c34c88d4e
9 changed files with 29 additions and 28 deletions
|
@ -14,10 +14,10 @@ python = "^3.8"
|
||||||
python-telegram = "0.18.0"
|
python-telegram = "0.18.0"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
black = "20.8b1"
|
black = "*"
|
||||||
flake8 = "3.8.4"
|
flake8 = "*"
|
||||||
isort = "5.6.2"
|
isort = "*"
|
||||||
mypy = "0.812"
|
mypy = "*"
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
tg = "tg.__main__:main"
|
tg = "tg.__main__:main"
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import signal
|
import signal
|
||||||
import threading
|
import threading
|
||||||
from curses import window, wrapper # type: ignore
|
from curses import window, wrapper
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from types import FrameType
|
from types import FrameType
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from tg import config, update_handlers, utils
|
from tg import config, update_handlers, utils
|
||||||
from tg.controllers import Controller
|
from tg.controllers import Controller
|
||||||
|
@ -15,9 +16,8 @@ log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def run(tg: Tdlib, stdscr: window) -> None:
|
def run(tg: Tdlib, stdscr: window) -> None:
|
||||||
|
|
||||||
# handle ctrl+c, to avoid interrupting tg when subprocess is called
|
# handle ctrl+c, to avoid interrupting tg when subprocess is called
|
||||||
def interrupt_signal_handler(sig: int, frame: FrameType) -> None:
|
def interrupt_signal_handler(sig: int, frame: Optional[FrameType]) -> None:
|
||||||
# TODO: draw on status pane: to quite press <q>
|
# TODO: draw on status pane: to quite press <q>
|
||||||
log.info("Interrupt signal is handled and ignored on purpose.")
|
log.info("Interrupt signal is handled and ignored on purpose.")
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ FILE_PICKER_CMD = "ranger --choosefile={file_path}"
|
||||||
DOWNLOAD_DIR = os.path.expanduser("~/Downloads/")
|
DOWNLOAD_DIR = os.path.expanduser("~/Downloads/")
|
||||||
|
|
||||||
if os.path.isfile(CONFIG_FILE):
|
if os.path.isfile(CONFIG_FILE):
|
||||||
config_params = runpy.run_path(CONFIG_FILE) # type: ignore
|
config_params = runpy.run_path(CONFIG_FILE)
|
||||||
for param, value in config_params.items():
|
for param, value in config_params.items():
|
||||||
if param.isupper():
|
if param.isupper():
|
||||||
globals()[param] = value
|
globals()[param] = value
|
||||||
|
|
|
@ -5,6 +5,7 @@ from datetime import datetime
|
||||||
from functools import partial, wraps
|
from functools import partial, wraps
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
|
from types import FrameType
|
||||||
from typing import Any, Callable, Dict, List, Optional
|
from typing import Any, Callable, Dict, List, Optional
|
||||||
|
|
||||||
from telegram.utils import AsyncResult
|
from telegram.utils import AsyncResult
|
||||||
|
@ -303,8 +304,8 @@ class Controller:
|
||||||
f.write(insert_replied_msg(msg))
|
f.write(insert_replied_msg(msg))
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
s.call(config.LONG_MSG_CMD.format(file_path=shlex.quote(f.name)))
|
s.call(config.LONG_MSG_CMD.format(file_path=shlex.quote(f.name)))
|
||||||
with open(f.name) as f:
|
with open(f.name) as t:
|
||||||
if replied_msg := strip_replied_msg(f.read().strip()):
|
if replied_msg := strip_replied_msg(t.read().strip()):
|
||||||
self.model.view_all_msgs()
|
self.model.view_all_msgs()
|
||||||
self.tg.reply_message(chat_id, reply_to_msg, replied_msg)
|
self.tg.reply_message(chat_id, reply_to_msg, replied_msg)
|
||||||
self.present_info("Message sent")
|
self.present_info("Message sent")
|
||||||
|
@ -336,8 +337,8 @@ class Controller:
|
||||||
) as s:
|
) as s:
|
||||||
self.tg.send_chat_action(chat_id, ChatAction.chatActionTyping)
|
self.tg.send_chat_action(chat_id, ChatAction.chatActionTyping)
|
||||||
s.call(config.LONG_MSG_CMD.format(file_path=shlex.quote(f.name)))
|
s.call(config.LONG_MSG_CMD.format(file_path=shlex.quote(f.name)))
|
||||||
with open(f.name) as f:
|
with open(f.name) as t:
|
||||||
if msg := f.read().strip():
|
if msg := t.read().strip():
|
||||||
self.model.send_message(text=msg)
|
self.model.send_message(text=msg)
|
||||||
self.present_info("Message sent")
|
self.present_info("Message sent")
|
||||||
else:
|
else:
|
||||||
|
@ -364,8 +365,8 @@ class Controller:
|
||||||
try:
|
try:
|
||||||
with NamedTemporaryFile("w") as f, suspend(self.view) as s:
|
with NamedTemporaryFile("w") as f, suspend(self.view) as s:
|
||||||
s.call(config.FILE_PICKER_CMD.format(file_path=f.name))
|
s.call(config.FILE_PICKER_CMD.format(file_path=f.name))
|
||||||
with open(f.name) as f:
|
with open(f.name) as t:
|
||||||
file_path = f.read().strip()
|
file_path = t.read().strip()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
if not file_path or not os.path.isfile(file_path):
|
if not file_path or not os.path.isfile(file_path):
|
||||||
|
@ -488,7 +489,7 @@ class Controller:
|
||||||
chat = self.model.chats.chats[self.model.current_chat]
|
chat = self.model.chats.chats[self.model.current_chat]
|
||||||
return chat["permissions"]["can_send_messages"]
|
return chat["permissions"]["can_send_messages"]
|
||||||
|
|
||||||
def _open_msg(self, msg: MsgProxy, cmd: str = None) -> None:
|
def _open_msg(self, msg: MsgProxy, cmd: Optional[str] = None) -> None:
|
||||||
if msg.is_text:
|
if msg.is_text:
|
||||||
with NamedTemporaryFile("w", suffix=".txt") as f:
|
with NamedTemporaryFile("w", suffix=".txt") as f:
|
||||||
f.write(msg.text_content)
|
f.write(msg.text_content)
|
||||||
|
@ -544,8 +545,8 @@ class Controller:
|
||||||
f.write(msg.text_content)
|
f.write(msg.text_content)
|
||||||
f.flush()
|
f.flush()
|
||||||
s.call(f"{config.EDITOR} {f.name}")
|
s.call(f"{config.EDITOR} {f.name}")
|
||||||
with open(f.name) as f:
|
with open(f.name) as t:
|
||||||
if text := f.read().strip():
|
if text := t.read().strip():
|
||||||
self.model.edit_message(text=text)
|
self.model.edit_message(text=text)
|
||||||
self.present_info("Message edited")
|
self.present_info("Message edited")
|
||||||
|
|
||||||
|
@ -775,7 +776,7 @@ class Controller:
|
||||||
except Exception:
|
except Exception:
|
||||||
log.exception("Error happend in key handle loop")
|
log.exception("Error happend in key handle loop")
|
||||||
|
|
||||||
def resize_handler(self, signum: int, frame: Any) -> None:
|
def resize_handler(self, signum: int, frame: Optional[FrameType]) -> None:
|
||||||
self.view.resize_handler()
|
self.view.resize_handler()
|
||||||
self.resize()
|
self.resize()
|
||||||
|
|
||||||
|
|
|
@ -403,7 +403,7 @@ class ChatModel:
|
||||||
"""
|
"""
|
||||||
if self.have_full_chat_list:
|
if self.have_full_chat_list:
|
||||||
return None
|
return None
|
||||||
offset_order = 2 ** 63 - 1
|
offset_order = 2**63 - 1
|
||||||
offset_chat_id = 0
|
offset_chat_id = 0
|
||||||
if len(self.chats):
|
if len(self.chats):
|
||||||
offset_chat_id = self.chats[-1]["id"]
|
offset_chat_id = self.chats[-1]["id"]
|
||||||
|
@ -655,7 +655,6 @@ User = namedtuple("User", ["id", "name", "status", "order"])
|
||||||
|
|
||||||
|
|
||||||
class UserModel:
|
class UserModel:
|
||||||
|
|
||||||
types = {
|
types = {
|
||||||
"userTypeUnknown": "unknown",
|
"userTypeUnknown": "unknown",
|
||||||
"userTypeBot": "bot",
|
"userTypeBot": "bot",
|
||||||
|
|
|
@ -8,7 +8,6 @@ log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class MsgProxy:
|
class MsgProxy:
|
||||||
|
|
||||||
fields_mapping = {
|
fields_mapping = {
|
||||||
"messageDocument": ("document", "document"),
|
"messageDocument": ("document", "document"),
|
||||||
"messageVoiceNote": ("voice_note", "voice"),
|
"messageVoiceNote": ("voice_note", "voice"),
|
||||||
|
|
|
@ -345,12 +345,12 @@ class Tdlib(Telegram):
|
||||||
return self._send_data(data)
|
return self._send_data(data)
|
||||||
|
|
||||||
def send_chat_action(
|
def send_chat_action(
|
||||||
self, chat_id: int, action: ChatAction, progress: int = None
|
self, chat_id: int, action: ChatAction
|
||||||
) -> AsyncResult:
|
) -> AsyncResult:
|
||||||
data = {
|
data = {
|
||||||
"@type": "sendChatAction",
|
"@type": "sendChatAction",
|
||||||
"chat_id": chat_id,
|
"chat_id": chat_id,
|
||||||
"action": {"@type": action.name, "progress": progress},
|
"action": {"@type": action.name},
|
||||||
}
|
}
|
||||||
return self._send_data(data)
|
return self._send_data(data)
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ from typing import Any, Dict, Optional, Tuple, Type
|
||||||
from tg import config
|
from tg import config
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
units = {"B": 1, "KB": 10 ** 3, "MB": 10 ** 6, "GB": 10 ** 9, "TB": 10 ** 12}
|
units = {"B": 1, "KB": 10**3, "MB": 10**6, "GB": 10**9, "TB": 10**12}
|
||||||
|
|
||||||
|
|
||||||
class LogWriter:
|
class LogWriter:
|
||||||
|
@ -85,7 +85,9 @@ def get_file_handler(file_path: str) -> str:
|
||||||
return config.DEFAULT_OPEN.format(file_path=shlex.quote(file_path))
|
return config.DEFAULT_OPEN.format(file_path=shlex.quote(file_path))
|
||||||
|
|
||||||
caps = get_mailcap()
|
caps = get_mailcap()
|
||||||
handler, view = mailcap.findmatch(caps, mtype, filename=shlex.quote(file_path))
|
handler, view = mailcap.findmatch(
|
||||||
|
caps, mtype, filename=shlex.quote(file_path)
|
||||||
|
)
|
||||||
if not handler:
|
if not handler:
|
||||||
return config.DEFAULT_OPEN.format(file_path=shlex.quote(file_path))
|
return config.DEFAULT_OPEN.format(file_path=shlex.quote(file_path))
|
||||||
return handler
|
return handler
|
||||||
|
@ -230,7 +232,7 @@ class suspend:
|
||||||
if proc.returncode:
|
if proc.returncode:
|
||||||
input(f"Command <{cmd}> failed: press <enter> to continue")
|
input(f"Command <{cmd}> failed: press <enter> to continue")
|
||||||
|
|
||||||
def open_file(self, file_path: str, cmd: str = None) -> None:
|
def open_file(self, file_path: str, cmd: Optional[str] = None) -> None:
|
||||||
if cmd:
|
if cmd:
|
||||||
cmd = cmd % shlex.quote(file_path)
|
cmd = cmd % shlex.quote(file_path)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -3,7 +3,7 @@ import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Dict, List, Optional, Tuple, Union, cast
|
from typing import Any, Dict, List, Optional, Tuple, Union, cast
|
||||||
|
|
||||||
from _curses import window # type: ignore
|
from _curses import window
|
||||||
|
|
||||||
from tg import config
|
from tg import config
|
||||||
from tg.colors import bold, cyan, get_color, magenta, reverse, white, yellow
|
from tg.colors import bold, cyan, get_color, magenta, reverse, white, yellow
|
||||||
|
@ -199,7 +199,7 @@ class ChatView:
|
||||||
self, current: int, chats: List[Dict[str, Any]], title: str = "Chats"
|
self, current: int, chats: List[Dict[str, Any]], title: str = "Chats"
|
||||||
) -> None:
|
) -> None:
|
||||||
self.win.erase()
|
self.win.erase()
|
||||||
line = curses.ACS_VLINE # type: ignore
|
line = curses.ACS_VLINE
|
||||||
width = self.w - 1
|
width = self.w - 1
|
||||||
|
|
||||||
self.win.vline(0, width, line, self.h)
|
self.win.vline(0, width, line, self.h)
|
||||||
|
|
Loading…
Reference in a new issue