def handle_levels(self, args): cur_level = self.file_operator.get_challenge().level print("Currently on level: \"{}\"\n".format(cur_level.name)) for level in all_levels.values(): # TODO Make pretty # TODO Add description print(level.name, ": {} challenges".format(len(level.challenges)))
def handle_levels(self, args): cur_level = self.file_operator.get_challenge().level print("Currently on level: \"{}\"\n".format(cur_level.name)) for level in all_levels.values(): # TODO Add description # 10 characters for the short IDs. print("Level {:<10} :{:>2} challenge{}".format("\"" + level.name + "\"", len(level.challenges), ("", "s")[len(level.challenges) > 1])) for index, challenge in enumerate(level.challenges.values()): # " " * (characters allocated for ID - 6) print("{}Challenge {:>2} : {:<10}".format(" " * 4, index + 1, challenge.name))
def handle_start(self, args): # Make sure it's safe to initialize if not args.force: # We aren't forcing if self.file_operator: print('Repo {} already initialized for git gud.'.format(self.file_operator.path)) print('Use --force to initialize {}.'.format(os.getcwd())) return self.file_operator = Operator(os.getcwd(), initialize_repo=False) if os.path.exists(self.file_operator.git_path): # Current directory is a git repo print('Currently in a git repo. Use --force to force initialize here.') return if os.path.exists(self.file_operator.gg_path): # Current directory is a git repo print('Git gud has already initialized. Use --force to force initialize again.') return if len(os.listdir(self.file_operator.path)) != 0: print('Current directory is nonempty. Use --force to force initialize here.') return else: print('Force initializing git gud.') # After here, we initialize everything try: self.file_operator.repo = Repo(self.file_operator.path) except InvalidGitRepositoryError: self.file_operator.repo = Repo.init(self.file_operator.path) if not os.path.exists(self.file_operator.gg_path): os.mkdir(self.file_operator.gg_path) with open(self.file_operator.last_commit_path, 'w+') as commit_file: commit_file.write('0') # First commit will be 1 with open(self.file_operator.level_path, 'w+') as level_file: level1 = next(iter(all_levels.values())) challenge1 = next(iter(level1.challenges.values())) level_file.write(challenge1.full_name()) python_exec = sys.executable.replace('\\', '/') # Git uses unix-like path separators for git_hook_name, module_hook_name in all_hooks: with open(os.path.join(self.file_operator.hooks_path, git_hook_name), 'w+') as hook_file: hook_file.write('#!/bin/sh' + os.linesep) hook_file.write('cat - | ' + python_exec + ' -m gitgud.hooks.' + module_hook_name + ' $1' +os.linesep) hook_file.write('exit 0' + os.linesep) print('Git Gud successfully setup in {}'.format(os.getcwd())) self.file_operator.get_challenge().setup(self.file_operator)