YaNFBHXeMy602Znn

forge_extentions_list.py

Oct 2nd, 2025
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.77 KB | None | 0 0
  1. import os,re
  2.  
  3. """
  4. 指定したextensions内のフォルダから「.git\config」か「pyproject.toml」
  5. を探して、リポジトリやurlを抽出し「フォルダ名,url」をtxtに書きだす。
  6. """
  7.  
  8. #指定するextensionsディレクトリ
  9. path=r"G:\Program Files\StabilityMatrix-win-x64\Data\Packages\Stable Diffusion WebUI Forge\extensions"
  10. #書き出すtxtファイル名
  11. txt_file=r".\forge_extensions.txt"
  12. ####################################################################
  13. ###### 設定ここまで 以下はPython読み書きできない人は触らない######
  14. ####################################################################
  15. 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]
  16.  
  17. write_line=[]
  18. for root, dirs, files in os.walk(path):
  19.     if len(dirs):
  20.         for dir in dirs:
  21.             for i in node_list:
  22.                 if i == dir:
  23.                     d=os.path.join(root,dir)
  24.                     d=os.path.join(d,".git\config")
  25.                     #print(d)
  26.                     e=""
  27.                     if os.path.isfile(d):
  28.                         with open(d, mode='r') as f:
  29.                             line=[s.rstrip() for s in f.readlines()]
  30.                         for j in line:
  31.                             if re.search('\turl.*', j):
  32.                                 e=j
  33.                                 e=e.replace(r'url = ', '')
  34.                                 e=e.replace(r'"', '')
  35.                                 e=e.replace(r"'", '')
  36.                                 e=e.strip()
  37.                                 break
  38.                         write_line.append(f"{dir},{e}")
  39.                         print(f">Git:\t\t{dir}\t{e}")
  40.                         break
  41.                     else:
  42.                         d=os.path.join(root,dir)
  43.                         d=os.path.join(d,"pyproject.toml")
  44.                         if os.path.isfile(d):
  45.                             with open(d, mode='r') as f:
  46.                                 line=[s.rstrip() for s in f.readlines()]
  47.                             for j in line:
  48.                                 if re.search('Repository.*', j):
  49.                                     e=j
  50.                                     e=e.replace(r'Repository = ', '')
  51.                                     e=e.replace(r'"', '')
  52.                                     e=e.replace(r"'", '')
  53.                                     e=e.strip()
  54.                                     break
  55.                             write_line.append(f"{dir},{e}")
  56.                             print(f">pyproject:\t{dir}\t{e}")
  57.                             break
  58.  
  59. with open(txt_file, mode='w') as f:
  60.     for d in write_line:
  61.         f.write("%s\n" % d)
  62. print("end")
Advertisement
Add Comment
Please, Sign In to add comment