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