Fix psm append not working
This commit is contained in:
+5
-4
@@ -1,3 +1,4 @@
|
|||||||
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@@ -163,16 +164,16 @@ def define_variables(items: list[str]) -> str:
|
|||||||
def define_strings(items: list[str]) -> str:
|
def define_strings(items: list[str]) -> str:
|
||||||
return "\n".join(["\t" + "[string]$" + "{" + sanitize_name(item) + "}" for item in items])
|
return "\n".join(["\t" + "[string]$" + "{" + sanitize_name(item) + "}" for item in items])
|
||||||
|
|
||||||
def write_psm(name, items: list[str], filename: Path = Path("Connector.psm1")) -> str:
|
|
||||||
from rich import print
|
|
||||||
|
|
||||||
|
def write_psm(name, items: list[str], filename: Path = Path("Connector.psm1")) -> str:
|
||||||
if filename.exists():
|
if filename.exists():
|
||||||
filename.rename(str(filename) + f".{datetime.now().strftime('%Y-%m-%d.%H%M%S')}.bak")
|
backup_filename = str(filename) + f".{datetime.now().strftime('%Y-%m-%d.%H%M%S')}.bak"
|
||||||
|
shutil.copy2(filename, backup_filename)
|
||||||
|
|
||||||
output = get_all_code.replace("!NAME!", name)
|
output = get_all_code.replace("!NAME!", name)
|
||||||
output += get_code.replace("!NAME!", name)
|
output += get_code.replace("!NAME!", name)
|
||||||
output += convert_from.replace("!NAME!", name).replace("!MAPS!", define_maps(items))
|
output += convert_from.replace("!NAME!", name).replace("!MAPS!", define_maps(items))
|
||||||
output += class_definition.replace("!NAME!", name).replace("!VARIABLES!", define_variables(items)).replace("!STRINGS!", define_strings(items))
|
output += class_definition.replace("!NAME!", name).replace("!VARIABLES!", define_variables(items)).replace("!STRINGS!", define_strings(items))
|
||||||
with open(filename, "a") as f:
|
with open(filename, "a") as f:
|
||||||
f.write(output)
|
f.write(output)
|
||||||
print(output)
|
|
||||||
pass
|
pass
|
||||||
Reference in New Issue
Block a user