예제 #1
0
def fetch(git_url: str,
          repo_path: str,
          overwrite: bool = False,
          branch='master') -> Optional[Any]:
    branch = branch or 'master'
    if os.path.isdir(repo_path):
        _logger.info('Current checkout path has content.')
        if overwrite:
            _logger.info('Overwriting current checkout path.')
            delete_path(repo_path)
        else:
            run_command(cmd='git fetch origin {}'.format(branch),
                        data=None,
                        location=repo_path,
                        chw=True)
            checkout_commit(repo_path=repo_path, commit=branch)
            run_command(cmd='git fetch origin {}'.format(branch),
                        data=None,
                        location=repo_path,
                        chw=True)
            run_command(cmd='git reset --hard FETCH_HEAD',
                        data=None,
                        location=repo_path,
                        chw=True)
            run_command(cmd='git clean -df',
                        data=None,
                        location=repo_path,
                        chw=True)
            return None
    return clone_git_repo(repo_path=repo_path, git_url=git_url)
예제 #2
0
def repo_deleted(sender, **kwargs):
    if kwargs.get('raw'):
        # Ignore signal handling for fixture loading
        return

    instance = kwargs['instance']

    # Clean repo
    delete_path(instance.path)
예제 #3
0
def handle_new_files(user_id, repo_id, tar_file_name):
    if not tarfile.is_tarfile(tar_file_name):
        raise ValueError('Received wrong file format.')

    User = get_user_model()  # noqa
    try:
        user = User.objects.get(id=user_id)
    except User.DoesNotExist:
        _logger.warning('User with id `%s` does not exist anymore.', user_id)
        return

    try:
        repo = Repo.objects.get(id=repo_id)
        # Checkout to master
        git.checkout_commit(repo.path)
    except User.DoesNotExist:
        _logger.warning('Repo with id `%s` does not exist anymore.', repo_id)
        return

    # Destination files
    new_repo_path = repo.get_tmp_tar_path()

    # clean the current path from all files
    path_files = os.listdir(repo.path)
    for member in path_files:
        if member == '.git':
            continue
        member = os.path.join(repo.path, member)
        if os.path.isfile(member):
            os.remove(member)
        else:
            delete_path(member)

    # Move the tar inside the repo path
    shutil.move(tar_file_name, new_repo_path)

    # Untar the file
    with tarfile.open(new_repo_path) as tar:
        tar.extractall(repo.path)

    # Delete the current tar
    os.remove(new_repo_path)

    # Get the git repo
    if not git.get_status(repo.path):
        return

    # commit changes
    git.commit(repo.path, user.email, user.username)
    auditor.record(event_type=REPO_NEW_COMMIT,
                   instance=repo,
                   actor_id=user.id,
                   actor_name=user.username)
예제 #4
0
파일: base.py 프로젝트: yutiansut/polyaxon
 def delete_path(self, subpath: str, ref: str):
     path = self.get_path(ref=ref)
     path = os.path.join(path, subpath)
     delete_path(path)
예제 #5
0
파일: service.py 프로젝트: yu-iskw/polyaxon
 def delete_data_path(cls, subpath, persistence):
     data_path = cls.get_data_path(persistence=persistence)
     path = os.path.join(data_path, subpath)
     delete_path(path)
예제 #6
0
 def clean(self) -> None:
     # Clean dockerfile
     delete_path(self.dockerfile_path)
예제 #7
0
def delete_project_repos(project_name: str) -> None:
    path = get_project_repos_path(project_name)
    delete_path(path)