chore: prefer f-strings over format
This commit is contained in:
parent
2dbca4d398
commit
82bc205b48
|
@ -20,7 +20,7 @@ class SongPage:
|
||||||
srt_str = srtfile.read().encode("utf-8").decode("utf-8-sig")
|
srt_str = srtfile.read().encode("utf-8").decode("utf-8-sig")
|
||||||
parsed_srt = list(srt.parse(srt_str))
|
parsed_srt = list(srt.parse(srt_str))
|
||||||
except Exception as e:
|
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)
|
root_path = os.path.relpath(self.song.root, self.song.path)
|
||||||
return {
|
return {
|
||||||
"song": self,
|
"song": self,
|
||||||
|
@ -58,8 +58,7 @@ class Builder:
|
||||||
def display_boolean(self, value):
|
def display_boolean(self, value):
|
||||||
if value:
|
if value:
|
||||||
return Markup("✓")
|
return Markup("✓")
|
||||||
else:
|
return Markup("✗")
|
||||||
return Markup("✗")
|
|
||||||
|
|
||||||
def render(self, template, target, context):
|
def render(self, template, target, context):
|
||||||
html_file = target / "index.html"
|
html_file = target / "index.html"
|
||||||
|
|
|
@ -17,28 +17,28 @@ def options(parser, config, **kwargs):
|
||||||
"--song_folder",
|
"--song_folder",
|
||||||
type=Path,
|
type=Path,
|
||||||
default=config["global"]["song_folder"],
|
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(
|
parser.add_argument(
|
||||||
"-l",
|
"-l",
|
||||||
"--lyrics_file",
|
"--lyrics_file",
|
||||||
type=Path,
|
type=Path,
|
||||||
default=config["global"]["lyrics_file"],
|
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(
|
parser.add_argument(
|
||||||
"-t",
|
"-t",
|
||||||
"--template_folder",
|
"--template_folder",
|
||||||
type=Path,
|
type=Path,
|
||||||
default=config["build"]["template_folder"],
|
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(
|
parser.add_argument(
|
||||||
"-S",
|
"-S",
|
||||||
"--static_folder",
|
"--static_folder",
|
||||||
type=Path,
|
type=Path,
|
||||||
default=config["build"]["static_folder"],
|
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']}",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,23 +21,23 @@ def options(parser, config, **kwargs):
|
||||||
"--song_folder",
|
"--song_folder",
|
||||||
type=Path,
|
type=Path,
|
||||||
default=config["global"]["song_folder"],
|
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(
|
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(
|
parser.add_argument(
|
||||||
"-r",
|
"-r",
|
||||||
"--realm",
|
"--realm",
|
||||||
default=config[name]["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(
|
parser.add_argument(
|
||||||
"-p",
|
"-p",
|
||||||
"--pinfile",
|
"--pinfile",
|
||||||
default=config[name]["pinfile"],
|
default=config[name]["pinfile"],
|
||||||
type=Path,
|
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(),
|
args.song_folder.expanduser(),
|
||||||
]
|
]
|
||||||
new_hash = subprocess.check_output(command).decode("utf-8").strip()
|
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
|
# pin in server
|
||||||
data = urllib.parse.urlencode(
|
data = urllib.parse.urlencode(
|
||||||
|
@ -68,8 +68,8 @@ def run(args, **kwargs):
|
||||||
"progress": "false",
|
"progress": "false",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
url = "{}/api/v0/pin/add?{}".format(args.api, data)
|
url = f"{args.api}/api/v0/pin/add?{data}"
|
||||||
logger.debug("server pin request: {}".format(url))
|
logger.debug("server pin request: %s", url)
|
||||||
request = urllib.request.Request(url, method="POST")
|
request = urllib.request.Request(url, method="POST")
|
||||||
urllib.request.urlopen(request)
|
urllib.request.urlopen(request)
|
||||||
logger.info("Hash pinned on server.")
|
logger.info("Hash pinned on server.")
|
||||||
|
@ -81,8 +81,8 @@ def run(args, **kwargs):
|
||||||
"resolve": "true",
|
"resolve": "true",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
url = "{}/api/v0/name/publish?{}".format(args.api, data)
|
url = f"{args.api}/api/v0/name/publish?{data}"
|
||||||
logger.debug("server ipns request: {}".format(url))
|
logger.debug("server ipns request: %s", url)
|
||||||
request = urllib.request.Request(url, method="POST")
|
request = urllib.request.Request(url, method="POST")
|
||||||
urllib.request.urlopen(request)
|
urllib.request.urlopen(request)
|
||||||
logger.info("IPNS name updated.")
|
logger.info("IPNS name updated.")
|
||||||
|
@ -92,7 +92,7 @@ def run(args, **kwargs):
|
||||||
if pinfile.exists():
|
if pinfile.exists():
|
||||||
with pinfile.open() as f:
|
with pinfile.open() as f:
|
||||||
previous_hash = f.read()
|
previous_hash = f.read()
|
||||||
logger.info("Previous hash: {}".format(previous_hash))
|
logger.info("Previous hash: %s", previous_hash)
|
||||||
else:
|
else:
|
||||||
if not pinfile.parent.exists():
|
if not pinfile.parent.exists():
|
||||||
pinfile.parent.mkdir()
|
pinfile.parent.mkdir()
|
||||||
|
@ -108,7 +108,7 @@ def run(args, **kwargs):
|
||||||
]
|
]
|
||||||
result = subprocess.run(command)
|
result = subprocess.run(command)
|
||||||
if result.returncode != 0:
|
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:
|
else:
|
||||||
logger.info("Previous hash unpinned on local")
|
logger.info("Previous hash unpinned on local")
|
||||||
|
|
||||||
|
@ -118,8 +118,8 @@ def run(args, **kwargs):
|
||||||
"arg": previous_hash,
|
"arg": previous_hash,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
url = "{}/api/v0/pin/rm?{}".format(args.api, data)
|
url = f"{args.api}/api/v0/pin/rm?{data}"
|
||||||
logger.debug("server unpin request: {}".format(url))
|
logger.debug("server unpin request: %s", url)
|
||||||
request = urllib.request.Request(url, method="POST")
|
request = urllib.request.Request(url, method="POST")
|
||||||
urllib.request.urlopen(request)
|
urllib.request.urlopen(request)
|
||||||
logger.info("Previous hash unpinned on server")
|
logger.info("Previous hash unpinned on server")
|
||||||
|
|
|
@ -18,43 +18,39 @@ def options(parser, config, **kwargs):
|
||||||
"--song_folder",
|
"--song_folder",
|
||||||
type=Path,
|
type=Path,
|
||||||
default=config["global"]["song_folder"],
|
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(
|
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(
|
parser.add_argument(
|
||||||
"-u",
|
"-u",
|
||||||
"--user",
|
"--user",
|
||||||
default=config[name]["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(
|
parser.add_argument(
|
||||||
"-p",
|
"-p",
|
||||||
"--port",
|
"--port",
|
||||||
default=config[name]["port"],
|
default=config[name]["port"],
|
||||||
type=int,
|
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(
|
parser.add_argument(
|
||||||
"-d",
|
"-d",
|
||||||
"--destination",
|
"--destination",
|
||||||
default=config[name]["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):
|
def run(args, **kwargs):
|
||||||
contents = str(args.song_folder.expanduser()) + "/"
|
contents = str(args.song_folder.expanduser()) + "/"
|
||||||
destination = "{user}@{host}:{folder}".format(
|
destination = f"{args.user}@{args.host}:{args.destination}"
|
||||||
user=args.user,
|
|
||||||
host=args.host,
|
|
||||||
folder=args.destination,
|
|
||||||
)
|
|
||||||
command = [
|
command = [
|
||||||
"rsync",
|
"rsync",
|
||||||
"-av",
|
"-av",
|
||||||
"--rsh=ssh -p {}".format(args.port),
|
f"--rsh=ssh -p {args.port}",
|
||||||
contents,
|
contents,
|
||||||
destination,
|
destination,
|
||||||
]
|
]
|
||||||
|
|
|
@ -17,23 +17,21 @@ def options(parser, config, **kwargs):
|
||||||
"--song_folder",
|
"--song_folder",
|
||||||
type=Path,
|
type=Path,
|
||||||
default=config["global"]["song_folder"],
|
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(
|
parser.add_argument(
|
||||||
"-p",
|
"-p",
|
||||||
"--port",
|
"--port",
|
||||||
default=config[name]["port"],
|
default=config[name]["port"],
|
||||||
type=int,
|
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(
|
parser.add_argument(
|
||||||
"--bind",
|
"--bind",
|
||||||
"-b",
|
"-b",
|
||||||
default=config[name]["bind"],
|
default=config[name]["bind"],
|
||||||
metavar="ADDRESS",
|
metavar="ADDRESS",
|
||||||
help="Specify alternate bind address, defaults to {}".format(
|
help="Specify alternate bind address, defaults to {config[name]['bind'] or 'all interfaces'}",
|
||||||
config[name]["bind"] or "all interfaces",
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue