Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import re
- import json
- import shutil
- import subprocess
- from pathlib import Path
- include_dirs = []
- # add all folders named 'include' to the included folders
- for path, sub_dirs, _ in os.walk(os.getcwd()):
- for folder in sub_dirs:
- if folder == "include":
- include_dirs.append(os.path.join(path, folder))
- # get includes from just this file (not recursively)
- def get_includes(file):
- file_as_str = ""
- with open(file, "r") as opened_file:
- for line in opened_file:
- file_as_str += line
- # remove comments
- file_as_str = re.sub(r"/\*.*?\*/", "", file_as_str, flags=re.DOTALL)
- file_as_str = re.sub(r"(/[^\n]*)\n", "", file_as_str)
- # get includes
- file_includes = re.findall(r'#include ?([<"][^>"]+[>"])', file_as_str)
- if file_includes is not None:
- file_includes = [string.replace('"', '') for string in file_includes]
- file_includes = [string.replace('<', '') for string in file_includes]
- file_includes = [string.replace('>', '.inc') for string in file_includes]
- return file_includes
- # check if the plugin has any include updated
- def has_updated_include(sp_file):
- files_to_parse = ["sourcemod.inc"]
- sp_file_includes = get_includes(sp_file)
- if sp_file_includes is not None:
- files_to_parse.extend(sp_file_includes)
- while files_to_parse:
- already_parsed = []
- includes_found = []
- for inc_file in files_to_parse:
- for inc_folder in include_dirs:
- inc_file_path = os.path.join(inc_folder, inc_file)
- if os.path.isfile(inc_file_path):
- includes_found = get_includes(inc_file_path)
- if includes_found is not None:
- sp_file_includes.extend(includes_found)
- break
- already_parsed.append(inc_file)
- files_to_parse = [x for x in files_to_parse if x not in already_parsed]
- if includes_found is not None:
- files_to_parse.extend(includes_found)
- return sp_file_includes
- value = has_updated_include("D:\\Documentos\\Sourcemod scripting\\scripting\\l4d2\\l4d2.sp")
- for i in value:
- print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement