diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2022-10-24 21:59:31 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:52 +0100 |
commit | ee9d976ff8d8910c091d1554dfa62ab28ad67509 (patch) | |
tree | 79cae5e252be07e11fd2d735b9c7fb37f91830d4 | |
parent | e3bc88120e071eac8fabb5b02d7b509488d563e2 (diff) | |
download | wee-slack-ee9d976ff8d8910c091d1554dfa62ab28ad67509.tar.gz |
Rename globals to G
-rw-r--r-- | slack/api.py | 6 | ||||
-rw-r--r-- | slack/config.py | 20 | ||||
-rw-r--r-- | slack/log.py | 4 | ||||
-rw-r--r-- | slack/main.py | 36 | ||||
-rw-r--r-- | slack/task.py | 24 |
5 files changed, 45 insertions, 45 deletions
diff --git a/slack/api.py b/slack/api.py index 1903718..47d3156 100644 --- a/slack/api.py +++ b/slack/api.py @@ -4,7 +4,7 @@ import json from typing import TYPE_CHECKING, Any, Dict, Union from urllib.parse import urlencode -import globals +import globals as G from weechat_http import http_request if TYPE_CHECKING: @@ -22,7 +22,7 @@ class SlackApi: def get_request_options(self): return { - "useragent": f"wee_slack {globals.SCRIPT_VERSION}", + "useragent": f"wee_slack {G.SCRIPT_VERSION}", "httpheader": f"Authorization: Bearer {self.workspace.config.api_token.value}", "cookie": self.workspace.config.api_cookies.value, } @@ -56,7 +56,7 @@ class SlackApi: class SlackWorkspace: def __init__(self, name: str): self.name = name - self.config = globals.config.create_workspace_config(self.name) + self.config = G.config.create_workspace_config(self.name) self.api = SlackApi(self) diff --git a/slack/config.py b/slack/config.py index 34c70cf..8584fca 100644 --- a/slack/config.py +++ b/slack/config.py @@ -3,7 +3,7 @@ from __future__ import annotations from dataclasses import dataclass from typing import Generic, TypeVar, Union, cast -import globals +import globals as G import weechat from api import SlackWorkspace from log import print_error @@ -127,7 +127,7 @@ class WeeChatOption(Generic[WeeChatOptionType]): value = None - if globals.weechat_version < 0x3050000: + if G.weechat_version < 0x3050000: default_value = str(self.default_value) value = default_value @@ -235,17 +235,17 @@ def config_section_workspace_read_cb( if not workspace_name or not name: return weechat.WEECHAT_CONFIG_OPTION_SET_ERROR - if workspace_name not in globals.workspaces: - globals.workspaces[workspace_name] = SlackWorkspace(workspace_name) + if workspace_name not in G.workspaces: + G.workspaces[workspace_name] = SlackWorkspace(workspace_name) - option = getattr(globals.workspaces[workspace_name].config, name, None) + option = getattr(G.workspaces[workspace_name].config, name, None) if option is None: return weechat.WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND if not isinstance(option, WeeChatOption): return weechat.WEECHAT_CONFIG_OPTION_SET_ERROR if value is None or ( - globals.weechat_version < 0x3080000 + G.weechat_version < 0x3080000 and value == "" and option.weechat_type != "string" ): @@ -263,7 +263,7 @@ def config_section_workspace_write_for_old_weechat_cb( if not weechat.config_write_line(config_file, section_name, ""): return weechat.WEECHAT_CONFIG_WRITE_ERROR - for workspace in globals.workspaces.values(): + for workspace in G.workspaces.values(): for option in vars(workspace.config).values(): if isinstance(option, WeeChatOption): if ( @@ -291,10 +291,10 @@ class SlackConfig: # WeeChat < 3.8 sends null as an empty string to callback_read, so in # order to distinguish them, don't write the null values to the config # See https://github.com/weechat/weechat/pull/1843 - print("version", globals.weechat_version) + print("version", G.weechat_version) callback_write = ( config_section_workspace_write_for_old_weechat_cb.__name__ - if globals.weechat_version < 0x3080000 + if G.weechat_version < 0x3080000 else "" ) self._section_workspace = WeeChatSection( @@ -311,7 +311,7 @@ class SlackConfig: weechat.config_read(self.weechat_config.pointer) def create_workspace_config(self, workspace_name: str): - if workspace_name in globals.workspaces: + if workspace_name in G.workspaces: raise Exception( f"Failed to create workspace config, already exists: {workspace_name}" ) diff --git a/slack/log.py b/slack/log.py index f65a095..d7b6843 100644 --- a/slack/log.py +++ b/slack/log.py @@ -1,6 +1,6 @@ from enum import IntEnum -import globals +import globals as G import weechat @@ -15,7 +15,7 @@ class LogLevel(IntEnum): # TODO: Figure out what to do with print_error vs log def print_error(message: str): - weechat.prnt("", f"{weechat.prefix('error')}{globals.SCRIPT_NAME}: {message}") + weechat.prnt("", f"{weechat.prefix('error')}{G.SCRIPT_NAME}: {message}") def log(level: LogLevel, message: str): diff --git a/slack/main.py b/slack/main.py index 38cd167..32dc3d5 100644 --- a/slack/main.py +++ b/slack/main.py @@ -6,44 +6,44 @@ import sys import weechat sys.path.append(os.path.dirname(os.path.realpath(__file__))) -import globals # pylint: disable=wrong-import-position +import globals as G # pylint: disable=wrong-import-position from config import SlackConfig, SlackWorkspace # pylint: disable=wrong-import-position from task import create_task # pylint: disable=wrong-import-position def shutdown_cb(): - weechat.config_write(globals.config.weechat_config.pointer) + weechat.config_write(G.config.weechat_config.pointer) return weechat.WEECHAT_RC_OK async def init(): - print(globals.workspaces) - if "wee-slack-test" not in globals.workspaces: - globals.workspaces["wee-slack-test"] = SlackWorkspace("wee-slack-test") - globals.workspaces[ + print(G.workspaces) + if "wee-slack-test" not in G.workspaces: + G.workspaces["wee-slack-test"] = SlackWorkspace("wee-slack-test") + G.workspaces[ "wee-slack-test" ].config.api_token.value = weechat.config_get_plugin("api_token") - globals.workspaces[ + G.workspaces[ "wee-slack-test" ].config.api_cookies.value = weechat.config_get_plugin("api_cookie") - workspace = globals.workspaces["wee-slack-test"] + workspace = G.workspaces["wee-slack-test"] print(workspace) print(workspace.config.slack_timeout.value) - print(globals.config.color.reaction_suffix.value) + print(G.config.color.reaction_suffix.value) if __name__ == "__main__": if weechat.register( - globals.SCRIPT_NAME, - globals.SCRIPT_AUTHOR, - globals.SCRIPT_VERSION, - globals.SCRIPT_LICENSE, - globals.SCRIPT_DESC, + G.SCRIPT_NAME, + G.SCRIPT_AUTHOR, + G.SCRIPT_VERSION, + G.SCRIPT_LICENSE, + G.SCRIPT_DESC, shutdown_cb.__name__, "", ): - globals.weechat_version = int(weechat.info_get("version_number", "") or 0) - globals.workspaces = {} - globals.config = SlackConfig() - globals.config.config_read() + G.weechat_version = int(weechat.info_get("version_number", "") or 0) + G.workspaces = {} + G.config = SlackConfig() + G.config.config_read() create_task(init(), final=True) diff --git a/slack/task.py b/slack/task.py index e976866..d9ba1cb 100644 --- a/slack/task.py +++ b/slack/task.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, Awaitable, Coroutine, Generator, Tuple, TypeVar from uuid import uuid4 -import globals +import globals as G import weechat T = TypeVar("T") @@ -33,7 +33,7 @@ class Task(Future[T]): def weechat_task_cb(data: str, *args: Any) -> int: - task = globals.active_tasks.pop(data) + task = G.active_tasks.pop(data) task_runner(task, args) return weechat.WEECHAT_RC_OK @@ -42,26 +42,26 @@ def task_runner(task: Task[Any], response: Any): while True: try: future = task.coroutine.send(response) - if future.id in globals.active_responses: - response = globals.active_responses.pop(future.id) + if future.id in G.active_responses: + response = G.active_responses.pop(future.id) else: - if future.id in globals.active_tasks: + if future.id in G.active_tasks: raise Exception( - f"future.id in active_tasks, {future.id}, {globals.active_tasks}" + f"future.id in active_tasks, {future.id}, {G.active_tasks}" ) - globals.active_tasks[future.id] = task + G.active_tasks[future.id] = task break except StopIteration as e: - if task.id in globals.active_tasks: - task = globals.active_tasks.pop(task.id) + if task.id in G.active_tasks: + task = G.active_tasks.pop(task.id) response = e.value else: - if task.id in globals.active_responses: + if task.id in G.active_responses: raise Exception( # pylint: disable=raise-missing-from - f"task.id in active_responses, {task.id}, {globals.active_responses}" + f"task.id in active_responses, {task.id}, {G.active_responses}" ) if not task.final: - globals.active_responses[task.id] = e.value + G.active_responses[task.id] = e.value break |