Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pubx
git-replace
提交
5b36aad1
G
git-replace
项目概览
pubx
/
git-replace
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
git-replace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5b36aad1
编写于
1月 26, 2023
作者:
P
prgrmz01@163.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
草稿replace_gitmodules_url.py ; processWordK注释及加强
上级
9ebe7c74
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
65 addition
and
3 deletion
+65
-3
replace_gitmodules_url.py
replace_gitmodules_url.py
+50
-0
replace_url.py
replace_url.py
+13
-2
repo_map.py
repo_map.py
+2
-1
未找到文件。
replace_gitmodules_url.py
0 → 100644
浏览文件 @
5b36aad1
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
sys
from
typing
import
List
,
Dict
from
datetime
import
datetime
from
replace_url
import
processWordK
"""
cd /mnt/d/tmp/
git clone https://github.com/frida/libpsl.git
cat libpsl/.gitmodules
'''[submodule "list"]
path = list
url = https://github.com/publicsuffix/list
'''
python /pubx/git-replace/replace_gitmodules_url.py /mnt/d/tmp/libpsl/.gitmodules
cat libpsl/.gitmodules
'''[submodule "list"]
path = list
url = git@gitcode.net:dependency/frida/list.git
'''
"""
from
repo_map
import
repo_url_map
#https://docs.python.org/3/library/configparser.html
import
configparser
logF
=
open
(
"/tmp/git.log"
,
"a"
)
now
:
str
=
datetime
.
now
().
strftime
(
'%Y-%m-%d %H:%M:%S'
)
logF
.
write
(
f
"
{
now
}
:
{
sys
.
argv
}
\n
"
)
gitmodulesPath
=
sys
.
argv
[
1
]
gitmodulesText
:
str
=
None
config
=
configparser
.
ConfigParser
()
submoduleNames
:
List
[
str
,
Dict
[
str
,
str
]]
=
config
.
read
(
gitmodulesPath
)
for
submoduleNameK
in
submoduleNames
:
newUrl
:
str
=
processWordK
(
config
[
submoduleNameK
][
'url'
])
if
not
newUrl
.
__contains__
(
"github.com"
):
logF
.
write
(
f
"
{
now
}
:
{
config
[
submoduleNameK
][
'url'
]
}
--->
{
newUrl
}
\n
"
)
config
[
submoduleNameK
][
'url'
]
=
newUrl
with
open
(
gitmodulesPath
,
"w"
)
as
configfile
:
config
.
write
(
configfile
)
logF
.
close
()
\ No newline at end of file
replace_url.py
浏览文件 @
5b36aad1
...
...
@@ -14,17 +14,28 @@ from datetime import datetime
from
repo_map
import
repo_url_map
def
processWordK
(
wordK
:
str
)
->
str
:
#存备份
wordKOriginal
:
str
=
wordK
#去掉行尾换行符
if
wordK
.
endswith
(
"
\r\n
"
):
wordK
=
wordK
[:
-
2
]
if
wordK
.
endswith
(
"
\n
"
):
wordK
=
wordK
[:
-
1
]
#若以https://github.com开头, 则认为是一个仓库地址.
if
wordK
.
startswith
(
"https://github.com"
):
# 若key不以.git结尾, 则添加.git后缀
wordK
=
wordK
if
wordK
.
endswith
(
".git"
)
else
f
"
{
wordK
}
.git"
# 查表 并返回表中给出的 git仓库地址
if
repo_url_map
.
__contains__
(
wordK
):
return
repo_url_map
.
__getitem__
(
wordK
)
#若表中key没有此地址, 则原样返回
else
:
return
wordK
return
wordKOriginal
#若不以https://github.com开头, 则认为不是一个仓库地址 , 故原样返回
else
:
return
wordK
return
wordK
Original
logF
=
open
(
"/tmp/git.log"
,
"a"
)
...
...
repo_map.py
浏览文件 @
5b36aad1
...
...
@@ -2,7 +2,8 @@
# -*- coding: utf-8 -*-
from
typing
import
Dict
#此表的key均以.git后缀;
# 即使待替换目标不以.git结尾, 查表者也会对key增加.git结尾 再查表.
repo_url_map
:
Dict
[
str
,
str
]
=
{
"https://github.com/frida/pcre2.git"
:
"git@gitcode.net:dependency/frida/pcre2.git"
,
"https://github.com/frida/glib.git"
:
"git@gitcode.net:dependency/frida/glib.git"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录