misdocumeno

Untitled

Oct 11th, 2020
942
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import re
  3. import json
  4. import shutil
  5. import subprocess
  6. from pathlib import Path
  7.  
  8. include_dirs = []
  9.  
  10. # add all folders named 'include' to the included folders
  11. for path, sub_dirs, _ in os.walk(os.getcwd()):
  12.     for folder in sub_dirs:
  13.         if folder == "include":
  14.             include_dirs.append(os.path.join(path, folder))
  15.  
  16. # get includes from just this file (not recursively)
  17. def get_includes(file):
  18.     file_as_str = ""
  19.     with open(file, "r") as opened_file:
  20.         for line in opened_file:
  21.             file_as_str += line
  22.    
  23.     # remove comments
  24.     file_as_str = re.sub(r"/\*.*?\*/", "", file_as_str, flags=re.DOTALL)
  25.     file_as_str = re.sub(r"(/[^\n]*)\n", "", file_as_str)
  26.  
  27.     # get includes
  28.     file_includes = re.findall(r'#include ?([<"][^>"]+[>"])', file_as_str)
  29.  
  30.     if file_includes is not None:
  31.         file_includes = [string.replace('"', '') for string in file_includes]
  32.         file_includes = [string.replace('<', '') for string in file_includes]
  33.         file_includes = [string.replace('>', '.inc') for string in file_includes]
  34.  
  35.     return file_includes
  36.  
  37. # check if the plugin has any include updated
  38. def has_updated_include(sp_file):
  39.  
  40.     files_to_parse = ["sourcemod.inc"]
  41.  
  42.     sp_file_includes = get_includes(sp_file)
  43.  
  44.     if sp_file_includes is not None:
  45.         files_to_parse.extend(sp_file_includes)
  46.    
  47.     while files_to_parse:
  48.  
  49.         already_parsed = []
  50.         includes_found = []
  51.  
  52.         for inc_file in files_to_parse:
  53.            
  54.             for inc_folder in include_dirs:
  55.  
  56.                 inc_file_path = os.path.join(inc_folder, inc_file)
  57.  
  58.                 if os.path.isfile(inc_file_path):
  59.                     includes_found = get_includes(inc_file_path)
  60.                     if includes_found is not None:
  61.                         sp_file_includes.extend(includes_found)
  62.                     break
  63.  
  64.             already_parsed.append(inc_file)
  65.  
  66.         files_to_parse = [x for x in files_to_parse if x not in already_parsed]
  67.         if includes_found is not None:
  68.             files_to_parse.extend(includes_found)
  69.  
  70.     return sp_file_includes
  71.  
  72. value = has_updated_include("D:\\Documentos\\Sourcemod scripting\\scripting\\l4d2\\l4d2.sp")
  73. for i in value:
  74.     print(i)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×