Last active
July 16, 2020 05:21
-
-
Save pinedance/e5a4047db89ce87511e267dc1f5130d2 to your computer and use it in GitHub Desktop.
Script to batch register git sub moudles of INI data type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to batch register git sub moudles of INI data type | |
# Usage : python add_modules.py YOUR_SUBMODULEFILE | |
# Do not name the YOUR_SUBMODULEFILE ".gitmodules". or There will be a duplicate problem inside ".gitmodules". | |
import sys | |
import configparser | |
import subprocess | |
CONFIG_FILE = sys.argv[1].strip() | |
EXCUTE = "git submodule add \"{}\" \"{}\" -b \"{}\" --depth 1 || true" | |
# The structure of INI files | |
config = configparser.ConfigParser() | |
config.read( CONFIG_FILE, encoding="utf-8" ) | |
submodules_list = [] | |
for sc in config.sections(): | |
module = config[sc] | |
submodules_list.append( ( module["url"], module["path"], module.get("branch", "master") ) ) | |
for module in submodules_list: | |
print( excute ) | |
excute = EXCUTE.format( *module ) | |
subprocess.call( excute ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[submodule "KR3a0001"] | |
path = KR3_子部/KR3a_儒家類/KR3a0001_孔子家語-魏-王肅 | |
url = https://github.com/kanripo/KR3a0001.git | |
branch = master | |
[submodule "KR3a0002"] | |
path = KR3_子部/KR3a_儒家類/KR3a0002_荀子-周-荀況 | |
url = https://github.com/kanripo/KR3a0002.git | |
branch = master | |
[submodule "KR3a0003"] | |
path = KR3_子部/KR3a_儒家類/KR3a0003_孔叢子-漢-孔鮒 | |
url = https://github.com/kanripo/KR3a0003.git | |
branch = master | |
[submodule "KR3a0004"] | |
path = KR3_子部/KR3a_儒家類/KR3a0004_新語-漢-陸賈 | |
url = https://github.com/kanripo/KR3a0004.git | |
branch = master | |
[submodule "KR3a0005"] | |
path = KR3_子部/KR3a_儒家類/KR3a0005_新書-漢-賈誼 | |
url = https://github.com/kanripo/KR3a0005.git | |
branch = master | |
[submodule "KR3a0006"] | |
path = KR3_子部/KR3a_儒家類/KR3a0006_鹽鐵論-漢-桓寬 | |
url = https://github.com/kanripo/KR3a0006.git | |
branch = master | |
[submodule "KR3a0007"] | |
path = KR3_子部/KR3a_儒家類/KR3a0007_說苑-漢-劉向 | |
url = https://github.com/kanripo/KR3a0007.git | |
branch = master | |
[submodule "KR3a0008"] | |
path = KR3_子部/KR3a_儒家類/KR3a0008_新序-漢-劉向 | |
url = https://github.com/kanripo/KR3a0008.git | |
branch = master | |
[submodule "KR3a0009"] | |
path = KR3_子部/KR3a_儒家類/KR3a0009_揚子法言-漢-揚雄 | |
url = https://github.com/kanripo/KR3a0009.git | |
branch = master | |
[submodule "KR3a0010"] | |
path = KR3_子部/KR3a_儒家類/KR3a0010_潛夫論-漢-王符 | |
url = https://github.com/kanripo/KR3a0010.git | |
branch = master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment