This commit is contained in:
Marc Beninca 2024-06-07 10:26:18 +02:00
parent 660140c084
commit 04d9661def
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -6,7 +6,7 @@ import env
from rwx import fs from rwx import fs
from rwx import ps from rwx import ps
COMMANDS_PREFIX = 'cd-' COMMANDS_PREFIX = "cd-"
projects = Projects(os.environ) projects = Projects(os.environ)
project = Project(projects) project = Project(projects)
@ -17,8 +17,8 @@ def cd_browse_workspace():
def cd_build_project(): def cd_build_project():
for extension in ['py', 'sh']: for extension in ["py", "sh"]:
path = os.path.join(project.root, f'build.{extension}') path = os.path.join(project.root, f"build.{extension}")
if os.path.exists(path): if os.path.exists(path):
ps.run(path) ps.run(path)
break break
@ -27,14 +27,14 @@ def cd_build_project():
def cd_clone_branch(): def cd_clone_branch():
print(f'''\ print(f"""\
{project.url} {project.url}
''', end=str(), flush=True) """, end=str(), flush=True)
ps.run('git', ps.run("git",
'clone', "clone",
'--branch', project.branch, "--branch", project.branch,
'--', "--",
project.url, project.url,
project.root, project.root,
) )
@ -42,25 +42,25 @@ def cd_clone_branch():
def cd_list_environment(): def cd_list_environment():
for variable, value in sorted(projects.environment.items()): for variable, value in sorted(projects.environment.items()):
print(variable, '=', value) print(variable, "=", value)
def cd_synchronize(): def cd_synchronize():
host = 'rwx.work' host = "rwx.work"
source = 'out' source = "out"
user = 'cd' user = "cd"
# #
root = os.sep.join([str(), root = os.sep.join([str(),
user, project.branch, projects.group, project.name]) user, project.branch, projects.group, project.name])
# #
target = f'{user}@{host}:{root}' target = f"{user}@{host}:{root}"
ps.run('rsync', ps.run("rsync",
'--archive', "--archive",
'--delete-before', "--delete-before",
'--verbose', "--verbose",
f'{source}/', f"{source}/",
f'{target}/', f"{target}/",
'--dry-run', "--dry-run",
) )
@ -84,38 +84,38 @@ def cat(file: str):
def install_commands(path): def install_commands(path):
step('Install commands') step("Install commands")
user = '/usr/local/bin' user = "/usr/local/bin"
for command in [ for command in [
'browse-workspace', "browse-workspace",
'build-project', "build-project",
'clone-branch', "clone-branch",
'list-environment', "list-environment",
'synchronize', "synchronize",
]: ]:
print(command) print(command)
os.symlink(path, os.path.join(user, f'{COMMANDS_PREFIX}{command}')) os.symlink(path, os.path.join(user, f"{COMMANDS_PREFIX}{command}"))
def set_ssh(*arguments): def set_ssh(*arguments):
step('Set SSH') step("Set SSH")
# #
ssh_key, ssh_hosts = arguments ssh_key, ssh_hosts = arguments
# #
ssh_type = 'ed25519' ssh_type = "ed25519"
# #
home = os.path.expanduser('~') home = os.path.expanduser("~")
# #
ssh = os.path.join(home, '.ssh') ssh = os.path.join(home, ".ssh")
os.makedirs(ssh, exist_ok=True) os.makedirs(ssh, exist_ok=True)
os.chmod(ssh, 0o700) os.chmod(ssh, 0o700)
# #
key = os.path.join(ssh, f'id_{ssh_type}') key = os.path.join(ssh, f"id_{ssh_type}")
if ssh_key: if ssh_key:
fs.write(key, ssh_key) fs.write(key, ssh_key)
os.chmod(key, 0o400) os.chmod(key, 0o400)
# #
known = os.path.join(ssh, 'known_hosts') known = os.path.join(ssh, "known_hosts")
if ssh_hosts: if ssh_hosts:
fs.write(known, ssh_hosts) fs.write(known, ssh_hosts)
os.chmod(known, 0o400) os.chmod(known, 0o400)