66 lines
1.4 KiB
Python
66 lines
1.4 KiB
Python
import os
|
|
|
|
from cd.project import Project
|
|
from cd.projects import Projects
|
|
from rwx import ps
|
|
|
|
COMMANDS_PREFIX = 'cd-'
|
|
|
|
projects = Projects(os.environ)
|
|
project = Project(projects)
|
|
|
|
|
|
def cd_browse_workspace():
|
|
print(f'''\
|
|
{project.root}
|
|
↓
|
|
''', end=str())
|
|
paths = []
|
|
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)
|
|
paths.append(relative_path)
|
|
for path in sorted(paths):
|
|
print(path)
|
|
|
|
|
|
def cd_build_project():
|
|
for extension in ['py', 'sh']:
|
|
path = os.path.join(project.root, f'build.{extension}')
|
|
if os.path.exists(path):
|
|
ps.run(path)
|
|
break
|
|
else:
|
|
pass
|
|
|
|
|
|
def cd_clone_branch():
|
|
print(f'''\
|
|
{project.url}
|
|
↓
|
|
''', end=str(), flush=True)
|
|
ps.run('git',
|
|
'clone',
|
|
'--branch', project.branch,
|
|
'--',
|
|
project.url,
|
|
project.root,
|
|
)
|
|
|
|
|
|
def cd_list_environment():
|
|
for variable, value in sorted(os.environ.items()):
|
|
print(variable, '=', value)
|
|
|
|
|
|
def install_commands(path):
|
|
user = '/usr/local/bin'
|
|
for command in [
|
|
'browse-workspace',
|
|
'build-project',
|
|
'clone-branch',
|
|
'list-environment',
|
|
]:
|
|
print(command)
|
|
os.symlink(path, os.path.join(user, f'{COMMANDS_PREFIX}{command}'))
|