Skip to content

Commit

Permalink
多线程优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gfdgd-xi committed Sep 17, 2024
1 parent 652bd27 commit bee6e74
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ on:
workflow_call:
workflow_dispatch:
schedule:
- cron: "0 * * * *"
- cron: "0 0 * * *"
- cron: "0 10 * * *"
- cron: "0 20 * * *"

jobs:
sync:
Expand Down
35 changes: 22 additions & 13 deletions sync-gitee-to-github/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sys
import requests
import threading

programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
dataHeaders = {
Expand Down Expand Up @@ -30,19 +31,8 @@
if (i % 2 == 0):
password.append(sys.argv[i])



data = requests.get("https://github.com/orgs/GXDE-OS/repos_list?q=&page=1", headers=dataHeaders).json()
# 获取页数
page = int(data["pageCount"])
repoList = []
# 获取仓库列表
for i in range(1, page + 1):
pageData = requests.get(f"https://github.com/orgs/GXDE-OS/repos_list?q=&page={i}", headers=dataHeaders).json()
repositories = pageData["repositories"]
for j in repositories:
repoList.append(j["name"])
for i in repoList:
def sync(i):
global thread
# 拉取代码进行同步
if (not os.path.exists(f"{programPath}/git-clone")):
os.makedirs(f"{programPath}/git-clone")
Expand All @@ -56,4 +46,23 @@
os.system(f"cd '{programPath}/git-clone/{i}.git' ; git push --mirror")
# 移除临时文件
os.system(f"rm -rf '{programPath}/git-clone/{i}.git'")
thread -= 1

data = requests.get("https://github.com/orgs/GXDE-OS/repos_list?q=&page=1", headers=dataHeaders).json()
# 获取页数
page = int(data["pageCount"])
repoList = []
# 获取仓库列表
for i in range(1, page + 1):
pageData = requests.get(f"https://github.com/orgs/GXDE-OS/repos_list?q=&page={i}", headers=dataHeaders).json()
repositories = pageData["repositories"]
for j in repositories:
repoList.append(j["name"])
# 多线程处理以提升速度
thread = 0
threadMax = 8
for i in repoList:
if (thread < threadMax):
threading.Thread(target=sync, args=[i]).start()
thread += 1

0 comments on commit bee6e74

Please sign in to comment.