def sync_branch(self, branch):
        """Sync clowder repo to specified branch"""
        try:
            repo = Repo(self.clowder_path)
        except:
            repo_path_output = colored(self.clowder_path, 'cyan')
            print("Failed to create Repo instance for " + repo_path_output)
        else:
            if git_is_detached(self.clowder_path):
                try:
                    repo.git.checkout(branch)
                except:
                    print("Failed to checkout branch " + branch)
                    print_exiting()

            if repo.active_branch.name != branch:
                try:
                    repo.git.checkout(branch)
                except:
                    print("Failed to checkout branch " + branch)
                    print_exiting()

            self._validate()
            self.print_status()
            git_pull(self.clowder_path)
            self.symlink_yaml()
 def _validate(self, group_names):
     """Validate status of all projects for specified groups"""
     valid = True
     for group in self.groups:
         if group.name in group_names:
             group.print_validation()
             if not group.is_valid():
                 valid = False
     if not valid:
         print_exiting()
 def sync(self):
     """Sync clowder repo"""
     self._validate()
     self.print_status()
     if not git_is_detached(self.clowder_path):
         git_pull(self.clowder_path)
         self.symlink_yaml()
     else:
         print(' - HEAD is detached')
         print_exiting()
 def _validate_projects_exist(self):
     """Validate existence status of all projects for specified groups"""
     projects_exist = True
     for group in self.groups:
         group.print_existence_message()
         if not group.projects_exist():
             projects_exist = False
     if not projects_exist:
         herd_output = colored('clowder herd', 'yellow')
         print('')
         print('First run ' + herd_output + ' to clone missing projects')
         print_exiting()
    def symlink_yaml(self, version=None):
        """Create symlink pointing to clowder.yaml file"""
        if version == None:
            yaml_file = os.path.join(self.root_directory, 'clowder', 'clowder.yaml')
            path_output = colored('clowder/clowder.yaml', 'cyan')
        else:
            relative_path = os.path.join('clowder', 'versions', version, 'clowder.yaml')
            path_output = colored(relative_path, 'cyan')
            yaml_file = os.path.join(self.root_directory, relative_path)

        if os.path.isfile(yaml_file):
            yaml_symlink = os.path.join(self.root_directory, 'clowder.yaml')
            print(' - Symlink ' + path_output)
            force_symlink(yaml_file, yaml_symlink)
        else:
            print(path_output + " doesn't seem to exist")
            print_exiting()
    def fix_version(self, version):
        """Save current commits to a clowder.yaml in the versions directory"""
        self._validate_projects_exist()
        self._validate(self.get_all_group_names())
        versions_dir = os.path.join(self.root_directory, 'clowder', 'versions')
        version_name = version.replace('/', '-') # Replace path separateors with dashes
        version_dir = os.path.join(versions_dir, version_name)
        if not os.path.exists(version_dir):
            os.makedirs(version_dir)

        yaml_file = os.path.join(version_dir, 'clowder.yaml')
        yaml_file_output = colored(yaml_file, 'cyan')
        version_output = colored(version_name, attrs=['bold'])
        if not os.path.exists(yaml_file):
            with open(yaml_file, 'w') as file:
                print('Fixing version ' + version_output + ' at ' + yaml_file_output)
                yaml.dump(self._get_yaml(), file, default_flow_style=False)
        else:
            print('Version ' + version_output + ' already exists at ' + yaml_file_output)
            print_exiting()
Exemple #7
0
def exit_clowder_not_found():
    """Print clowder not found message and exit"""
    cprint('No clowder found in the current directory, exiting...\n', 'red')
    print_exiting()
Exemple #8
0
def exit_unrecognized_command(parser):
    """Print unrecognized command message and exit"""
    cprint('Unrecognized command\n', 'red')
    parser.print_help()
    print_exiting()
 def _validate(self):
     """Validate status of clowder repo"""
     if not validate_repo_state(self.clowder_path):
         print_validation(self.clowder_path)
         print_exiting()