spcd/cd/__init__.py

56 lines
1.2 KiB
Python
Raw Normal View History

2024-04-26 21:58:35 +02:00
import os
2024-04-27 15:32:33 +02:00
from cd.project import Project
from cd.projects import Projects
2024-04-27 01:10:30 +02:00
from rwx import ps
2024-04-26 23:55:20 +02:00
COMMANDS_PREFIX = 'cd-'
2024-04-27 17:09:51 +02:00
projects = Projects(os.environ)
project = Project(projects)
2024-04-27 15:32:33 +02:00
2024-04-26 23:55:20 +02:00
2024-05-30 00:21:42 +02:00
def cd_browse_workspace():
print(f'''\
{project.root}
''', end=str())
files = []
for directory, directories, files in os.walk(project.root):
for file in files:
absolute_path = os.path.join(directory, file)
relative_path = os.path.relpath(absolute_path, start=project.root)
files.append(relative_path)
for file in files:
print(file)
2024-04-27 01:10:30 +02:00
def cd_clone_branch():
2024-04-28 18:36:34 +02:00
print(f'''\
{project.url}
2024-04-28 18:40:31 +02:00
''', end=str(), flush=True)
2024-04-27 01:10:30 +02:00
ps.run('git',
'clone',
2024-04-27 15:32:33 +02:00
'--branch', project.branch,
2024-04-27 01:10:30 +02:00
'--',
2024-04-27 15:32:33 +02:00
project.url,
2024-04-28 18:48:01 +02:00
os.path.realpath(os.curdir),
2024-04-27 01:10:30 +02:00
)
2024-04-26 23:58:06 +02:00
def cd_list_environment():
2024-04-27 17:09:51 +02:00
for variable, value in sorted(os.environ.items()):
2024-04-27 00:06:41 +02:00
print(variable, '=', value)
2024-04-26 23:55:20 +02:00
2024-04-26 21:58:35 +02:00
2024-04-26 23:24:46 +02:00
def install_commands(path):
user = '/usr/local/bin'
2024-04-27 01:10:30 +02:00
for command in [
2024-05-30 00:21:42 +02:00
'browse-workspace',
2024-04-27 01:10:30 +02:00
'clone-branch',
'list-environment',
]:
2024-04-28 13:00:18 +02:00
print(command)
2024-04-26 23:55:20 +02:00
os.symlink(path, os.path.join(user, f'{COMMANDS_PREFIX}{command}'))