Reformat with black.

This commit is contained in:
tecnovert
2024-11-15 18:52:19 +02:00
parent 6be9a14335
commit 732c87b013
66 changed files with 16755 additions and 9343 deletions

View File

@@ -9,91 +9,119 @@
Join docker compose fragments
"""
__version__ = '0.1'
__version__ = "0.1"
import os
import argparse
def get_bkp_offset(filename, ext='yml'):
def get_bkp_offset(filename, ext="yml"):
for i in range(1000):
if not os.path.exists(f'{filename}_bkp_{i}.{ext}'):
if not os.path.exists(f"{filename}_bkp_{i}.{ext}"):
return i
raise ValueError(f'Unable to get backup filename for: {filename}.{ext}')
raise ValueError(f"Unable to get backup filename for: {filename}.{ext}")
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-v', '--version', action='version',
version='%(prog)s {version}'.format(version=__version__))
parser.add_argument('-c', '--coins', nargs='+', help='<Required> Select coins', required=True)
parser.add_argument('--withscript', dest='withscript', help='Add container to run createoffers.py (default=false)', required=False, action='store_true')
parser.add_argument(
"-v",
"--version",
action="version",
version="%(prog)s {version}".format(version=__version__),
)
parser.add_argument(
"-c", "--coins", nargs="+", help="<Required> Select coins", required=True
)
parser.add_argument(
"--withscript",
dest="withscript",
help="Add container to run createoffers.py (default=false)",
required=False,
action="store_true",
)
args = parser.parse_args()
with_coins = ['particl', ]
with_coins = [
"particl",
]
for coin_name in args.coins:
parsed_name = coin_name.lower()
if parsed_name not in with_coins:
with_coins.append(parsed_name)
print('Preparing docker compose files with coins:', ','.join(with_coins))
print("Preparing docker compose files with coins:", ",".join(with_coins))
num_docker_compose = get_bkp_offset('docker-compose')
num_docker_compose_prepare = get_bkp_offset('docker-compose-prepare')
num_docker_compose = get_bkp_offset("docker-compose")
num_docker_compose_prepare = get_bkp_offset("docker-compose-prepare")
if os.path.exists('docker-compose.yml'):
os.rename('docker-compose.yml', f'docker-compose_bkp_{num_docker_compose}.yml')
if os.path.exists('docker-compose-prepare.yml'):
os.rename('docker-compose-prepare.yml', f'docker-compose-prepare_bkp_{num_docker_compose_prepare}.yml')
if os.path.exists("docker-compose.yml"):
os.rename("docker-compose.yml", f"docker-compose_bkp_{num_docker_compose}.yml")
if os.path.exists("docker-compose-prepare.yml"):
os.rename(
"docker-compose-prepare.yml",
f"docker-compose-prepare_bkp_{num_docker_compose_prepare}.yml",
)
fragments_dir = 'compose-fragments'
with open('docker-compose.yml', 'wb') as fp, open('docker-compose-prepare.yml', 'wb') as fpp:
with open(os.path.join(fragments_dir, '0_start.yml'), 'rb') as fp_in:
fragments_dir = "compose-fragments"
with (
open("docker-compose.yml", "wb") as fp,
open("docker-compose-prepare.yml", "wb") as fpp,
):
with open(os.path.join(fragments_dir, "0_start.yml"), "rb") as fp_in:
for line in fp_in:
fp.write(line)
fpp.write(line)
for coin_name in with_coins:
if coin_name == 'particl':
if coin_name == "particl":
# Nothing to do
continue
if coin_name in ('monero', 'wownero'):
with open(os.path.join(fragments_dir, '1_{coin_name}-wallet.yml'), 'rb') as fp_in:
if coin_name in ("monero", "wownero"):
with open(
os.path.join(fragments_dir, "1_{coin_name}-wallet.yml"), "rb"
) as fp_in:
for line in fp_in:
fp.write(line)
fpp.write(line)
with open(os.path.join(fragments_dir, '8_{coin_name}-daemon.yml'), 'rb') as fp_in:
with open(
os.path.join(fragments_dir, "8_{coin_name}-daemon.yml"), "rb"
) as fp_in:
for line in fp_in:
fp.write(line)
continue
if coin_name == 'decred':
with open(os.path.join(fragments_dir, '1_decred-wallet.yml'), 'rb') as fp_in:
if coin_name == "decred":
with open(
os.path.join(fragments_dir, "1_decred-wallet.yml"), "rb"
) as fp_in:
for line in fp_in:
fp.write(line)
fpp.write(line)
with open(os.path.join(fragments_dir, '8_decred-daemon.yml'), 'rb') as fp_in:
with open(
os.path.join(fragments_dir, "8_decred-daemon.yml"), "rb"
) as fp_in:
for line in fp_in:
fp.write(line)
continue
with open(os.path.join(fragments_dir, f'1_{coin_name}.yml'), 'rb') as fp_in:
with open(os.path.join(fragments_dir, f"1_{coin_name}.yml"), "rb") as fp_in:
for line in fp_in:
fp.write(line)
fpp.write(line)
with open(os.path.join(fragments_dir, '8_swapclient.yml'), 'rb') as fp_in:
with open(os.path.join(fragments_dir, "8_swapclient.yml"), "rb") as fp_in:
for line in fp_in:
fp.write(line)
if args.withscript:
with open(os.path.join(fragments_dir, '8_script.yml'), 'rb') as fp_in:
with open(os.path.join(fragments_dir, "8_script.yml"), "rb") as fp_in:
for line in fp_in:
fp.write(line)
with open(os.path.join(fragments_dir, '9_swapprepare.yml'), 'rb') as fp_in:
with open(os.path.join(fragments_dir, "9_swapprepare.yml"), "rb") as fp_in:
for line in fp_in:
fpp.write(line)
print('Done.')
print("Done.")
if __name__ == '__main__':
if __name__ == "__main__":
main()