Added FindValueFromFile
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
|
||||
import os
|
||||
|
||||
class Text:
|
||||
|
||||
@@ -42,12 +42,61 @@ class String:
|
||||
def string(STRING):
|
||||
return STRING,
|
||||
|
||||
class FindValueFromFile:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
|
||||
return {"required": {
|
||||
"key": ("STRING", {"default": '', "multiline": False}),
|
||||
"input_path": ("STRING", {"default": '', "multiline": False})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING", "BOOLEAN")
|
||||
RETURN_NAMES = ("Value STRING", "Value received BOOL")
|
||||
|
||||
FUNCTION = "find_value_from_file"
|
||||
CATEGORY = "LevelPixel/IO"
|
||||
|
||||
def find_value_from_file(self, key, input_path=None):
|
||||
valueString = ""
|
||||
boolResult = True
|
||||
log = []
|
||||
log.append("")
|
||||
try:
|
||||
with open(os.path.normpath(input_path), 'r', encoding='utf-8') as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
|
||||
if "-->" in line:
|
||||
keyLine, valueLine = line.split("-->", 1)
|
||||
if keyLine.strip() == key:
|
||||
valueString = valueLine.strip()
|
||||
break
|
||||
except FileNotFoundError:
|
||||
log[0] = log[0] + f"Error: File not found at {input_path}"
|
||||
boolResult = False
|
||||
except Exception as e:
|
||||
log[0] = log[0] + f"Error: {e}"
|
||||
boolResult = False
|
||||
|
||||
if valueString == "":
|
||||
boolResult = False
|
||||
|
||||
return {"ui": {"text": valueString, "log": log,}, "result": (valueString, boolResult,)}
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"Text|LP": Text,
|
||||
"String|LP": String,
|
||||
"FindValueFromFile|LP": FindValueFromFile,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"Text|LP": "Text [LP]",
|
||||
"String|LP": "String [LP]",
|
||||
"FindValueFromFile|LP": "Find Value From File [LP]",
|
||||
}
|
||||
Reference in New Issue
Block a user