mirror of
https://github.com/keanuplayz/dotfiles.git
synced 2024-08-15 02:33:12 +00:00
reformat all remaining Python scripts
This commit is contained in:
parent
dbd76019c8
commit
f8c01686ee
13 changed files with 572 additions and 612 deletions
|
@ -8,6 +8,8 @@ let s:ignored_errors += ['E111']
|
||||||
let s:ignored_errors += ['E114']
|
let s:ignored_errors += ['E114']
|
||||||
" Indent for continuation lines is smaller than expected
|
" Indent for continuation lines is smaller than expected
|
||||||
let s:ignored_errors += ['E121']
|
let s:ignored_errors += ['E121']
|
||||||
|
" Import not at the top of the file
|
||||||
|
let s:ignored_errors += ['E402']
|
||||||
" Line too long
|
" Line too long
|
||||||
let s:ignored_errors += ['E501']
|
let s:ignored_errors += ['E501']
|
||||||
|
|
||||||
|
|
|
@ -9,35 +9,29 @@ from typing import Any, Generator, Optional, Union
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
|
|
||||||
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "script-resources"))
|
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "script-resources"))
|
||||||
import common_script_utils
|
import common_script_utils
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_REGISTRY_DUMP_URL = "https://stronghold.crosscode.ru/~ccbot/emote-registry.json"
|
DEFAULT_REGISTRY_DUMP_URL = "https://stronghold.crosscode.ru/~ccbot/emote-registry.json"
|
||||||
|
|
||||||
|
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
config_path: Path = (
|
config_path: Path = (common_script_utils.DOTFILES_CONFIG_DIR / "copy-crosscode-emoji-url.ini")
|
||||||
common_script_utils.DOTFILES_CONFIG_DIR / "copy-crosscode-emoji-url.ini"
|
default_registry_dump_file: Path = (common_script_utils.DOTFILES_CACHE_DIR / "dotfiles")
|
||||||
)
|
|
||||||
default_registry_dump_file: Path = (
|
|
||||||
common_script_utils.DOTFILES_CACHE_DIR / "dotfiles"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
common_script_utils.platform_not_supported_error()
|
common_script_utils.platform_not_supported_error()
|
||||||
config = ConfigParser(interpolation=None)
|
config = ConfigParser(interpolation=None)
|
||||||
config.read(config_path)
|
config.read(config_path)
|
||||||
|
|
||||||
|
|
||||||
emotes: list[dict[str, Any]] = []
|
emotes: list[dict[str, Any]] = []
|
||||||
|
|
||||||
|
|
||||||
def emote_downloader_and_iterator() -> Generator[str, None, None]:
|
def emote_downloader_and_iterator() -> Generator[str, None, None]:
|
||||||
global emotes
|
global emotes
|
||||||
|
|
||||||
registry_dump_file: Optional[Union[str, Path]] = config.get(
|
registry_dump_file: Optional[Union[
|
||||||
"default", "ccbot_emote_registry_dump_file", fallback=None
|
str, Path]] = config.get("default", "ccbot_emote_registry_dump_file", fallback=None)
|
||||||
)
|
|
||||||
if registry_dump_file is not None:
|
if registry_dump_file is not None:
|
||||||
registry_dump_file = os.path.expanduser(registry_dump_file)
|
registry_dump_file = os.path.expanduser(registry_dump_file)
|
||||||
else:
|
else:
|
||||||
|
@ -75,16 +69,12 @@ if chosen_index >= 0:
|
||||||
if config.getboolean("default", "add_emote_name_to_url", fallback=False):
|
if config.getboolean("default", "add_emote_name_to_url", fallback=False):
|
||||||
emote_url_query["name"] = [chosen_emote["name"]]
|
emote_url_query["name"] = [chosen_emote["name"]]
|
||||||
|
|
||||||
default_emote_image_size = config.getint(
|
default_emote_image_size = config.getint("default", "default_emote_image_size", fallback=None)
|
||||||
"default", "default_emote_image_size", fallback=None
|
|
||||||
)
|
|
||||||
if default_emote_image_size is not None:
|
if default_emote_image_size is not None:
|
||||||
emote_url_query["size"] = [str(default_emote_image_size)]
|
emote_url_query["size"] = [str(default_emote_image_size)]
|
||||||
|
|
||||||
emote_url_query_str = urllib.parse.urlencode(emote_url_query, doseq=True)
|
emote_url_query_str = urllib.parse.urlencode(emote_url_query, doseq=True)
|
||||||
emote_url_str = urllib.parse.urlunparse(
|
emote_url_str = urllib.parse.urlunparse(emote_url._replace(query=emote_url_query_str))
|
||||||
emote_url._replace(query=emote_url_query_str)
|
|
||||||
)
|
|
||||||
|
|
||||||
common_script_utils.set_clipboard(emote_url_str)
|
common_script_utils.set_clipboard(emote_url_str)
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import sys
|
||||||
import colorama
|
import colorama
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
DISCORD_EPOCH = 1420070400000 # milliseconds
|
DISCORD_EPOCH = 1420070400000 # milliseconds
|
||||||
|
|
||||||
user_snowflake = int(sys.argv[1])
|
user_snowflake = int(sys.argv[1])
|
||||||
|
@ -13,9 +14,7 @@ user_snowflake = int(sys.argv[1])
|
||||||
|
|
||||||
def print_field(name, value):
|
def print_field(name, value):
|
||||||
print(
|
print(
|
||||||
"{}{}:{} {}".format(
|
"{}{}:{} {}".format(colorama.Style.BRIGHT, name.rjust(21), colorama.Style.RESET_ALL, value)
|
||||||
colorama.Style.BRIGHT, name.rjust(21), colorama.Style.RESET_ALL, value
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import discord
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
guild_id = int(sys.argv[1])
|
guild_id = int(sys.argv[1])
|
||||||
voice_channel_id = int(sys.argv[2])
|
voice_channel_id = int(sys.argv[2])
|
||||||
pulseaudio_device = sys.argv[3]
|
pulseaudio_device = sys.argv[3]
|
||||||
|
@ -11,7 +12,6 @@ pulseaudio_device = sys.argv[3]
|
||||||
with open(os.path.expanduser("~/.config/dotfiles/discord-tools-bot-token.txt")) as f:
|
with open(os.path.expanduser("~/.config/dotfiles/discord-tools-bot-token.txt")) as f:
|
||||||
bot_token = f.read().strip()
|
bot_token = f.read().strip()
|
||||||
|
|
||||||
|
|
||||||
bot = discord.Client()
|
bot = discord.Client()
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,9 +30,7 @@ async def on_ready():
|
||||||
print("connected to {0} ({0.id}) in {1} ({1.id})".format(voice_channel, guild))
|
print("connected to {0} ({0.id}) in {1} ({1.id})".format(voice_channel, guild))
|
||||||
|
|
||||||
source = discord.FFmpegPCMAudio(pulseaudio_device, before_options="-f pulse")
|
source = discord.FFmpegPCMAudio(pulseaudio_device, before_options="-f pulse")
|
||||||
voice_client.play(
|
voice_client.play(source, after=lambda e: print("Player error: %s" % e) if e else None)
|
||||||
source, after=lambda e: print("Player error: %s" % e) if e else None
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
bot.run(bot_token)
|
bot.run(bot_token)
|
||||||
|
|
|
@ -33,7 +33,6 @@ DISCORD_FLAGS = {
|
||||||
"Verified Bot Developer": 1 << 17,
|
"Verified Bot Developer": 1 << 17,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("user_snowflake", type=int)
|
parser.add_argument("user_snowflake", type=int)
|
||||||
parser.add_argument("--bot-token", type=str)
|
parser.add_argument("--bot-token", type=str)
|
||||||
|
@ -45,16 +44,13 @@ user_snowflake = cli_args.user_snowflake
|
||||||
|
|
||||||
bot_token = cli_args.bot_token
|
bot_token = cli_args.bot_token
|
||||||
if bot_token is None:
|
if bot_token is None:
|
||||||
with open(
|
with open(os.path.expanduser("~/.config/dotfiles/discord-tools-bot-token.txt")) as f:
|
||||||
os.path.expanduser("~/.config/dotfiles/discord-tools-bot-token.txt")
|
|
||||||
) as f:
|
|
||||||
bot_token = f.read().strip()
|
bot_token = f.read().strip()
|
||||||
|
|
||||||
image_size = cli_args.image_size
|
image_size = cli_args.image_size
|
||||||
if not (image_size is None or (image_size > 0 and image_size & (image_size - 1)) == 0):
|
if not (image_size is None or (image_size > 0 and image_size & (image_size - 1)) == 0):
|
||||||
parser.error("image_size must be greater than zero and a power of two")
|
parser.error("image_size must be greater than zero and a power of two")
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opener = urllib.request.build_opener()
|
opener = urllib.request.build_opener()
|
||||||
# Don't send the User-Agent header, Discord blocks the default one
|
# Don't send the User-Agent header, Discord blocks the default one
|
||||||
|
@ -85,9 +81,7 @@ avatar_url = (
|
||||||
raw_data["id"],
|
raw_data["id"],
|
||||||
raw_data["avatar"],
|
raw_data["avatar"],
|
||||||
"gif" if raw_data["avatar"].startswith("a_") else "png",
|
"gif" if raw_data["avatar"].startswith("a_") else "png",
|
||||||
)
|
) if raw_data["avatar"] is not None else default_avatar_url
|
||||||
if raw_data["avatar"] is not None
|
|
||||||
else default_avatar_url
|
|
||||||
)
|
)
|
||||||
if image_size is not None:
|
if image_size is not None:
|
||||||
avatar_url += "?size={}".format(image_size)
|
avatar_url += "?size={}".format(image_size)
|
||||||
|
@ -115,7 +109,6 @@ else:
|
||||||
user_flag_names.append(flag_name)
|
user_flag_names.append(flag_name)
|
||||||
data["Flags"] = ", ".join(user_flag_names)
|
data["Flags"] = ", ".join(user_flag_names)
|
||||||
|
|
||||||
|
|
||||||
if cli_args.get_prop is None:
|
if cli_args.get_prop is None:
|
||||||
max_name_length = max(map(len, data.keys()))
|
max_name_length = max(map(len, data.keys()))
|
||||||
for name, value in data.items():
|
for name, value in data.items():
|
||||||
|
|
|
@ -10,19 +10,17 @@ from pathlib import Path
|
||||||
import struct
|
import struct
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "script-resources"))
|
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "script-resources"))
|
||||||
import factorio.property_tree
|
import factorio.property_tree
|
||||||
|
|
||||||
|
|
||||||
with open(Path.home() / ".factorio" / "mods" / "mod-settings.dat", "rb") as f:
|
with open(Path.home() / ".factorio" / "mods" / "mod-settings.dat", "rb") as f:
|
||||||
|
|
||||||
version_main: int
|
version_main: int
|
||||||
version_major: int
|
version_major: int
|
||||||
version_minor: int
|
version_minor: int
|
||||||
version_developer: int
|
version_developer: int
|
||||||
version_main, version_major, version_minor, version_developer = struct.unpack(
|
version_main, version_major, version_minor, version_developer = struct.unpack("<HHHH", f.read(8))
|
||||||
"<HHHH", f.read(8)
|
|
||||||
)
|
|
||||||
|
|
||||||
always_false_flag = factorio.property_tree.read_bool(f)
|
always_false_flag = factorio.property_tree.read_bool(f)
|
||||||
assert not always_false_flag
|
assert not always_false_flag
|
||||||
|
|
|
@ -7,6 +7,7 @@ import json
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
encoding_names = ["utf8", "base16", "base32", "base64", "base85"]
|
encoding_names = ["utf8", "base16", "base32", "base64", "base85"]
|
||||||
parser.add_argument("--encoding", "-e", choices=encoding_names, default="utf8")
|
parser.add_argument("--encoding", "-e", choices=encoding_names, default="utf8")
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/env python3
|
||||||
# Taken from <https://unix.stackexchange.com/a/509417/411555>
|
# Taken from <https://unix.stackexchange.com/a/509417/411555>
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
from gi.repository import Gtk, Gio, GLib # noqa E402
|
from gi.repository import Gtk, Gio, GLib
|
||||||
|
|
||||||
|
|
||||||
rec_mgr = Gtk.RecentManager.get_default()
|
rec_mgr = Gtk.RecentManager.get_default()
|
||||||
for arg in sys.argv[1:]:
|
for arg in sys.argv[1:]:
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
# - The module `skins.citizen.scripts` references search inputs which aren't
|
# - The module `skins.citizen.scripts` references search inputs which aren't
|
||||||
# created by this script.
|
# created by this script.
|
||||||
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import mwclient
|
import mwclient
|
||||||
import json
|
import json
|
||||||
|
@ -137,13 +136,14 @@ parser.add_argument("--site", type=str, required=True)
|
||||||
parser.add_argument("--scheme", type=str, default="https")
|
parser.add_argument("--scheme", type=str, default="https")
|
||||||
parser.add_argument("--skin", type=str, default="vector")
|
parser.add_argument("--skin", type=str, default="vector")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--input", type=str, required=True,
|
"--input",
|
||||||
|
type=str,
|
||||||
|
required=True,
|
||||||
)
|
)
|
||||||
parser.add_argument("--title", type=str)
|
parser.add_argument("--title", type=str)
|
||||||
parser.add_argument("--output", type=str, required=True)
|
parser.add_argument("--output", type=str, required=True)
|
||||||
cli_args = parser.parse_args()
|
cli_args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
site = mwclient.Site(cli_args.site, scheme=cli_args.scheme)
|
site = mwclient.Site(cli_args.site, scheme=cli_args.scheme)
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,7 +151,11 @@ def get_load_script_url(**args):
|
||||||
return "{path}load{ext}?{args}".format(
|
return "{path}load{ext}?{args}".format(
|
||||||
path=site.path,
|
path=site.path,
|
||||||
ext=site.ext,
|
ext=site.ext,
|
||||||
args=urlencode({"lang": LANG, "skin": cli_args.skin, **args}),
|
args=urlencode({
|
||||||
|
"lang": LANG,
|
||||||
|
"skin": cli_args.skin,
|
||||||
|
**args
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -243,14 +247,12 @@ rendered_html = """\
|
||||||
lang=html.escape(LANG),
|
lang=html.escape(LANG),
|
||||||
text_dir=html.escape(LANG_TEXT_DIRECTION),
|
text_dir=html.escape(LANG_TEXT_DIRECTION),
|
||||||
base_url=html.escape("{}://{}".format(site.scheme, site.host)),
|
base_url=html.escape("{}://{}".format(site.scheme, site.host)),
|
||||||
page_modules_state_json=json_dumps_compact(
|
page_modules_state_json=json_dumps_compact({
|
||||||
{
|
|
||||||
"noscript": "ready",
|
"noscript": "ready",
|
||||||
"user.options": "ready",
|
"user.options": "ready",
|
||||||
"user.tokens": "loading",
|
"user.tokens": "loading",
|
||||||
**{name: "ready" for name in MODULES_PRELOAD_STYLES[cli_args.skin]},
|
**{name: "ready" for name in MODULES_PRELOAD_STYLES[cli_args.skin]},
|
||||||
}
|
}),
|
||||||
),
|
|
||||||
page_config_json=json_dumps_compact(result["jsconfigvars"]),
|
page_config_json=json_dumps_compact(result["jsconfigvars"]),
|
||||||
page_modules_json=json_dumps_compact(
|
page_modules_json=json_dumps_compact(
|
||||||
get_modules(result["modules"], MODULES_POST_LOAD, MODULES_POST_LOAD_BLOCKED)
|
get_modules(result["modules"], MODULES_POST_LOAD, MODULES_POST_LOAD_BLOCKED)
|
||||||
|
@ -258,35 +260,27 @@ rendered_html = """\
|
||||||
style_url=html.escape(
|
style_url=html.escape(
|
||||||
get_load_script_url(
|
get_load_script_url(
|
||||||
only="styles",
|
only="styles",
|
||||||
modules="|".join(
|
modules="|".join(get_modules(result["modulestyles"], MODULES_PRELOAD_STYLES)),
|
||||||
get_modules(result["modulestyles"], MODULES_PRELOAD_STYLES)
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
script_url=html.escape(
|
script_url=html.escape(
|
||||||
get_load_script_url(
|
get_load_script_url(
|
||||||
only="scripts",
|
only="scripts",
|
||||||
modules="|".join(
|
modules="|".join(get_modules(result["modulescripts"], MODULES_PRELOAD_SCRIPTS)),
|
||||||
get_modules(result["modulescripts"], MODULES_PRELOAD_SCRIPTS)
|
|
||||||
),
|
|
||||||
raw="1",
|
raw="1",
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
skin=html.escape(cli_args.skin),
|
skin=html.escape(cli_args.skin),
|
||||||
page_class=html.escape(escape_css_class(result["displaytitle"])),
|
page_class=html.escape(escape_css_class(result["displaytitle"])),
|
||||||
title=html.escape(result["displaytitle"]),
|
title=html.escape(result["displaytitle"]),
|
||||||
indicators_html="\n".join(
|
indicators_html="\n".join([
|
||||||
[
|
|
||||||
'<div id="mw-indicator-{}" class="mw-indicator">{}</div>'.format(
|
'<div id="mw-indicator-{}" class="mw-indicator">{}</div>'.format(
|
||||||
indicator["name"], indicator["*"]
|
indicator["name"], indicator["*"]
|
||||||
)
|
) for indicator in result["indicators"]
|
||||||
for indicator in result["indicators"]
|
]),
|
||||||
]
|
|
||||||
),
|
|
||||||
content_html=result["text"]["*"],
|
content_html=result["text"]["*"],
|
||||||
categories_html=result["categorieshtml"]["*"],
|
categories_html=result["categorieshtml"]["*"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
with open(cli_args.output, "w") as f:
|
with open(cli_args.output, "w") as f:
|
||||||
f.write(rendered_html)
|
f.write(rendered_html)
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
import gi
|
import gi
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
from gi.repository import Gtk, Gdk, Pango # noqa: E402
|
from gi.repository import Gtk, Gdk, Pango
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
@ -12,7 +13,6 @@ args = parser.parse_args()
|
||||||
|
|
||||||
message = " ".join(args.message)
|
message = " ".join(args.message)
|
||||||
|
|
||||||
|
|
||||||
window = Gtk.ApplicationWindow()
|
window = Gtk.ApplicationWindow()
|
||||||
window.set_keep_above(True)
|
window.set_keep_above(True)
|
||||||
window.set_decorated(False)
|
window.set_decorated(False)
|
||||||
|
|
|
@ -9,12 +9,12 @@
|
||||||
import math
|
import math
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
|
|
||||||
gi.require_version("Playerctl", "2.0")
|
gi.require_version("Playerctl", "2.0")
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
gi.require_version("Gdk", "3.0")
|
gi.require_version("Gdk", "3.0")
|
||||||
gi.require_version("Pango", "1.0")
|
gi.require_version("Pango", "1.0")
|
||||||
from gi.repository import Playerctl, Gtk, Gdk, GLib, Pango # noqa: E402
|
from gi.repository import Playerctl, Gtk, Gdk, GLib, Pango
|
||||||
|
|
||||||
|
|
||||||
# Larger priority values will make the player with this name appear higher in
|
# Larger priority values will make the player with this name appear higher in
|
||||||
# the menu. The default priority is 0.
|
# the menu. The default priority is 0.
|
||||||
|
@ -175,20 +175,18 @@ if len(player_names) > 0:
|
||||||
players = []
|
players = []
|
||||||
for player_name in player_names:
|
for player_name in player_names:
|
||||||
player = Playerctl.Player.new_from_name(player_name)
|
player = Playerctl.Player.new_from_name(player_name)
|
||||||
players.append(
|
players.append({
|
||||||
{
|
"player":
|
||||||
"player": player,
|
player,
|
||||||
"player_name": player_name,
|
"player_name":
|
||||||
|
player_name,
|
||||||
"sorting_key": (
|
"sorting_key": (
|
||||||
player.props.playback_status != Playerctl.PlaybackStatus.PLAYING,
|
player.props.playback_status != Playerctl.PlaybackStatus.PLAYING,
|
||||||
-PLAYER_NAME_PRIORITIES.get(player_name.name, 0),
|
-PLAYER_NAME_PRIORITIES.get(player_name.name, 0),
|
||||||
player_name.instance,
|
player_name.instance,
|
||||||
),
|
),
|
||||||
}
|
})
|
||||||
)
|
players = sorted(players, key=lambda player_and_meta: player_and_meta["sorting_key"])
|
||||||
players = sorted(
|
|
||||||
players, key=lambda player_and_meta: player_and_meta["sorting_key"]
|
|
||||||
)
|
|
||||||
|
|
||||||
for player_and_meta in players:
|
for player_and_meta in players:
|
||||||
player_name = player_and_meta["player_name"]
|
player_name = player_and_meta["player_name"]
|
||||||
|
@ -201,9 +199,7 @@ if len(player_names) > 0:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
player_icon_name = PLAYER_ICON_NAME_FIXES.get(
|
player_icon_name = PLAYER_ICON_NAME_FIXES.get(player_name.name, player_name.name)
|
||||||
player_name.name, player_name.name
|
|
||||||
)
|
|
||||||
player_icon = Gtk.Image.new_from_icon_name(player_icon_name, Gtk.IconSize.MENU)
|
player_icon = Gtk.Image.new_from_icon_name(player_icon_name, Gtk.IconSize.MENU)
|
||||||
player_menu_item.set_image(player_icon)
|
player_menu_item.set_image(player_icon)
|
||||||
|
|
||||||
|
@ -234,18 +230,14 @@ if len(player_names) > 0:
|
||||||
action_menu_item = Gtk.ImageMenuItem.new_with_mnemonic(action_name)
|
action_menu_item = Gtk.ImageMenuItem.new_with_mnemonic(action_name)
|
||||||
|
|
||||||
if action_icon_name is not None:
|
if action_icon_name is not None:
|
||||||
action_icon = Gtk.Image.new_from_icon_name(
|
action_icon = Gtk.Image.new_from_icon_name(action_icon_name, Gtk.IconSize.MENU)
|
||||||
action_icon_name, Gtk.IconSize.MENU
|
|
||||||
)
|
|
||||||
action_menu_item.set_image(action_icon)
|
action_menu_item.set_image(action_icon)
|
||||||
|
|
||||||
action_menu_item.set_sensitive(action_enabled)
|
action_menu_item.set_sensitive(action_enabled)
|
||||||
if action_fn is not None:
|
if action_fn is not None:
|
||||||
action_menu_item.connect(
|
action_menu_item.connect(
|
||||||
"activate",
|
"activate",
|
||||||
lambda _menu_item, action_fn, action_fn_args: action_fn(
|
lambda _menu_item, action_fn, action_fn_args: action_fn(*action_fn_args),
|
||||||
*action_fn_args
|
|
||||||
),
|
|
||||||
action_fn,
|
action_fn,
|
||||||
action_fn_args,
|
action_fn_args,
|
||||||
)
|
)
|
||||||
|
@ -259,7 +251,6 @@ else:
|
||||||
menu_item.set_sensitive(False)
|
menu_item.set_sensitive(False)
|
||||||
root_menu.append(menu_item)
|
root_menu.append(menu_item)
|
||||||
|
|
||||||
|
|
||||||
root_menu.connect("selection-done", Gtk.main_quit)
|
root_menu.connect("selection-done", Gtk.main_quit)
|
||||||
root_menu.connect("deactivate", Gtk.main_quit)
|
root_menu.connect("deactivate", Gtk.main_quit)
|
||||||
root_menu.connect("destroy", Gtk.main_quit)
|
root_menu.connect("destroy", Gtk.main_quit)
|
||||||
|
|
|
@ -16,10 +16,10 @@ import shutil
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from typing import Optional, Tuple, Generator
|
from typing import Optional, Tuple, Generator
|
||||||
|
|
||||||
|
|
||||||
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "script-resources"))
|
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "script-resources"))
|
||||||
import common_script_utils
|
import common_script_utils
|
||||||
|
|
||||||
|
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
firefox_home: Path = Path.home() / "Library" / "Application Support" / "Firefox"
|
firefox_home: Path = Path.home() / "Library" / "Application Support" / "Firefox"
|
||||||
elif os.name == "posix":
|
elif os.name == "posix":
|
||||||
|
@ -27,13 +27,10 @@ elif os.name == "posix":
|
||||||
else:
|
else:
|
||||||
common_script_utils.platform_not_supported_error()
|
common_script_utils.platform_not_supported_error()
|
||||||
|
|
||||||
|
|
||||||
profiles_config = ConfigParser(interpolation=None)
|
profiles_config = ConfigParser(interpolation=None)
|
||||||
profiles_config.read(firefox_home / "profiles.ini")
|
profiles_config.read(firefox_home / "profiles.ini")
|
||||||
|
|
||||||
installs_sections: list[str] = [
|
installs_sections: list[str] = [s for s in profiles_config.sections() if s.startswith("Install")]
|
||||||
s for s in profiles_config.sections() if s.startswith("Install")
|
|
||||||
]
|
|
||||||
if not installs_sections:
|
if not installs_sections:
|
||||||
raise Exception("no Firefox installations detected!")
|
raise Exception("no Firefox installations detected!")
|
||||||
if len(installs_sections) > 1:
|
if len(installs_sections) > 1:
|
||||||
|
@ -45,7 +42,6 @@ db_path: Path = profile_dir / "weave" / "bookmarks.sqlite"
|
||||||
if not db_path.is_file():
|
if not db_path.is_file():
|
||||||
raise Exception("'{}' is not a file".format(db_path))
|
raise Exception("'{}' is not a file".format(db_path))
|
||||||
|
|
||||||
|
|
||||||
# Firefox holds a lock over the database file, so I can't connect to it even
|
# Firefox holds a lock over the database file, so I can't connect to it even
|
||||||
# in the readonly mode: https://stackoverflow.com/a/7857866/12005228
|
# in the readonly mode: https://stackoverflow.com/a/7857866/12005228
|
||||||
# as a workaround I copy the file
|
# as a workaround I copy the file
|
||||||
|
@ -97,9 +93,7 @@ try:
|
||||||
if folder_title is not None:
|
if folder_title is not None:
|
||||||
folder_path.append(folder_title)
|
folder_path.append(folder_title)
|
||||||
|
|
||||||
folder_path_str = (
|
folder_path_str = (("/" + "/".join(reversed(folder_path))) if len(folder_path) > 0 else None)
|
||||||
("/" + "/".join(reversed(folder_path))) if len(folder_path) > 0 else None
|
|
||||||
)
|
|
||||||
|
|
||||||
chooser_entries.append((url_title, url, folder_path_str))
|
chooser_entries.append((url_title, url, folder_path_str))
|
||||||
if url_keyword is not None:
|
if url_keyword is not None:
|
||||||
|
@ -118,9 +112,7 @@ def chooser_entries_iter() -> Generator[str, None, None]:
|
||||||
yield entry
|
yield entry
|
||||||
|
|
||||||
|
|
||||||
chosen_index = common_script_utils.run_chooser(
|
chosen_index = common_script_utils.run_chooser(chooser_entries_iter(), prompt="bookmark")
|
||||||
chooser_entries_iter(), prompt="bookmark"
|
|
||||||
)
|
|
||||||
|
|
||||||
if chosen_index >= 0:
|
if chosen_index >= 0:
|
||||||
_title, url, _folder_path_str = chooser_entries[chosen_index]
|
_title, url, _folder_path_str = chooser_entries[chosen_index]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue