Exemple #1
0
def checkout_worktree(repo_name,
                      repo_dir,
                      worktree_dir,
                      branch,
                      new_branch,
                      force=False):
    print('Checking out worktree for project {!r} into {!r} '
          '(branch {})'.format(repo_name, worktree_dir, branch))
    try:
        args = ["worktree", "add"]
        if force:
            args += ["-f", "-f"]
        args += [worktree_dir, branch]
        if new_branch:
            args += ["-b", new_branch]
        git(*args, repository_path=repo_dir)
    except subprocess.CalledProcessError as e:
        out = getattr(e, "output", b"").decode()
        print("\nCould not checkout worktree %s, please fix and try again."
              " Error:\n\n%s %s" % (repo_dir, out, e))

        return False

    commit_message = git("show",
                         "--format=medium",
                         "--shortstat",
                         repository_path=repo_dir).split("\n")
    print(u"  -> %s%s%s - %s" %
          (Colors.HEADER, repo_dir, Colors.ENDC, commit_message[4].strip()))
    return True
Exemple #2
0
def remove_worktree(worktree_dir):
    worktree_subdir = os.path.join(worktree_dir, "subprojects")

    for repo_name, _, parent_repo_dir in get_wrap_subprojects(
            worktree_dir, None):
        workdir = os.path.normpath(os.path.join(worktree_subdir, repo_name))
        if not os.path.exists(workdir):
            continue

        subprojdir = os.path.normpath(os.path.join(SUBPROJECTS_DIR, repo_name))
        if not os.path.exists(subprojdir):
            continue

        print('Removing worktree {!r}'.format(workdir))
        try:
            git('worktree',
                'remove',
                '-f',
                workdir,
                repository_path=subprojdir)
        except subprocess.CalledProcessError as e:
            out = getattr(e, "output", b"").decode()
            print('Ignoring error while removing worktree {!r}:\n\n{}'.format(
                workdir, out))

    try:
        git('worktree',
            'remove',
            '-f',
            worktree_dir,
            repository_path=SCRIPTDIR)
    except subprocess.CalledProcessError:
        print('Failed to remove worktree {!r}'.format(worktree_dir))
        return False
    return True
Exemple #3
0
def repo_has_branch(repo_dir, branch):
    if not branch:
        return False
    try:
        git("describe", branch, repository_path=repo_dir)
    except subprocess.CalledProcessError:
        return False
    return True
Exemple #4
0
    def setup(self, args):
        if not os.path.exists(self.options.msys2_path):
            print(
                "msys2 not found in %s. Please make sure to install"
                " (from http://msys2.github.io/) specify --msys2-path"
                " if you did not install in the default directory.",
                flush=True)
            return False

        for path in ['mingw64/bin', 'bin', 'usr/bin']:
            os.environ['PATH'] = os.environ.get(
                'PATH', '') + os.pathsep + os.path.normpath(
                    os.path.join(self.options.msys2_path, path))
        os.environ['PATH'] = os.environ['PATH'].replace(';;', ';')
        os.environ['PKG_CONFIG_PATH'] = os.environ.get(
            'PKG_CONFIG_PATH',
            '') + ':/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig'

        subprocess.check_call(['pacman', '-S', '--needed', '--noconfirm'] +
                              self.DEPENDENCIES)
        source_path = os.path.abspath(os.path.curdir)

        print('Making sure meson is present in root folder... ',
              end='',
              flush=True)
        if not os.path.isdir(os.path.join(source_path, 'meson')):
            print('\nCloning meson', flush=True)
            git('clone', self.MESON_GIT, repository_path=source_path)
        else:
            print('\nDONE', flush=True)

        print("Making libs", flush=True)
        self.make_libs()
        print("Done making .lib files.", flush=True)
        if not os.path.exists(os.path.join(source_path, 'build', 'build.ninja')) or \
                self.options.reconfigure:
            print("Running meson", flush=True)
            if not self.configure_meson():
                return False

        try:
            if not args:
                print("Getting into msys2 environment", flush=True)
                subprocess.check_call([
                    sys.executable,
                    os.path.join(source_path, 'gst-uninstalled.py'),
                    '--builddir',
                    os.path.join(source_path, 'build')
                ])
            else:
                print("Running %s" ' '.join(args), flush=True)
                res = subprocess.check_call(args)
        except subprocess.CalledProcessError as e:
            return False

        return True
Exemple #5
0
    options, args = parser.parse_known_args()

    if not os.path.exists(options.builddir):
        print("GStreamer not built in %s\n\nBuild it and try again" %
              options.builddir)
        exit(1)
    options.builddir = os.path.abspath(options.builddir)

    if not os.path.exists(options.srcdir):
        print("The specified source dir does not exist" % options.srcdir)
        exit(1)

    # The following incantation will retrieve the current branch name.
    gst_version = git("rev-parse",
                      "--symbolic-full-name",
                      "--abbrev-ref",
                      "HEAD",
                      repository_path=options.srcdir).strip('\n')

    if not args:
        if os.name is 'nt':
            shell = get_windows_shell()
            if shell == 'powershell.exe':
                args = ['powershell.exe']
                args += ['-NoLogo', '-NoExit']
                prompt = 'function global:prompt {  "[gst-' + gst_version + '"+"] PS " + $PWD + "> "}'
                args += ['-Command', prompt]
            else:
                args = [
                    os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")
                ]