コード例 #1
0
ファイル: __init__.py プロジェクト: maltebaumann/polyaxon
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
ファイル: projects.py プロジェクト: yu-iskw/polyaxon
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
ファイル: tasks.py プロジェクト: mouradmourafiq/polyaxon
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
ファイル: projects.py プロジェクト: yutiansut/polyaxon
def delete_project_repos(project_name: str) -> None:
    path = get_project_repos_path(project_name)
    delete_path(path)