parent
807049f27b
commit
660cdbde11
4 changed files with 22 additions and 22 deletions
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import env
|
import env
|
||||||
from rwx import fs, ps
|
from rwx import fs, ps
|
||||||
|
@ -18,8 +19,8 @@ def cd_browse_workspace() -> None:
|
||||||
|
|
||||||
def cd_build_project() -> None:
|
def cd_build_project() -> None:
|
||||||
for extension in ["py", "sh"]:
|
for extension in ["py", "sh"]:
|
||||||
path = os.path.join(project.root, f"build.{extension}")
|
path = Path(project.root) / f"build.{extension}"
|
||||||
if os.path.exists(path):
|
if path.exists():
|
||||||
ps.run(path)
|
ps.run(path)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@ -50,8 +51,7 @@ def cd_synchronize() -> None:
|
||||||
source = "out"
|
source = "out"
|
||||||
user = "cd"
|
user = "cd"
|
||||||
#
|
#
|
||||||
root = os.sep.join(["",
|
root = Path(os.sep) / 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",
|
||||||
|
@ -68,7 +68,7 @@ def browse(root: str) -> None:
|
||||||
paths = []
|
paths = []
|
||||||
for directory, _, files in os.walk(root):
|
for directory, _, files in os.walk(root):
|
||||||
for file in files:
|
for file in files:
|
||||||
absolute_path = os.path.join(directory, file)
|
absolute_path = Path(directory) / file
|
||||||
relative_path = os.path.relpath(absolute_path, start=root)
|
relative_path = os.path.relpath(absolute_path, start=root)
|
||||||
paths.append(relative_path)
|
paths.append(relative_path)
|
||||||
open(root)
|
open(root)
|
||||||
|
@ -85,7 +85,7 @@ def cat(file: str) -> None:
|
||||||
|
|
||||||
def install_commands(path) -> None:
|
def install_commands(path) -> None:
|
||||||
step("Install commands")
|
step("Install commands")
|
||||||
user = "/usr/local/bin"
|
user = Path("/usr/local/bin")
|
||||||
for command in [
|
for command in [
|
||||||
"browse-workspace",
|
"browse-workspace",
|
||||||
"build-project",
|
"build-project",
|
||||||
|
@ -94,7 +94,7 @@ def install_commands(path) -> None:
|
||||||
"synchronize",
|
"synchronize",
|
||||||
]:
|
]:
|
||||||
print(command)
|
print(command)
|
||||||
os.symlink(path, os.path.join(user, f"{COMMANDS_PREFIX}{command}"))
|
os.symlink(path, user / f"{COMMANDS_PREFIX}{command}")
|
||||||
|
|
||||||
|
|
||||||
def set_ssh(*arguments) -> None:
|
def set_ssh(*arguments) -> None:
|
||||||
|
@ -104,21 +104,21 @@ def set_ssh(*arguments) -> None:
|
||||||
#
|
#
|
||||||
ssh_type = "ed25519"
|
ssh_type = "ed25519"
|
||||||
#
|
#
|
||||||
home = os.path.expanduser("~")
|
home = Path("~").expanduser()
|
||||||
#
|
#
|
||||||
ssh = os.path.join(home, ".ssh")
|
ssh = home / ".ssh"
|
||||||
os.makedirs(ssh, exist_ok=True)
|
ssh.mkdir(parents=True)
|
||||||
os.chmod(ssh, 0o700)
|
ssh.chmod(0o700)
|
||||||
#
|
#
|
||||||
key = os.path.join(ssh, f"id_{ssh_type}")
|
key = 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)
|
key.chmod(0o400)
|
||||||
#
|
#
|
||||||
known = os.path.join(ssh, "known_hosts")
|
known = ssh / "known_hosts"
|
||||||
if ssh_hosts:
|
if ssh_hosts:
|
||||||
fs.write(known, ssh_hosts)
|
fs.write(known, ssh_hosts)
|
||||||
os.chmod(known, 0o400)
|
known.chmod(0o400)
|
||||||
#
|
#
|
||||||
browse(ssh)
|
browse(ssh)
|
||||||
cat(known)
|
cat(known)
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import cd
|
import cd
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
command, *arguments = sys.argv
|
command, *arguments = sys.argv
|
||||||
command = os.path.basename(command)
|
command = Path(command).name
|
||||||
if command == "__main__.py":
|
if command == "__main__.py":
|
||||||
cd.set_ssh(*arguments)
|
cd.set_ssh(*arguments)
|
||||||
cd.install_commands(__file__)
|
cd.install_commands(__file__)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from os import path
|
from pathlib import Path
|
||||||
|
|
||||||
BRANCH = [
|
BRANCH = [
|
||||||
"GITHUB_REF_NAME",
|
"GITHUB_REF_NAME",
|
||||||
|
@ -24,10 +24,10 @@ class Project:
|
||||||
# name
|
# name
|
||||||
for variable in NAME:
|
for variable in NAME:
|
||||||
if value := projects.environment.get(variable, None):
|
if value := projects.environment.get(variable, None):
|
||||||
self.name = path.basename(value)
|
self.name = Path(value).name
|
||||||
# root
|
# root
|
||||||
for variable in ROOT:
|
for variable in ROOT:
|
||||||
if value := projects.environment.get(variable, None):
|
if value := projects.environment.get(variable, None):
|
||||||
self.root = value
|
self.root = value
|
||||||
# url
|
# url
|
||||||
self.url = path.join(projects.url, self.name)
|
self.url = Path(projects.url) / self.name
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from os import path
|
from pathlib import Path
|
||||||
|
|
||||||
GROUP_AND_NAME = [
|
GROUP_AND_NAME = [
|
||||||
"GITHUB_REPOSITORY",
|
"GITHUB_REPOSITORY",
|
||||||
|
@ -20,4 +20,4 @@ class Projects:
|
||||||
# url
|
# url
|
||||||
for variable in SERVER_URL:
|
for variable in SERVER_URL:
|
||||||
if value := self.environment.get(variable, None):
|
if value := self.environment.get(variable, None):
|
||||||
self.url = path.join(value, self.group)
|
self.url = Path(value) / self.group
|
||||||
|
|
Loading…
Reference in a new issue