mirror of
https://github.com/hubHarmony/servii-backend.git
synced 2024-11-17 21:40:31 +00:00
47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
|
import os
|
||
|
import shutil
|
||
|
import re
|
||
|
|
||
|
def create_folder(path):
|
||
|
os.makedirs(path, exist_ok=True)
|
||
|
|
||
|
def check_if_exists(path):
|
||
|
return os.path.exists(path)
|
||
|
|
||
|
def delete_non_empty_folder(path):
|
||
|
shutil.rmtree(path)
|
||
|
|
||
|
def copy_folder_contents(source_dir, destination_dir):
|
||
|
if not os.path.exists(destination_dir):
|
||
|
os.makedirs(destination_dir)
|
||
|
for item_name in os.listdir(source_dir):
|
||
|
source_path = os.path.join(source_dir, item_name)
|
||
|
destination_path = os.path.join(destination_dir, item_name)
|
||
|
if os.path.isfile(source_path):
|
||
|
shutil.copy2(source_path, destination_path)
|
||
|
elif os.path.isdir(source_path):
|
||
|
if os.path.exists(destination_path):
|
||
|
for filename in os.listdir(source_path):
|
||
|
file_source_path = os.path.join(source_path, filename)
|
||
|
file_destination_path = os.path.join(destination_path, filename)
|
||
|
if not os.path.exists(file_destination_path):
|
||
|
shutil.copy2(file_source_path, file_destination_path)
|
||
|
else:
|
||
|
shutil.copytree(source_path, destination_path)
|
||
|
|
||
|
def update_server_property(file_path, property_name, new_value):
|
||
|
pattern = rf'^{property_name}=.*$'
|
||
|
with open(file_path, 'r') as file:
|
||
|
content = file.readlines()
|
||
|
for i, line in enumerate(content):
|
||
|
if re.match(pattern, line):
|
||
|
content[i] = f"{property_name}={new_value}\n"
|
||
|
break
|
||
|
else:
|
||
|
raise ValueError(f"Property '{property_name}' not found in the file.")
|
||
|
with open(file_path, 'w') as file:
|
||
|
file.writelines(content)
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
pass
|