@SolarPH said in Python NODES - Shouldn't really they can change the scene?:
Edit: One thing though, this code kinda has it's own holes, because I encountered a problem ...
I never said that it is perfect, I just implemented, what I thought you were after. If you want to find all file paths where the file name matches the file name part of a given preset URL, you could use os.walk. Something like this:
def find_preset_url_candidates(url):
"""Find all OS file paths for which the file name matches the file name
of a given MAXON preset url.
Args:
url (str): The url in the MAXON 'preset' scheme to resolve.
Returns:
list[str]: The resolved preset paths.
Raises:
ValueError: When the argument preset_url is not a valid preset url.
"""
# Half-heartedly sort out some malformed preset urls.
url = str(url)
if (not url.startswith("preset://") or
not url.endswith(".lib4d")):
msg = r"Not a preset url: {}."
raise ValueError(msg.format(url))
# Split the url into the scheme-path and filename-extension parts
_, preset_file = os.path.split(url)
candidates = []
# For each preset path walk that path and test if any file matches the
# file name of our preset file name.
for preset_path in PRESET_PATHS:
for root, folders, files in os.walk(preset_path):
if preset_file in files:
candidates.append((os.path.join(root, preset_file)))
return candidates
My example does not deal with any fuzzy path searches / does not sort its output by the edit-distance (you would have to do that yourself). To test successfully against something like testrig0.lib4d you would have to implement a Hamming distance or Levenshtein distance to sort out what is close enough. For your example you would need the latter. Or you could just use a regular expression if you do not care about the edit distance.
Cheers,
zipit