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
Overload "Delete Results From Disk"
5547 11 0- Ostap
- Member
- 209 posts
- Joined: Nov. 2010
- Offline
- tpetrick
- Staff
- 578 posts
- Joined: May 2014
- Offline
- Ostap
- Member
- 209 posts
- Joined: Nov. 2010
- Offline
- tpetrick
- Staff
- 578 posts
- Joined: May 2014
- Offline
- Ostap
- Member
- 209 posts
- Joined: Nov. 2010
- Offline
- tpetrick
- Staff
- 578 posts
- Joined: May 2014
- Offline
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:
All of the arguments are optional, except for the function itself:
The custom function should have the following signature:
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:
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.
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 - Sept. 16, 2020 17:23:45
- Ostap
- Member
- 209 posts
- Joined: Nov. 2010
- Offline
- Ostap
- Member
- 209 posts
- Joined: Nov. 2010
- Offline
- tpetrick
- Staff
- 578 posts
- Joined: May 2014
- Offline
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.
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.
- Ostap
- Member
- 209 posts
- Joined: Nov. 2010
- Offline
- tpetrick
- Staff
- 578 posts
- Joined: May 2014
- Offline
- Ostap
- Member
- 209 posts
- Joined: Nov. 2010
- Offline
-
- Quick Links