def main(args): try: conf = config.get() except: pass if paths.inside_project(conf['projects-path']): # print('Inside') pass else: # print('Outside') pass
def test__outside_projects__returns_false(self, mock_os): p = '/machine/projects' mock_os.getcwd.return_value = '/machine' result = paths.inside_project(p) self.assertEqual(False, result)
def test__deep_inside_project__returns_true(self, mock_os): p = '/machine/projects' mock_os.getcwd.return_value = '/machine/projects/project/d1/d2/d3' result = paths.inside_project(p) self.assertEqual(True, result)
def test__current_path_gets_called(self, mock_os): paths.inside_project('some/path') mock_os.getcwd.assert_called_with()
def main(args): signal.signal(signal.SIGTSTP, sigterm_handle) try: conf = config.get() if not os.path.isdir(conf['projects-path']): os.mkdir(conf['projects-path']) print("Projects root was created: {}".format(conf['projects-path'])) print("You can put your projects here.") with open(os.path.join(os.path.expanduser('~'), '.p-path'), 'w+') as f: f.write(conf['projects-path']) return else: if not os.listdir(conf['projects-path']): print("Your projects directory is empty. Nothing to do..") with open(os.path.join(os.path.expanduser('~'), '.p-path'), 'w+') as f: f.write(conf['projects-path']) return args = args[2:] if len(args) == 1: if args[0] in ['-v', '--version']: print(__version__) return elif args[0] in ['-i', '--init']: if paths.inside_project(conf['projects-path']): if os.path.isfile('Projectfile'): print('You already have a Projectfile in this directory.. Nothing to do ;)') else: projectfile_content = projectfile.DEFAULT_PROJECTFILE.format(__version__) with open('Projectfile', 'w+') as f: f.write(projectfile_content) print('Projectfile created. Use the "p" command to invoke the manual.') else: print('You are not inside any of your projects. Use the "p" command to navigate into one.') return elif args[0] in ['-h', '--help']: pydoc.pager(help_text) return elif args[0] in ['-w', '--walk']: if paths.inside_project(conf['projects-path']): print(projectfile.get_walk_order(os.getcwd())) else: print('You are not inside any of your projects. Use the "p" command to navigate into one.') return elif args[0] in ['p']: handle_project_selection(conf) return elif args[0] in ['-l', '--list']: print('Command name missing after this option. Cannot list the command body..\np (-l|--list) <command>') return elif args[0] in ['-md', '--markdown']: project_root = paths.get_project_root(conf['projects-path'], os.getcwd()) data = projectfile.get_data_for_root(project_root['path']) data['name'] = project_root['name'] md_content = gui.generate_markdown(data) with open(os.path.join(project_root['path'], 'README.md'), 'w+') as f: f.write(md_content) print("README.md file was generated into your project's root.") return if len(args) == 2: if args[0] in ['-l', '--list']: command = args[1] project_root = paths.get_project_root(conf['projects-path'], os.getcwd()) data = projectfile.get_data_for_root(project_root['path']) if command in data['commands']: if 'alias' in data['commands'][command]: command = data['commands'][command]['alias'] for line in data['commands'][command]['script']: print(line) else: print('Invalid command: "{}"\nAvailable commands:'.format(command)) for c in data['commands']: print(c) return elif args[0] in ['-md', '--markdown']: name = args[1] project_root = paths.get_project_root(conf['projects-path'], os.getcwd()) data = projectfile.get_data_for_root(project_root['path']) data['name'] = project_root['name'] md_content = gui.generate_markdown(data) with open(os.path.join(project_root['path'], name), 'w+') as f: f.write(md_content) print("A markdown file named \"{}\" was generated into your project's root.".format(name)) return if paths.inside_project(conf['projects-path']): handle_inside_project(args, conf) else: handle_project_selection(conf) except projectfile.error.ProjectfileError as e: error = e.args[0] message = 'Projectfile error!\n{}'.format(error['error']) if 'path' in error: message = '{}\nPath: {}/Projectfile'.format(message, error['path']) if 'line' in error: message = '{}\nLine: {}'.format(message, error['line']) print(colored(message, 'red')) sys.exit(-1) except config.ConfigError as e: error = e.args[0] message = 'Config error!\n{}'.format(error) print(colored(message, 'red')) sys.exit(-1)