def stage(self, directory=None, name=None, alias=None, create_hop_file=False): if directory is None: directory = getcwd() directory = path.abspath(directory) if not path.exists(directory): self.composer.add('error', f'Directory {directory} does not exist') if name is None: name = path.basename(directory).title() if alias is None: alias = name.lower() if create_hop_file is None: create_hop_file = False all_projects = configs.configs.get('projects') project_directories = { apath(config.get('path')): name for name, config in all_projects.items() } if directory in project_directories: project_name = project_directories[directory] self.composer.add( 'warning', f'Project {project_name} already configured for directory {directory}' ) else: basic_config = f""" {alias}: name: {name} path: {directory}""" self.composer.add( 'message', f'\e[32mAdding new project {name} to ~/.hoprc\e[0m') with open(apath('~/.hoprc'), 'a+') as f: f.write(basic_config) if create_hop_file: hop_file_destination = path.join(directory, '.hop') if path.exists(hop_file_destination): self.composer.add('warning', f'.hop file already exists in {directory}') else: self.composer.add('message', f'\e[32mCreating .hop file in {directory}') example_hop_file = path.join(sys.argv[0], 'ext/.hop.example') shutil.copy(example_hop_file, hop_file_destination)
def stage(self, project_name=None, edit_global=False): config_file = None if edit_global: config_file = '~/.hoprc' elif project_name is not None: config = configs.project_configs(project_name) hop_file = path.join(config.get('path'), '.hop') if path.exists(apath(hop_file)): config_file = hop_file else: self.composer.add('message', [ f'No .hop file is present in project {project_name}. Your options are:', '', f' \e[32m$\e[0m hop to {project_name}', f' \e[32m$\e[0m hop init --create-hop-file', '', 'or you can edit the global config file with:', '', ' \e[32m$\e[0m hop edit -g' ]) return else: self.composer.add('error', 'No options specified') self.composer.add('task', f'$EDITOR {config_file} </dev/tty')
def current_project(self): current_project = None project_paths = { k: apath(v['path']).rstrip('/') for k, v in self.configs.get('projects', {}).items() } current_path = getcwd() for project, project_path in project_paths.items(): if issubdir(current_path, project_path): current_project = project return current_project
def project_configs(self, project_name=current_project): project_global_config = (self.configs.get('projects', {}).get(project_name)) if project_global_config: project_root = project_global_config.get('path') if project_root: config_path = apath(f'{project_root}/.hop') if path.exists(config_path): project_specific_config = self.load_config(config_path) combined = mergedicts(project_global_config, project_specific_config) return combined else: return project_global_config else: composer.add( 'error', f'path is not configured for project {project_name}') else: composer.add('error', f'Project is not configured')
def __init__(self): self.configs = {} self.configs = self.load_config(apath('~/.hoprc'))
def stage(self, project_name=None): project_configs = configs.project_configs(project_name) project_path = apath(project_configs.get("path")) self.composer.add('task', f'cd {project_configs.get("path")}')
from commands._hop_command import HopCommand from tasks._task import Task from config_handler import configs from helpers.utils import apath from os.path import isdir import inspect import pkgutil import sys import types sys.path.append(apath('~/.hop/lib')) def load_carrots(composer=None): bunch = {} imported_package = __import__('carrots', fromlist=['devnull']) for _1, bunch_name, is_pkg1 in pkgutil.iter_modules( imported_package.__path__, imported_package.__name__ + '.'): if is_pkg1: bunch_package = __import__(bunch_name, fromlist=['devnull']) carrot_members = [ m for m in inspect.getmembers(bunch_package, inspect.isclass) if m[1].__module__.split('.')[0] == 'carrots' ] carrot = None for (_, c) in carrot_members: if 'Carrot' in [i.__name__ for i in c.__bases__]: carrot = { 'name': c.__name__, 'klass': c(),
#!/usr/bin/env python3 from composer import composer from helpers.loaders import initialize_hop from helpers.utils import apath import argparse import sys sys.path.append(apath('~/repos/personal/task-hopper')) def run_hop_command(command, parsed_args): command.process_command(parsed_args) def main(): commands = initialize_hop(composer=composer) parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='subparser_name', metavar='') for alias, cls in commands.items(): cls.setup_command(subparsers) if len(sys.argv) == 1 or sys.argv[-1] in ['-h', '--help']: # print directive before showing help message print('__hop_message__') if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1)