Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os,re
- """
- 指定したextensions内のフォルダから「.git\config」か「pyproject.toml」
- を探して、リポジトリやurlを抽出し「フォルダ名,url」をtxtに書きだす。
- """
- #指定するextensionsディレクトリ
- path=r"G:\Program Files\StabilityMatrix-win-x64\Data\Packages\Stable Diffusion WebUI Forge\extensions"
- #書き出すtxtファイル名
- txt_file=r".\forge_extensions.txt"
- ####################################################################
- ###### 設定ここまで 以下はPython読み書きできない人は触らない######
- ####################################################################
- node_list = [f for f in os.listdir(path) if os.path.isdir(os.path.join(path, f)) and os.path.join(path, f).find('__pycache__')==-1]
- write_line=[]
- for root, dirs, files in os.walk(path):
- if len(dirs):
- for dir in dirs:
- for i in node_list:
- if i == dir:
- d=os.path.join(root,dir)
- d=os.path.join(d,".git\config")
- #print(d)
- e=""
- if os.path.isfile(d):
- with open(d, mode='r') as f:
- line=[s.rstrip() for s in f.readlines()]
- for j in line:
- if re.search('\turl.*', j):
- e=j
- e=e.replace(r'url = ', '')
- e=e.replace(r'"', '')
- e=e.replace(r"'", '')
- e=e.strip()
- break
- write_line.append(f"{dir},{e}")
- print(f">Git:\t\t{dir}\t{e}")
- break
- else:
- d=os.path.join(root,dir)
- d=os.path.join(d,"pyproject.toml")
- if os.path.isfile(d):
- with open(d, mode='r') as f:
- line=[s.rstrip() for s in f.readlines()]
- for j in line:
- if re.search('Repository.*', j):
- e=j
- e=e.replace(r'Repository = ', '')
- e=e.replace(r'"', '')
- e=e.replace(r"'", '')
- e=e.strip()
- break
- write_line.append(f"{dir},{e}")
- print(f">pyproject:\t{dir}\t{e}")
- break
- with open(txt_file, mode='w') as f:
- for d in write_line:
- f.write("%s\n" % d)
- print("end")
Advertisement
Add Comment
Please, Sign In to add comment