chore: prefer f-strings over format

This commit is contained in:
Ales (Shagi) Zabala Alava 2024-09-24 14:43:55 +02:00
parent 2dbca4d398
commit 82bc205b48
5 changed files with 29 additions and 36 deletions

View File

@ -20,7 +20,7 @@ class SongPage:
srt_str = srtfile.read().encode("utf-8").decode("utf-8-sig")
parsed_srt = list(srt.parse(srt_str))
except Exception as e:
print("{}: srt parse error: {}".format(self.song.path.name, e))
print(f"{self.song.path.name}: srt parse error: {e}")
root_path = os.path.relpath(self.song.root, self.song.path)
return {
"song": self,
@ -58,8 +58,7 @@ class Builder:
def display_boolean(self, value):
if value:
return Markup("✓")
else:
return Markup("✗")
return Markup("✗")
def render(self, template, target, context):
html_file = target / "index.html"

View File

@ -17,28 +17,28 @@ def options(parser, config, **kwargs):
"--song_folder",
type=Path,
default=config["global"]["song_folder"],
help="Folder with the song database, defaults to {}".format(config["global"]["song_folder"]),
help=f"Folder with the song database, defaults to {config['global']['song_folder']}",
)
parser.add_argument(
"-l",
"--lyrics_file",
type=Path,
default=config["global"]["lyrics_file"],
help="File with the lyrics of the songs, defaults to {}".format(config["global"]["lyrics_file"]),
help=f"File with the lyrics of the songs, defaults to {config['global']['lyrics_file']}",
)
parser.add_argument(
"-t",
"--template_folder",
type=Path,
default=config["build"]["template_folder"],
help="Folder with jinja2 templates, defaults to {}".format(config["build"]["template_folder"]),
help=f"Folder with jinja2 templates, defaults to {config['build']['template_folder']}",
)
parser.add_argument(
"-S",
"--static_folder",
type=Path,
default=config["build"]["static_folder"],
help="Folder with static content, defaults to {}".format(config["build"]["static_folder"]),
help=f"Folder with static content, defaults to {config['build']['static_folder']}",
)

View File

@ -21,23 +21,23 @@ def options(parser, config, **kwargs):
"--song_folder",
type=Path,
default=config["global"]["song_folder"],
help="Folder with the song database, defaults to {}".format(config["global"]["song_folder"]),
help=f"Folder with the song database, defaults to {config['global']['song_folder']}",
)
parser.add_argument(
"-a", "--api", default=config[name]["api"], help="IPFS API server, defaults to {}.".format(config[name]["api"])
"-a", "--api", default=config[name]["api"], help=f"IPFS API server, defaults to {config[name]['api']}."
)
parser.add_argument(
"-r",
"--realm",
default=config[name]["realm"],
help="IPFS API basic authentication realm, defaults to {}.".format(config[name]["realm"]),
help=f"IPFS API basic authentication realm, defaults to {config[name]['realm']}.",
)
parser.add_argument(
"-p",
"--pinfile",
default=config[name]["pinfile"],
type=Path,
help="file to store the current ipfs hash, defaults to {}".format(config[name]["pinfile"]),
help=f"file to store the current ipfs hash, defaults to {config[name]['pinfile']}",
)
@ -59,7 +59,7 @@ def run(args, **kwargs):
args.song_folder.expanduser(),
]
new_hash = subprocess.check_output(command).decode("utf-8").strip()
logger.info("New hash: {}".format(new_hash))
logger.info("New hash: %s", new_hash)
# pin in server
data = urllib.parse.urlencode(
@ -68,8 +68,8 @@ def run(args, **kwargs):
"progress": "false",
}
)
url = "{}/api/v0/pin/add?{}".format(args.api, data)
logger.debug("server pin request: {}".format(url))
url = f"{args.api}/api/v0/pin/add?{data}"
logger.debug("server pin request: %s", url)
request = urllib.request.Request(url, method="POST")
urllib.request.urlopen(request)
logger.info("Hash pinned on server.")
@ -81,8 +81,8 @@ def run(args, **kwargs):
"resolve": "true",
}
)
url = "{}/api/v0/name/publish?{}".format(args.api, data)
logger.debug("server ipns request: {}".format(url))
url = f"{args.api}/api/v0/name/publish?{data}"
logger.debug("server ipns request: %s", url)
request = urllib.request.Request(url, method="POST")
urllib.request.urlopen(request)
logger.info("IPNS name updated.")
@ -92,7 +92,7 @@ def run(args, **kwargs):
if pinfile.exists():
with pinfile.open() as f:
previous_hash = f.read()
logger.info("Previous hash: {}".format(previous_hash))
logger.info("Previous hash: %s", previous_hash)
else:
if not pinfile.parent.exists():
pinfile.parent.mkdir()
@ -108,7 +108,7 @@ def run(args, **kwargs):
]
result = subprocess.run(command)
if result.returncode != 0:
logger.info("Previous {} hash not removed: {}".format(previous_hash, result.stdout))
logger.info("Previous %s hash not removed: %s", previous_hash, result.stdout)
else:
logger.info("Previous hash unpinned on local")
@ -118,8 +118,8 @@ def run(args, **kwargs):
"arg": previous_hash,
}
)
url = "{}/api/v0/pin/rm?{}".format(args.api, data)
logger.debug("server unpin request: {}".format(url))
url = f"{args.api}/api/v0/pin/rm?{data}"
logger.debug("server unpin request: %s", url)
request = urllib.request.Request(url, method="POST")
urllib.request.urlopen(request)
logger.info("Previous hash unpinned on server")

View File

@ -18,43 +18,39 @@ def options(parser, config, **kwargs):
"--song_folder",
type=Path,
default=config["global"]["song_folder"],
help="Folder with the song database, defaults to {}".format(config["global"]["song_folder"]),
help=f"Folder with the song database, defaults to {config['global']['song_folder']}",
)
parser.add_argument(
"-H", "--host", default=config[name]["host"], help="Target server, defaults to {}.".format(config[name]["host"])
"-H", "--host", default=config[name]["host"], help=f"Target server, defaults to {config[name]['host']}."
)
parser.add_argument(
"-u",
"--user",
default=config[name]["user"],
help="User in the server, defaults to {}.".format(config[name]["user"]),
help=f"User in the server, defaults to {config[name]['user']}.",
)
parser.add_argument(
"-p",
"--port",
default=config[name]["port"],
type=int,
help="Port of the ssh server, defaults to {}.".format(config[name]["port"]),
help=f"Port of the ssh server, defaults to {config[name]['port']}.",
)
parser.add_argument(
"-d",
"--destination",
default=config[name]["destination"],
help="Folder of the server, defaults to {}".format(config[name]["destination"]),
help=f"Folder of the server, defaults to {config[name]['destination']}",
)
def run(args, **kwargs):
contents = str(args.song_folder.expanduser()) + "/"
destination = "{user}@{host}:{folder}".format(
user=args.user,
host=args.host,
folder=args.destination,
)
destination = f"{args.user}@{args.host}:{args.destination}"
command = [
"rsync",
"-av",
"--rsh=ssh -p {}".format(args.port),
f"--rsh=ssh -p {args.port}",
contents,
destination,
]

View File

@ -17,23 +17,21 @@ def options(parser, config, **kwargs):
"--song_folder",
type=Path,
default=config["global"]["song_folder"],
help="Folder with the song database, defaults to {}".format(config["global"]["song_folder"]),
help=f"Folder with the song database, defaults to {config['global']['song_folder']}",
)
parser.add_argument(
"-p",
"--port",
default=config[name]["port"],
type=int,
help="Specify alternate port, defaults to {}".format(config[name]["port"]),
help=f"Specify alternate port, defaults to {config[name]['port']}",
)
parser.add_argument(
"--bind",
"-b",
default=config[name]["bind"],
metavar="ADDRESS",
help="Specify alternate bind address, defaults to {}".format(
config[name]["bind"] or "all interfaces",
),
help="Specify alternate bind address, defaults to {config[name]['bind'] or 'all interfaces'}",
)