试图用子进程模块克隆Gitlab repo的列表

发布于 2025-02-13 09:56:55 字数 1410 浏览 1 评论 0原文

我正在尝试从我的GitLab服务器中克服大量的GitLab存储库列表。但是,我很难让子进程模块工作。我已经尝试了这个问题的答案,但对我不起作用。

repo_list = [list_with_all_repository_names]

    for repo_name in repo_list:
        repo_url = f'https://url_to_my_gitlab_server/{repo_name}.git'
        p = subprocess.run(["C:/Users/my_user_name/AppData/Local/Programs/Git/git-bash.exe",
                            "C:/Users/my_user_name/Documents/Gitlab Repos/git-clone-shell.sh",
                            f"git clone {repo_name}"],
                         bufsize=-1,
                         executable=None,
                         stdin=None,
                         stdout=None,
                         stderr=None,
                         preexec_fn=None,
                         close_fds=False,
                         shell=False,
                         cwd="C:/Users/my_user_name/Documents/Gitlab Repos")
        time.sleep(20)

> f“ git clone {repo_name}” subprocess.run 调用,因此它的内容不超过$ 1

git bash opens opens opens立即崩溃,我不知道为什么。我还试图在没有外壳脚本的情况下直接在bash中直接运行命令,但是这只是打开git bash,什么也不做:

p = subprocess.run(
    [f'git clone {repo_url}'],
    bufsize=-1,
    executable='C:/Users/my_user_name/AppData/Local/Programs/Git/git-bash.exe',
    capture_output=True,
    cwd="C:/Users/my_user_name/Documents/Gitlab Repos"
)

我感觉自己接近解决方案,但我不明白它的问题在哪里。

I'm trying to clone a big list of GitLab repositories from my GitLab Server. However, I'm having trouble getting the subprocess module to work. I've tried the answer to this question but it won't work for me. Open Git Bash shell using a python script and then run a shell script in git bash shell

Here is my code:

repo_list = [list_with_all_repository_names]

    for repo_name in repo_list:
        repo_url = f'https://url_to_my_gitlab_server/{repo_name}.git'
        p = subprocess.run(["C:/Users/my_user_name/AppData/Local/Programs/Git/git-bash.exe",
                            "C:/Users/my_user_name/Documents/Gitlab Repos/git-clone-shell.sh",
                            f"git clone {repo_name}"],
                         bufsize=-1,
                         executable=None,
                         stdin=None,
                         stdout=None,
                         stderr=None,
                         preexec_fn=None,
                         close_fds=False,
                         shell=False,
                         cwd="C:/Users/my_user_name/Documents/Gitlab Repos")
        time.sleep(20)

My shell script is simply a placeholder for the f"git clone {repo_name}" argument in the subprocess.run call, and therefore it's contents are no more than $1

Git bash opens but immediatly crashes and I don't know why. I've also tried to run the command directly in bash without a shell script, but this simply opens git bash and does nothing:

p = subprocess.run(
    [f'git clone {repo_url}'],
    bufsize=-1,
    executable='C:/Users/my_user_name/AppData/Local/Programs/Git/git-bash.exe',
    capture_output=True,
    cwd="C:/Users/my_user_name/Documents/Gitlab Repos"
)

I have the feeling that I'm close to a solution but I don't understand where it's going wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾听心声的旋律 2025-02-20 09:56:55

我通过在WSL环境中运行脚本来解决问题,并具有以下子过程设置:

for repo_name in repo_list:
    repo_url = f'url_to_gitlab_server/{repo_name}.git'
    p = subprocess.run(["git", "clone", f"{repo_url}"],
                     bufsize=-1,
                     stdin=None,
                     stdout=None,
                     stderr=None,
                     shell=False)
    print(p)

I've solved the problem by running the script in a WSL-environment, with the following subprocess setting:

for repo_name in repo_list:
    repo_url = f'url_to_gitlab_server/{repo_name}.git'
    p = subprocess.run(["git", "clone", f"{repo_url}"],
                     bufsize=-1,
                     stdin=None,
                     stdout=None,
                     stderr=None,
                     shell=False)
    print(p)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文