CommunityScripts icon indicating copy to clipboard operation
CommunityScripts copied to clipboard

[RenamerOnUpdate] Move files fails when library is referenced via UNC

Open Wheeliewhee opened this issue 2 years ago • 3 comments

[Symptom] Can't use RenamerOnUpdate to move files and create folder structures when library uses UNC names (ie \library\share) - at least on Windows.

[Investigation] In-situ file renames work fine. Digging around a bit (and I'm no coder for sure!) it's because the code in RenamerOnUpdate.py funtion create_new_pathis expecting a ": " in the first position, and then builds a path after that. When no ":" is present, the resulting path is \library\share\folder which then doesn't match in the DB, resulting in DB update failure and roll back.

[Fix] At least for me was to add a bool assuming path was a UNC, setting that to False if a ":" was detected, but if it remained True, then simply appending two backslashes (\ - one is needed to escape the second). While this works for me, I've done no testing beyond triggering a move based on a tag, and I've not tested against a named drive.

Wheeliewhee avatar Sep 18 '23 13:09 Wheeliewhee

@Wheeliewhee Can you show the code you used to make it work?

eeyoredk avatar Sep 06 '24 17:09 eeyoredk

Within renamerOnUpdate.py, edit the function create_new_path with the three additions in shown by the remarks below - it still seems to work!

def create_new_path(scene_info: dict, template: dict):
    # Create the new path
    # Split the template path
    path_split = scene_info["template_split"]
    
    #ADDITION ONE
    bUNC = True
    #END ONE

    path_list = []
    for part in path_split:
        if ":" in part and path_split[0]:
            path_list.append(part)
            
    #ADDITION TWO
    bUNC = False
    #END TWO

        elif part == "$studio_hierarchy":
            if not scene_info.get("studio_hierarchy"):
                continue
            for p in scene_info["studio_hierarchy"]:
                path_list.append(re.sub('[\\/:"*?<>|]+', "", p).strip())
        else:
            path_list.append(
                re.sub('[\\/:"*?<>|]+', "", makePath(scene_info, part)).strip()
            )
    # Remove blank, empty string
    path_split = [x for x in path_list if x]
    # The first character was a seperator, so put it back.
    if path_list[0] == "":
        path_split.insert(0, "")

    if PREVENT_CONSECUTIVE:
        # remove consecutive (/FolderName/FolderName/video.mp4 -> FolderName/video.mp4
        path_split = remove_consecutive(path_split)

    if "^*" in template["path"]["destination"]:
        if scene_info["current_directory"] != os.sep.join(path_split):
            path_split.pop(len(scene_info["current_directory"]))

    path_edited = os.sep.join(path_split)
    
    #ADDITION THREE
     if bUNC:
        path_edited = '\\' + path_edited
    #END THREE
     
    if FILENAME_REMOVECHARACTER:
        path_edited = re.sub(f"[{FILENAME_REMOVECHARACTER}]+", "", path_edited)

    # Using typewriter for Apostrophe
    new_path = re.sub("[’‘”“]+", "'", path_edited)

    return new_path```

Wheeliewhee avatar Sep 06 '24 20:09 Wheeliewhee

Thanks @Wheeliewhee Unfortunately it does not work with my setup and I do not have the skills to figure out what is wrong. Edit: Since I only have UNC paths in my libraries, I took a chance and added the last line below to the original script. It seems to work fine, but since I have no idea what I am doing, it may mess up everything eventually.

if PREVENT_CONSECUTIVE:
    # remove consecutive (/FolderName/FolderName/video.mp4 -> FolderName/video.mp4
    path_split = remove_consecutive(path_split)

if "^*" in template["path"]["destination"]:
    if scene_info["current_directory"] != os.sep.join(path_split):
        path_split.pop(len(scene_info["current_directory"]))

path_edited = os.sep.join(path_split)
path_edited = '\\' + path_edited

eeyoredk avatar Sep 07 '24 04:09 eeyoredk