Exemplo n.º 1
0
def disable_network_connection() -> CompletedProcess:
    path = Path()
    from sys import platform
    if platform == "linux":
        result = cmd.run("ip link set eth0 down", path)
    elif platform == "darwin":
        result = cmd.run("networksetup -setairportpower airport off", path)
        sleep(1)
    elif platform == "win32":
        raise NotImplementedError
    else:
        raise NotImplementedError
    return result
Exemplo n.º 2
0
    def clone(cls, path: Path, url: str, depth: Optional[int] = None, branch: Optional[str] = None,
              tag: Optional[str] = None, jobs: Optional[int] = None, single_branch: bool = False,
              blobless: bool = False, treeless: bool = False, origin: Optional[str] = None) -> CompletedProcess:
        if path.is_dir():
            if fs.has_contents(path):
                raise Exception(f'Existing directory at clone path {path}')
            fs.remove_dir(path)

        args = ''
        if branch is not None:
            args += f' --branch {branch} '
        elif tag is not None:
            args += f' --branch {tag} '

        if single_branch:
            args += ' --single-branch '
        if jobs is not None:
            args += f' --jobs {jobs} '
        if depth is not None:
            args += f' --depth {depth} '
        if origin is not None:
            args += f' --origin {origin} '

        assert not (blobless and treeless)
        if blobless:
            args += ' --filter=blob:none '
        elif treeless:
            args += ' --filter=tree:0 '

        return cmd.run(f'git clone {args} {url} {path}')
Exemplo n.º 3
0
    def submodule_update(cls, path: Path, init: bool = False, depth: Optional[int] = None, single_branch: bool = False,
                         jobs: Optional[int] = None, recursive: bool = False, remote: bool = False,
                         no_fetch: bool = False, checkout: bool = False, rebase: bool = False, merge: bool = False,
                         paths: Optional[List[Path]] = None) -> CompletedProcess:
        args = ''
        if init:
            args += ' --init '
        if single_branch:
            args += ' --single-branch '
        if jobs is not None:
            args += f' --jobs {jobs} '
        if depth is not None:
            args += f' --depth {depth} '
        if recursive is not None:
            args += ' --recursive '
        if remote:
            args += ' --remote '
        if no_fetch:
            args += ' --no-fetch '

        # TODO: Validate that at most one of these is True
        if checkout:
            args += ' --checkout '
        if merge:
            args += ' --merge '
        if rebase:
            args += ' --rebase '

        if paths is not None and paths:
            paths = ' '.join([str(p) for p in paths])
        else:
            paths = ''
        return cmd.run(f'git submodule update {args} {paths}', cwd=path)
Exemplo n.º 4
0
    def pull(cls, path: Path, remote: Optional[str] = None, branch: Optional[str] = None,
             rebase: bool = False, prune: bool = False, tags: bool = False,
             jobs: Optional[int] = None, no_edit: bool = False, autostash: bool = False,
             depth: Optional[int] = None, fetch_all: bool = False) -> CompletedProcess:
        """Pull upstream changes"""

        refspec = None
        if branch is not None:
            remote = ORIGIN if remote is None else remote
            refspec = f'refs/heads/{branch}:refs/remotes/{remote}/heads/{branch}'

        remote = '' if remote is None else remote
        refspec = '' if refspec is None else refspec

        args = ''
        if rebase:
            args += ' --rebase '
        if prune:
            args += ' --prune '
        if tags:
            args += ' --tags '
        if no_edit:
            args += ' --no-edit '
        if autostash:
            args += ' --autostash '
        if jobs is not None:
            args += f' --jobs={jobs} '
        if depth is not None:
            args += f' --depth={depth} '
        if fetch_all:
            args += f' --all '
        return cmd.run(f'git pull {args} {remote} {refspec}', cwd=path)
Exemplo n.º 5
0
    def fetch(cls, path: Path, prune: bool = False, prune_tags: bool = False, tags: bool = False,
              depth: Optional[int] = None, remote: Optional[str] = None, branch: Optional[str] = None,
              unshallow: bool = False, jobs: Optional[int] = None, fetch_all: bool = False,
              print_output: bool = True) -> CompletedProcess:

        refspec = None
        if branch is not None:
            remote = ORIGIN if remote is None else remote
            refspec = f'refs/heads/{branch}:refs/remotes/{remote}/heads/{branch}'

        remote = '' if remote is None else remote
        refspec = '' if refspec is None else refspec

        args = ''
        if prune:
            args += ' --prune '
        if prune_tags:
            args += ' --prune-tags '
        if tags:
            args += ' --tags '
        if depth is not None:
            args += f' --depth {depth}'
        if unshallow:
            args += ' --unshallow '
        if jobs is not None:
            args += ' --jobs '
        if fetch_all:
            args += ' --all '

        return cmd.run(f"git fetch {args} {remote} {refspec}", cwd=path, print_output=print_output)
Exemplo n.º 6
0
 def delete_remote_branch(cls, path: Path, branch: str, remote: str = ORIGIN,
                          force: bool = False) -> CompletedProcess:
     refspec = f':refs/heads/{branch}'
     remote = ORIGIN if remote is None else remote
     args = ''
     if force:
         args += ' --force '
     return cmd.run(f'git push {remote} {args} {refspec}', cwd=path)
Exemplo n.º 7
0
 def delete_remote_tag(cls, path: Path, tag: str, remote: Optional[str] = None,
                       force: bool = False) -> CompletedProcess:
     refspec = f':refs/tags/{tag}'
     remote = ORIGIN if remote is None else remote
     args = ''
     if force:
         args += ' --force '
     return cmd.run(f'git push {remote} {args} {refspec}', cwd=path)
Exemplo n.º 8
0
def enable_network_connection(gateway_address: Optional[str]) -> [CompletedProcess]:
    path = Path()
    from sys import platform
    results = []
    if platform == "linux":
        result = cmd.run("ip link set eth0 up", path)
        results.append(result)
        if gateway_address is not None:
            result = cmd.run(f"route add default gw {gateway_address}", path)
            results.append(result)
    elif platform == "darwin":
        result = cmd.run("networksetup -setairportpower airport on", path, check=False)
        sleep(5)
    elif platform == "win32":
        raise NotImplementedError
    else:
        raise NotImplementedError
    return result
Exemplo n.º 9
0
def get_gateway_ip_address() -> Optional[str]:
    path = Path()
    from sys import platform
    if platform == "linux":
        result = cmd.run("netstat -nr | awk '{print $2}' | head -n3 | tail -n1", path)
        return result.stdout.strip()
    elif platform == "darwin":
        return None
    elif platform == "win32":
        raise NotImplementedError
    else:
        raise NotImplementedError
Exemplo n.º 10
0
    def push(cls, path: Path, remote: Optional[str] = None, local_branch: Optional[str] = None,
             remote_branch: Optional[str] = None, force: bool = False, set_upstream: bool = False) -> CompletedProcess:
        refspec = None
        if remote_branch is not None:
            remote = ORIGIN if remote is None else remote
            local_branch = HEAD if local_branch is None else local_branch
            refspec = f'refs/heads/{local_branch}:refs/heads/{remote_branch}'
        elif local_branch is not None:
            remote = ORIGIN if remote is None else remote
            remote_branch = local_branch
            refspec = f'refs/heads/{local_branch}:refs/heads/{remote_branch}'

        remote = '' if remote is None else remote
        refspec = '' if refspec is None else refspec

        args = ''
        if force:
            args += ' --force '
        if set_upstream:
            args += ' --set-upstream '

        return cmd.run(f'git push {args} {remote} {refspec}', cwd=path)
Exemplo n.º 11
0
    def pull_lfs(cls, path: Path) -> CompletedProcess:
        """Pull lfs files"""

        return cmd.run('git lfs pull', cwd=path)
Exemplo n.º 12
0
def unar(file: Path) -> None:
    # escaped_file_name = str(file).replace("'", r"\'")
    cmd.run(f'unar "{file}"', cwd=file.parent)