Guest User

Update loggers names and remove old imports

a guest
May 3rd, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. # Update s_loggers' names and remove old imports
  2.  
  3. for root, subdirs, files in os.walk(walk_dir):
  4.     for filename in files:
  5.         if not filename.endswith('.java'):
  6.             continue
  7.  
  8.         file_path = os.path.join(root, filename)
  9.         print("Processing \t" + filename)
  10.  
  11.         with open(file_path) as file:
  12.             subprocess.run("sed -i '/import org.apache.log4j.Logger/d' {}".format(file_path), shell=True)
  13.             subprocess.run("sed -i 's/s_logger/logger/g' {}".format(file_path), shell=True)
  14.  
  15.  
  16. # Update static loggers' names
  17.  
  18. for root, subdirs, files in os.walk(walk_dir):
  19.     for filename in files:
  20.         if not filename.endswith('.java'):
  21.             continue
  22.  
  23.         file_path = os.path.join(root, filename)
  24.         print("Processing \t" + filename)
  25.  
  26.         with open(file_path) as file:
  27.             file_content = file.read()
  28.             if "static Logger logger" in file_content:
  29.                 subprocess.run("sed -i 's/logger/LOGGER/g' {}".format(file_path), shell=True)
  30.             if "private static final Logger logger" in file_content:
  31.                 subprocess.run("sed -i 's/private static final Logger logger/protected static Logger LOGGER/g' {}"
  32.                                .format(file_path), shell=True)
  33.                 subprocess.run("sed -i 's/logger/LOGGER/g' {}".format(file_path), shell=True)
Advertisement
Add Comment
Please, Sign In to add comment