diff --git a/cd.sh b/cd.sh index eddae10..5058593 100644 --- a/cd.sh +++ b/cd.sh @@ -1,11 +1,11 @@ #! /usr/bin/env sh # defaults -[ -n "${CD_DNS}" ] || CD_DNS="\ +[ "${CD_DNS}" ] || CD_DNS="\ 9.9.9.9 \ " -[ -n "${CD_GIT_CHILD}" ] || CD_GIT_CHILD="cd" -[ -n "${CD_GIT_PARENT}" ] || CD_GIT_PARENT="rwx" +[ "${CD_GIT_CHILD}" ] || CD_GIT_CHILD="cd" +[ "${CD_GIT_PARENT}" ] || CD_GIT_PARENT="rwx" # main cd_main () { @@ -40,9 +40,6 @@ cd_main () { cd_set_environment_variables () { cd_step "Set environment variables" - # set path - CD_PATH="$(realpath "${0}")" - cd_echo "CD_PATH" # set operating system id CD_OS_ID="$(cd_grep_os ID)" case "${CD_OS_ID}" in @@ -68,7 +65,6 @@ cd_set_environment_variables () { "${CD_OS_DEBIAN}"|"${CD_OS_UBUNTU}") CD_OS_VERSION="$(cd_grep_os VERSION_CODENAME)" ;; - *) esac # check operating system version case "${CD_OS_ID}" in @@ -108,9 +104,7 @@ cd_set_environment_variables () { *) cd_error_os "CD_OS_VERSION" ;; esac ;; - *) esac - cd_split cd_echo "CD_OS_ID" "CD_OS_VERSION" # universal CD_DNS_FILE="/etc/resolv.conf" @@ -139,7 +133,6 @@ cd_set_environment_variables () { CD_CA_ROOT="/usr/local/share/ca-certificates" CD_CMD_CA="update-ca-certificates" ;; - *) esac cd_split cd_echo "CD_CA_ROOT" "CD_CMD_CA" @@ -157,7 +150,6 @@ cd_set_environment_variables () { "${CD_OS_ARCH}") CD_PM="${CD_PM_PACMAN}" ;; - *) esac cd_split cd_echo "CD_PM" @@ -231,7 +223,6 @@ Dir::Etc::SourceParts \"\"; Acquire::https::Verify-Peer False; " ;; - *) esac cd_split cd_echo "CD_PM_CLEAN" \ @@ -261,36 +252,34 @@ Acquire::https::Verify-Peer False; "${CD_OS_UBUNTU}") CD_URL_DEFAULT="http://archive.ubuntu.com/ubuntu" ;; - *) esac CD_URL_CHOSEN="${CD_URL_DEFAULT}" case "${CD_OS_ID}" in "${CD_OS_ALMA}") - [ -n "${CD_URL_ALMA}" ] && CD_URL_CHOSEN="${CD_URL_ALMA}" + [ "${CD_URL_ALMA}" ] && CD_URL_CHOSEN="${CD_URL_ALMA}" ;; "${CD_OS_ALPINE}") - [ -n "${CD_URL_ALPINE}" ] && CD_URL_CHOSEN="${CD_URL_ALPINE}" + [ "${CD_URL_ALPINE}" ] && CD_URL_CHOSEN="${CD_URL_ALPINE}" ;; "${CD_OS_ARCH}") - [ -n "${CD_URL_ARCH}" ] && CD_URL_CHOSEN="${CD_URL_ARCH}" + [ "${CD_URL_ARCH}" ] && CD_URL_CHOSEN="${CD_URL_ARCH}" ;; "${CD_OS_DEBIAN}") - [ -n "${CD_URL_DEBIAN}" ] && CD_URL_CHOSEN="${CD_URL_DEBIAN}" \ + [ "${CD_URL_DEBIAN}" ] && CD_URL_CHOSEN="${CD_URL_DEBIAN}" \ || CD_URL_CHOSEN="https://deb.debian.org/debian" ;; "${CD_OS_FEDORA}") - [ -n "${CD_URL_FEDORA}" ] && CD_URL_CHOSEN="${CD_URL_FEDORA}" \ + [ "${CD_URL_FEDORA}" ] && CD_URL_CHOSEN="${CD_URL_FEDORA}" \ || CD_URL_CHOSEN="https://rpmfind.net/linux/fedora/linux/releases" ;; "${CD_OS_ROCKY}") - [ -n "${CD_URL_ROCKY}" ] && CD_URL_CHOSEN="${CD_URL_ROCKY}" \ + [ "${CD_URL_ROCKY}" ] && CD_URL_CHOSEN="${CD_URL_ROCKY}" \ || CD_URL_CHOSEN="https://dl.rockylinux.org/\$contentdir" ;; "${CD_OS_UBUNTU}") - [ -n "${CD_URL_UBUNTU}" ] && CD_URL_CHOSEN="${CD_URL_UBUNTU}" \ + [ "${CD_URL_UBUNTU}" ] && CD_URL_CHOSEN="${CD_URL_UBUNTU}" \ || CD_URL_CHOSEN="https://ubuntu.mirrors.ovh.net/ubuntu" ;; - *) esac cd_split cd_echo "CD_URL_DEFAULT" "CD_URL_CHOSEN" @@ -312,7 +301,6 @@ Acquire::https::Verify-Peer False; case "${CD_OS_VERSION}" in "bookworm") CD_PYTHON_COMMAND="python3.11" ;; "bullseye") CD_PYTHON_COMMAND="python3.9" ;; - *) esac CD_PYTHON_PACKAGE="python3" ;; @@ -324,11 +312,9 @@ Acquire::https::Verify-Peer False; case "${CD_OS_VERSION}" in "noble") CD_PYTHON_COMMAND="python3.12" ;; "jammy") CD_PYTHON_COMMAND="python3.10" ;; - *) esac CD_PYTHON_PACKAGE="python3" ;; - *) esac # set python packages case "${CD_OS_ID}" in @@ -341,20 +327,19 @@ Acquire::https::Verify-Peer False; "${CD_OS_DEBIAN}"|"${CD_OS_UBUNTU}") CD_PYTHON_PACKAGES="/usr/lib/${CD_PYTHON_ALIAS}/dist-packages" ;; - *) esac cd_split cd_echo "CD_PYTHON_COMMAND" "CD_PYTHON_PACKAGE" "CD_PYTHON_PACKAGES" # variables - [ -n "${CD_CA_1}" ] && CD_CA=true + [ "${CD_CA_1}" ] && CD_CA=true # continuous integration platform - if [ -n "${GITHUB_ACTIONS}" ] ; then + if [ "${GITHUB_ACTIONS}" ] ; then # github → gitea → forgejo CD_SERVER_URL="${GITHUB_SERVER_URL}" CD_PROJECTS_GROUP="$(dirname "${GITHUB_REPOSITORY}")" CD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")" CD_PROJECT_BRANCH="${GITHUB_REF_NAME}" - elif [ -n "${GITLAB_CI}" ] ; then + elif [ "${GITLAB_CI}" ] ; then # gitlab CD_SERVER_URL="${CI_SERVER_URL}" CD_PROJECTS_GROUP="$(dirname "${CI_PROJECT_PATH}")" @@ -364,12 +349,13 @@ Acquire::https::Verify-Peer False; # unsupported cd_error_ci "ø" fi - [ -n "${CD_SERVER_URL}" ] || cd_error_ci "CD_SERVER_URL" - [ -n "${CD_PROJECTS_GROUP}" ] || cd_error_ci "CD_PROJECTS_GROUP" - [ -n "${CD_PROJECT_NAME}" ] || cd_error_ci "CD_PROJECT_NAME" - [ -n "${CD_PROJECT_BRANCH}" ] || cd_error_ci "CD_PROJECT_BRANCH" + [ "${CD_SERVER_URL}" ] || cd_error_ci "CD_SERVER_URL" + [ "${CD_PROJECTS_GROUP}" ] || cd_error_ci "CD_PROJECTS_GROUP" + [ "${CD_PROJECT_NAME}" ] || cd_error_ci "CD_PROJECT_NAME" + [ "${CD_PROJECT_BRANCH}" ] || cd_error_ci "CD_PROJECT_BRANCH" # CD_PROJECTS_URL="${CD_SERVER_URL}/${CD_PROJECTS_GROUP}" + CD_PROJECT_URL="${CD_PROJECTS_URL}/${CD_PROJECT_NAME}" # cd_split cd_echo "CD_CA" @@ -377,42 +363,40 @@ Acquire::https::Verify-Peer False; cd_echo "CD_SERVER_URL" \ "CD_PROJECTS_GROUP" "CD_PROJECT_NAME" "CD_PROJECT_BRANCH" cd_split - cd_echo "CD_PROJECTS_URL" + cd_echo "CD_PROJECTS_URL" "CD_PROJECT_URL" # TODO move to Python case "${CD_PM}" in "${CD_PM_APK}"|"${CD_PM_APT}") CD_PKG_SSH="openssh-client" ;; "${CD_PM_DNF}") CD_PKG_SSH="openssh-clients" ;; "${CD_PM_PACMAN}") CD_PKG_SSH="openssh" ;; - *) esac } cd_set_packages_repositories () { +local expression +local file cd_step "Set packages repositories" case "${CD_OS_ID}" in "${CD_OS_ALMA}") case "${CD_OS_VERSION}" in - "8") \ -cd_set_packages_repositories__file="/etc/yum.repos.d/almalinux.repo" ;; - "9") \ -cd_set_packages_repositories__file="/etc/yum.repos.d/almalinux-baseos.repo" ;; - *) + "8") file="/etc/yum.repos.d/almalinux.repo" ;; + "9") file="/etc/yum.repos.d/almalinux-baseos.repo" ;; esac - cd_sed "${cd_set_packages_repositories__file}" \ + cd_sed "${file}" \ "|^mirrorlist|# mirrorlist|" \ "|${CD_URL_DEFAULT}|${CD_URL_CHOSEN}|" \ "|^# baseurl|baseurl|" ;; "${CD_OS_ALPINE}") - cd_set_packages_repositories__file="/etc/apk/repositories" - cd_write "${cd_set_packages_repositories__file}" "\ + file="/etc/apk/repositories" + cd_write "${file}" "\ ${CD_URL_CHOSEN}/v${CD_OS_VERSION}/main ${CD_URL_CHOSEN}/v${CD_OS_VERSION}/community " ;; "${CD_OS_DEBIAN}") - cd_set_packages_repositories__file="/etc/apt/sources.list" - cd_write "${cd_set_packages_repositories__file}" "\ + file="/etc/apt/sources.list" + cd_write "${file}" "\ deb ${CD_URL_CHOSEN} ${CD_OS_VERSION} main deb ${CD_URL_CHOSEN} ${CD_OS_VERSION}-backports main deb ${CD_URL_CHOSEN} ${CD_OS_VERSION}-updates main @@ -421,27 +405,23 @@ deb ${CD_URL_CHOSEN}-security ${CD_OS_VERSION}-security main ;; "${CD_OS_ROCKY}") case "${CD_OS_VERSION}" in - "8") \ -cd_set_packages_repositories__file="/etc/yum.repos.d/Rocky-BaseOS.repo" ;; - "9") \ -cd_set_packages_repositories__file="/etc/yum.repos.d/rocky.repo" ;; - *) + "8") file="/etc/yum.repos.d/Rocky-BaseOS.repo" ;; + "9") file="/etc/yum.repos.d/rocky.repo" ;; esac - cd_sed "${cd_set_packages_repositories__file}" \ + cd_sed "${file}" \ "|^mirrorlist|# mirrorlist|" \ "|${CD_URL_DEFAULT}|${CD_URL_CHOSEN}|" \ "|^#baseurl|baseurl|" ;; "${CD_OS_UBUNTU}") - cd_set_packages_repositories__file="/etc/apt/sources.list" - cd_write "${cd_set_packages_repositories__file}" "\ + file="/etc/apt/sources.list" + cd_write "${file}" "\ deb ${CD_URL_CHOSEN} ${CD_OS_VERSION} main deb ${CD_URL_CHOSEN} ${CD_OS_VERSION}-backports main deb ${CD_URL_CHOSEN} ${CD_OS_VERSION}-updates main deb ${CD_URL_CHOSEN} ${CD_OS_VERSION}-security main " ;; - *) esac } @@ -452,7 +432,6 @@ cd_set_packages_configuration () { "${CD_OS_DEBIAN}"|"${CD_OS_UBUNTU}") export DEBIAN_FRONTEND="noninteractive" ;; - *) esac } @@ -460,12 +439,11 @@ cd_set_packages_configuration () { cd_list_working_directory () { cd_step "List working directory" - cd_list_working_directory__path="$(realpath .)" - cd_ls "${cd_list_working_directory__path}" + cd_ls "$(realpath .)" } cd_set_https_verification_off () { - if [ -n "${CD_CA}" ] || [ "${CD_PM}" = "${CD_PM_APT}" ] ; then + if [ "${CD_CA}" -o "${CD_PM}" = "${CD_PM_APT}" ] ; then cd_step "Set HTTPS verification off" cd_mkdir "$(dirname "${CD_PM_HTTPS_PATH}")" cd_write "${CD_PM_HTTPS_PATH}" "${CD_PM_HTTPS_TEXT}" @@ -473,13 +451,14 @@ cd_set_https_verification_off () { } cd_set_dns_resolving () { +local server +local text="" cd_step "Set DNS resolving" - for cd_set_dns_resolving__server in ${CD_DNS} ; do - cd_set_dns_resolving__text="${cd_set_dns_resolving__text}\ -nameserver ${cd_set_dns_resolving__server} + for server in ${CD_DNS} ; do + text="${text}nameserver ${server} " done - cd_write "${CD_DNS_FILE}" "${cd_set_dns_resolving__text}" + cd_write "${CD_DNS_FILE}" "${text}" } cd_update_packages_catalog () { @@ -498,22 +477,20 @@ cd_install_ca_certificates () { } cd_write_ca_certificates () { +local index +local path +local text cd_step "Write CA certificates" cd_mkdir "${CD_CA_ROOT}" - cd_write_ca_certificates__index=1 - eval "cd_write_ca_certificates__text=\ -\"\${CD_CA_${cd_write_ca_certificates__index}}\"" - while [ -n "${cd_write_ca_certificates__text}" ] ; do - cd_write_ca_certificates__path="\ -${CD_CA_ROOT}/${cd_write_ca_certificates__index}.crt" + index=1 + eval "text=\"\${CD_CA_${index}}\"" + while [ "${text}" ] ; do + path="${CD_CA_ROOT}/${index}.crt" cd_split - cd_write \ - "${cd_write_ca_certificates__path}" \ - "${cd_write_ca_certificates__text}" - cd_openssl "${cd_write_ca_certificates__path}" - cd_write_ca_certificates__index=$((cd_write_ca_certificates__index+1)) - eval "cd_write_ca_certificates__text=\ -\"\${CD_CA_${cd_write_ca_certificates__index}}\"" + cd_write "${path}" "${text}" + cd_openssl "${path}" + index=$((index+1)) + eval "text=\"\${CD_CA_${index}}\"" done } @@ -562,174 +539,169 @@ cd_clean_packages_cache () { } cd_install_python_modules () { +local path +local repository +local root +local url cd_step "Install Python modules" - cd_install_python_modules__root="$(mktemp --directory)" || exit - echo "→ ${cd_install_python_modules__root}" - for cd_install_python_modules__repository \ - in "${CD_GIT_CHILD}" "${CD_GIT_PARENT}" ; do + root="$(mktemp --directory)" || exit + echo "→ ${root}" + for repository in "${CD_GIT_CHILD}" "${CD_GIT_PARENT}" ; do cd_split - cd_install_python_modules__url="\ -${CD_PROJECTS_URL}/${cd_install_python_modules__repository}" - echo "\ -${cd_install_python_modules__url} -↓" - git clone \ - "${cd_install_python_modules__url}" \ - "${cd_install_python_modules__root}\ -/${cd_install_python_modules__repository}" \ - || exit - cd_install_python_modules__path="\ -${cd_install_python_modules__root}\ -/${cd_install_python_modules__repository}\ -/${cd_install_python_modules__repository}" - echo "\ -${cd_install_python_modules__path} + url="${CD_PROJECTS_URL}/${repository}" + echo -n "\ +${url} ↓ -${CD_PYTHON_PACKAGES}" +" + git clone \ + "${url}" "${root}/${repository}" \ + || exit + path="${root}/${repository}/${repository}" + echo -n "\ +${path} +↓ +${CD_PYTHON_PACKAGES} +" cp --recursive \ - "${cd_install_python_modules__path}" "${CD_PYTHON_PACKAGES}" \ + "${path}" "${CD_PYTHON_PACKAGES}" \ || exit done cd_split cd_ls "${CD_PYTHON_PACKAGES}" cd_split - cd_rm "${cd_install_python_modules__root}" + cd_rm "${root}" } cd_write_python_module () { cd_step "Write Python module" - for cd_write_python_module__variable \ - in OPEN DOWN VERT SPLT __UP SHUT OS_ID OS_VERSION ; do - cd_write_python_module__value="\ -$(cd_echo "CD_${cd_write_python_module__variable}")" - cd_write_python_module__text="${cd_write_python_module__text}\ -${cd_write_python_module__value} -" - done - cd_write "${CD_PYTHON_PACKAGES}/env.py" "${cd_write_python_module__text}\ + cd_write "${CD_PYTHON_PACKAGES}/env.py" "\ +$(cd_echo CD_OPEN CD_DOWN) +$(cd_echo CD_VERT CD_SPLT) +$(cd_echo CD___UP CD_SHUT) + +$(cd_echo CD_OS_ID CD_OS_VERSION) + CD_STEP = $((CD_STEP+1)) " } cd_switch_to_python () { +local path cd_step "Switch to Python" - echo "\ -${CD_PATH} + # + path="$(realpath "${0}")" + echo -n "\ +${path} ↓ -${CD_PYTHON_PACKAGES}/${CD_GIT_CHILD}" +${CD_PYTHON_PACKAGES}/${CD_GIT_CHILD} +" "${CD_PYTHON_ALIAS}" -m "${CD_GIT_CHILD}" "${@}" } # functions cd_cat () { - cd_cat__file="${1}" - if [ -n "${cd_cat__file}" ] ; then - cd_open "${cd_cat__file}" - cat "${cd_cat__file}" || exit - cd_shut "${cd_cat__file}" + if [ -f "${1}" ] ; then + cd_open "${1}" + cat "${1}" || exit + cd_shut "${1}" fi } cd_echo () { - if [ -n "${1}" ] ; then - for cd_echo__name in "${@}" ; do - eval "echo ${cd_echo__name} = \\\"\${${cd_echo__name}}\\\"" +local name + if [ "${1}" ] ; then + for name in "${@}" ; do + eval "echo ${name} = \\\"\${${name}}\\\"" done fi } cd_error_ci () { - echo "× CI: ${*}" - exit "${CD_ERROR_CI}" + echo "× CI: ${1}" + exit ${CD_ERROR_CI} } cd_error_os () { - cd_error_os__variable="${1}" - printf "× OS: " - cd_echo "${cd_error_os__variable}" - exit "${CD_ERROR_OS}" +local variable="${1}" + echo -n "× OS: " + cd_echo "${variable}" + exit ${CD_ERROR_OS} } cd_grep_os () { - cd_grep_os__variable="${1}" - if [ -n "${cd_grep_os__variable}" ] ; then - grep "^${cd_grep_os__variable}=" "/etc/os-release" \ - | sed "s|^${cd_grep_os__variable}=||" \ +local variable="${1}" + if [ "${variable}" ] ; then + grep "^${variable}=" "/etc/os-release" \ + | sed "s|^${variable}=||" \ | sed "s|^\"\(.*\)\"$|\1|" fi } cd_install_package () { - cd_install_package__name="${1}" - if [ -n "${cd_install_package__name}" ] ; then - ${CD_PM_INSTALL} "${cd_install_package__name}" || exit + if [ "${1}" ] ; then + ${CD_PM_INSTALL} "${1}" || exit fi } cd_ln_python () { - cd_ln_python__command="${1}" - if [ -n "${cd_ln_python__command}" ] ; then - echo "→ ${CD_PYTHON_ALIAS} → ${cd_ln_python__command}" - ln -f -s "${cd_ln_python__command}" "/usr/bin/${CD_PYTHON_ALIAS}" \ - || exit +local command="${1}" + if [ "${command}" ] ; then + echo "→ ${CD_PYTHON_ALIAS} → ${command}" + ln -f -s "${command}" "/usr/bin/${CD_PYTHON_ALIAS}" || exit fi } cd_ls () { - cd_ls__path="${1}" - if [ -n "${cd_ls__path}" ] ; then - cd_open "${cd_ls__path}" - ls -a -l "${cd_ls__path}" || exit - cd_shut "${cd_ls__path}" + if [ -d "${1}" ] ; then + cd_open "${1}" + ls -a -l "${1}" || exit + cd_shut "${1}" fi } cd_mkdir () { - cd_mkdir__path="${1}" - if [ -n "${cd_mkdir__path}" ] ; then - echo "→ ${cd_mkdir__path}" - mkdir --parents "${cd_mkdir__path}" || exit + if [ "${1}" ] ; then + echo "→ ${1}" + mkdir --parents "${1}" || exit fi } cd_open () { - echo "${CD_OPEN}${*}" + echo "${CD_OPEN}${@}" } cd_openssl () { - cd_openssl__file="${1}" - if [ -f "${cd_openssl__file}" ] ; then - openssl x509 \ - -in "${cd_openssl__file}" \ - -noout -text \ - || exit +local file="${1}" + if [ -f "${file}" ] ; then + openssl x509 -noout -text -in "${file}" || exit fi } cd_rm () { - cd_rm__path="${1}" - if [ -e "${cd_rm__path}" ] ; then - echo "← ${cd_rm__path}" - rm -r "${cd_rm__path}" || exit +local path="${1}" + if [ -e "${path}" ] ; then + echo "← ${path}" + rm -r "${path}" || exit fi } cd_sed () { - cd_sed__file="${1}" - shift - if [ -f "${cd_sed__file}" ] ; then - cd_cat "${cd_sed__file}" - for cd_sed__regex in "${@}" ; do - sed --in-place "s${cd_sed__regex}g" "${cd_sed__file}" \ - && cd_cat "${cd_sed__file}" \ +local expression +local file="${1}" +shift + if [ -f "${file}" ] ; then + cd_cat "${file}" + for expression in "${@}" ; do + sed --in-place "s${expression}g" "${file}" \ + && cd_cat "${file}" \ || exit done fi } cd_shut () { - echo "${CD_SHUT}${*}" + echo "${CD_SHUT}${@}" } cd_split () { @@ -738,20 +710,21 @@ cd_split () { cd_step () { CD_STEP=$((CD_STEP+1)) - echo "\ + echo -n "\ ${CD_DOWN} -${CD_VERT} ${CD_STEP} ${*} -${CD___UP}" +${CD_VERT} ${CD_STEP} ${@} +${CD___UP} +" } cd_write () { - cd_write__file="${1}" - cd_write__text="${2}" - if [ -n "${cd_write__file}" ] ; then - [ -f "${cd_write__file}" ] && cd_cat "${cd_write__file}" - echo "→ ${cd_write__file}" - printf "%s" "${cd_write__text}" > "${cd_write__file}" || exit - cd_cat "${cd_write__file}" +local file="${1}" +local text="${2}" + if [ "${file}" ] ; then + [ -f "${file}" ] && cd_cat "${file}" + echo "→ ${1}" + echo -n "${text}" > "${file}" || exit + cd_cat "${file}" fi } diff --git a/cd/__init__.py b/cd/__init__.py index 4ea730e..befcf35 100644 --- a/cd/__init__.py +++ b/cd/__init__.py @@ -6,7 +6,7 @@ import env from rwx import fs from rwx import ps -COMMANDS_PREFIX = "cd-" +COMMANDS_PREFIX = 'cd-' projects = Projects(os.environ) project = Project(projects) @@ -17,8 +17,8 @@ def cd_browse_workspace(): def cd_build_project(): - for extension in ["py", "sh"]: - path = os.path.join(project.root, f"build.{extension}") + for extension in ['py', 'sh']: + path = os.path.join(project.root, f'build.{extension}') if os.path.exists(path): ps.run(path) break @@ -27,14 +27,14 @@ def cd_build_project(): def cd_clone_branch(): - print(f"""\ + print(f'''\ {project.url} ↓ -""", end="", flush=True) - ps.run("git", - "clone", - "--branch", project.branch, - "--", +''', end=str(), flush=True) + ps.run('git', + 'clone', + '--branch', project.branch, + '--', project.url, project.root, ) @@ -42,25 +42,25 @@ def cd_clone_branch(): def cd_list_environment(): for variable, value in sorted(projects.environment.items()): - print(variable, "=", value) + print(variable, '=', value) def cd_synchronize(): - host = "rwx.work" - source = "out" - user = "cd" + host = 'rwx.work' + source = 'out' + user = 'cd' # - root = os.sep.join(["", + root = os.sep.join([str(), user, project.branch, projects.group, project.name]) # - target = f"{user}@{host}:{root}" - ps.run("rsync", - "--archive", - "--delete-before", - "--verbose", - f"{source}/", - f"{target}/", - "--dry-run", + target = f'{user}@{host}:{root}' + ps.run('rsync', + '--archive', + '--delete-before', + '--verbose', + f'{source}/', + f'{target}/', + '--dry-run', ) @@ -84,38 +84,38 @@ def cat(file: str): def install_commands(path): - step("Install commands") - user = "/usr/local/bin" + step('Install commands') + user = '/usr/local/bin' for command in [ - "browse-workspace", - "build-project", - "clone-branch", - "list-environment", - "synchronize", + 'browse-workspace', + 'build-project', + 'clone-branch', + 'list-environment', + 'synchronize', ]: 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): - step("Set SSH") + step('Set SSH') # 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.chmod(ssh, 0o700) # - key = os.path.join(ssh, f"id_{ssh_type}") + key = os.path.join(ssh, f'id_{ssh_type}') if ssh_key: fs.write(key, ssh_key) os.chmod(key, 0o400) # - known = os.path.join(ssh, "known_hosts") + known = os.path.join(ssh, 'known_hosts') if ssh_hosts: fs.write(known, ssh_hosts) os.chmod(known, 0o400) @@ -125,12 +125,12 @@ def set_ssh(*arguments): def open(*arguments): - print(env.CD_OPEN, end="") + print(env.CD_OPEN, end=str()) print(*arguments, flush=True) def shut(*arguments): - print(env.CD_SHUT, end="") + print(env.CD_SHUT, end=str()) print(*arguments, flush=True)