Overload "Delete Results From Disk"

   553   11   0
User Avatar
Member
186 posts
Joined: 11月 2010
Offline
Hi,

Is it possible to overload/make callback for “Delete Results From Disk” call from workitem context menu?

For some cases, it is not so easy just delete files from the disk if we are using wrappers or need an additional callback.

Thanks
Ostap
User Avatar
スタッフ
378 posts
Joined: 5月 2014
Online
This isn't possible right now, but I think we can make that an RFE to add that functionality. It would probably be something like the custom cache handlers – a callback function that's registered globally, and invoked when a work item is deleting files.
User Avatar
Member
186 posts
Joined: 11月 2010
Offline
It is a pretty important improvement for us.
Is there any chance to get some time frame when it could be done?
User Avatar
スタッフ
378 posts
Joined: 5月 2014
Online
I should be able to get that improvement added this week.
User Avatar
Member
186 posts
Joined: 11月 2010
Offline
Looking forward to updates.
Thanks
User Avatar
スタッフ
378 posts
Joined: 5月 2014
Online
Hey Ostap, the next daily build will have something for you try out.

Adding a hook for work item dirtying has been a long standing RFE, and the Delete Files… option is just a special case of dirtying. Starting with tomorrow's build its now possible to register custom functions that get called when work items are dirtied, deleted, or have their files removed from disk. The new function for adding a dirty handler is the following:

pdg.TypeRegistry.registerDirtyHandler(
	handler,
	handler_type = pdg.dirtyHandlerType.Any,
	scheduler_filter = [],
	node_filter = [],
	requires_outputs = False,
	is_global = False)

All of the arguments are optional, except for the function itself:

handler               -  Custom function defined by the user
handler_type - The type of dirty operation that should trigger the function. Can be any work item dirty, work item deletion, or work item deletion w/ file removal.
scheduler_filter - A list of scheduler type names. The handler is only called if the work item's scheduler matches the filter, or if the filter is empty
node_filter - A list of node type names. Handler is only called if the work item's node matches the filter, or if the filter is empty.
requires_outputs - If handler_type is pdg.dirtyHandlerType.Files and this flag is True, then the handler is only called if there are actual files being deleted.
is_global - If this is True, the handler is called only once at the beginning of the dirty, instead of for each work item, regardless of the number of items being dirtied.

The custom function should have the following signature:

def handler(work_item, file_list)

The work_item argument is the item being dirtied/deleted, or None if the handler is global. The file_list is the list of files from that work item that will be deleted from disk. The reason this is provided as a separate argument is that the files that are deleted is not necessarily the same as the output file list on the work item itself. Only files “owned” by a work item are deleted – the output files on a ROP Fetch are deleted, but the files on a File Pattern are not since they're not owned by those work items.

For example:

import pdg

def simple_handler(work_item, file_list):
    print(work_item)
    print(file_list)

def registerTypes(type_registry):
    # Prints for any work item that is dirtied, deleted or deleted + remove files
    type_registry.registerDirtyHandler(simple_handler)

    # Only prints for work items that are having their files deleted
    type_registry.registerDirtyHandler(simple_handler, handler_type=pdg.dirtyHandlerType.Files)

    # Only prints for work items that are having their files deleted, with at least one file being deleted
    type_registry.registerDirtyHandler(
    	simple_handler,
    	handler_type=pdg.dirtyHandlerType.Files,
    	requires_outputs=True)

You can register the function at any point in time, but the intended use is to put them in a file in ~/houdini18.0/pdg/types, like a custom node, scheduler or file cache handler.
Edited by tpetrick - 2020年9月16日 17:23:45
User Avatar
Member
186 posts
Joined: 11月 2010
Offline
Thank you very much!
Going to try
User Avatar
Member
186 posts
Joined: 11月 2010
Offline
Is it possible to prevent deletion from your side?
We would like to use our own methods to delete files.

Maybe something like that:
    type_registry.registerDirtyHandler(
    	simple_handler,
    	handler_type=pdg.dirtyHandlerType.Files,
    	skip_deletion=True)
User Avatar
スタッフ
378 posts
Joined: 5月 2014
Online
Yep, we can make it so the handler also prevents PDG from doing the deletion itself.


How about using the return value of the handler? If the handler doesn't return anything or returns False, then PDG will do the deletion like it normally does. If the handler returns True, that indicates that the custom code has deleted the files.
User Avatar
Member
186 posts
Joined: 11月 2010
Offline
Using return value as an indicator for deletion - seems like a nice idea!
User Avatar
スタッフ
378 posts
Joined: 5月 2014
Online
Hey Ostap, that change is now available in the latest daily builds of 18.0. Your custom delete handler can return True to tell PDG not to delete the file(s) for the work item that was passed to the handler function.
User Avatar
Member
186 posts
Joined: 11月 2010
Offline
Thank you!
Going to try
  • Quick Links