提交 5b36aad1 编写于 作者: P prgrmz01@163.com

草稿replace_gitmodules_url.py ; processWordK注释及加强

上级 9ebe7c74
#!/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
......@@ -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 wordKOriginal
logF= open("/tmp/git.log","a")
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册