Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrj committed Dec 28, 2023
1 parent 1e52c8d commit 1be2358
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ https://github.com/PJDude/librer/releases
## Guidelines for crafting custom data extractors
Custom data extractor is a command that can be invoked with a single parameter - the full path to a specific file from which data is extracted. The command should provide the expected data in any textual format to the standard output (stdout). CDE can be an executable file (e.g., 7z, zip, ffmpeg, md5sum etc.) or an executable shell script (extract.sh, extract.bat etc.). The conditions it should meet are reasonably short execution time and reasonably limited information output. The criteria allowing the execution of a particular **Custom data extractor** include the glob expression (on file name) and the file size range.

## [Custom Data tutorial and examples](./info/tutorial.md) ##
## [Tutorial](./info/tutorial.md) ##

## Usage tips:
- don't put any destructive actions in your Custom Data Extractors scrips
Expand Down
Binary file modified info/example_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 12 additions & 7 deletions info/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@ How to apply this in **librer** ? Create Custom Data extractor like this:

![image info](../info/tutorial_01.png)

Now we can test new Custom Data Extractor (warning yellow icon on the right) and run it on selected file
Now we can test new Custom Data Extractor (yellow warning icon on the right) and run it on selected file:

![image info](../info/tutorial_02.png)

The Custom Data extractor worked fine on the selected file:
The Custom Data extractor worked fine on the selected file and returned the expected data:

![image info](../info/tutorial_03.png)

The result is ok, but the header generated by 7zip is something we don't really need. The simplest option is to get rid of the first 12 lines. To do this, you need to improve the executed command, execute it in the system shell and use pipes. See below. Note that a command with the "Shell" option enabled has one common field for the command and parameters. Now path to 7zip requires quotes (space sign in "Program Files" section).
The information generated by 7zip will be piped to the "more" command with the +12 parameter, resulting in the first 12 lines being skipped.
At this point we can just use such CDE and start scan our media with it.

The result is ok, but the constant header generated by 7zip is something we don't really need. The simplest option is to get rid of the first 12 lines. To do this, you need to improve the executed command, execute it in the system shell and use pipes. See below. Note that a command with the "Shell" option enabled has one common field for the command and parameters. Now path to 7zip requires quotes (space sign in "Program Files" path part). The information generated by 7zip will be piped to the "more" command with the "+12" parameter, resulting in the first 12 lines being skipped.

![image info](../info/tutorial_04.png)

result:
we test again and we have the result:

![image info](../info/tutorial_05.png)

There is no need to enclose the % character representing the processed file with quotation marks. Librer will do this internally. What if there is a problem during processing? E.g. What if the file is password protected and 7z expects user interaction and asks for password ? If we really want to open such an archive, we must enter the password for our command. However, we would most likely want to skip such a file. To do this, simply set a timeout value. A few seconds will usually be more than necessary. Once the timeout expires, the extraction of custom data from the file will be terminated.
What else do we need to consider?

There is no need to enclose the % character representing the processed file with quotation marks. Librer will do this internally. What if there is a problem during processing? E.g. What if the file is password protected and 7z expects user interaction and asks for password while scanning? If we really want to open such an archive, we must enter the password for our command. However, we would most likely want to skip such a file. To do this, simply set a timeout value. A few seconds will usually be more than necessary. Once the timeout expires, the extraction of custom data from the file will be terminated and scanning will continue.

Below is CDE with timeout set to 3 (seconds). A timeout can be set for both shell and non-shell CDE commands. Upon timeout or manual abort, which is also possible, the entire subprocess tree will be terminated.

Expand All @@ -33,13 +36,15 @@ What if we need to implement a more complex condition? E.g. file processing must

![image info](../info/tutorial_07.png)

Inside such script passed file will be mapped as first parameter (%1 on Windows). example:
Inside such script used like that, passed file will be mapped as first parameter (%1 on Windows). Example of such script (like CDE1.bat here):

```
@echo CDE test
"C:\Program Files\7-Zip\7z.exe" l %1 | more +12
@echo test finished
```
'echo' commands before and after 7z execution may be just for information purposes during testing, as always everything printed to stdout of such script will be gathered as custom data, so we dont need them in real use.

All of the above will apply to Linux as well, with consideration of obvious differences

Once we have the full set of custom data extractors set up and tested, we can start scanning the media we want to catalog. Once a new record is created, files with successfully collected custom data will be shown with a small green dot. A double click or menu action allows you to view the data and commands used to extract. The collected data is searchable
Expand Down
48 changes: 18 additions & 30 deletions src/librer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,6 @@ def fix_text_fialog(self,dialog):
dialog.find_prev_butt.configure(image=self.ico_left)
dialog.find_next_butt.configure(image=self.ico_right)


self.widget_tooltip(dialog.find_prev_butt,'Find Prev (Shift+F3)')
self.widget_tooltip(dialog.find_next_butt,'Find Next (F3)')

Expand Down Expand Up @@ -2005,6 +2004,7 @@ def exit(self):

find_params_changed=True

@block_actions_processing
def finder_wrapper_show(self):
if self.current_record:
dialog = self.get_find_dialog()
Expand Down Expand Up @@ -2078,22 +2078,23 @@ def set_found(self):
_ = {nodes_set_add(child) for child in self_tree_get_children(item)}

#@restore_status_line
@block_actions_processing
#@block_actions_processing
@gui_block
def find_prev(self):
if not self.any_find_result:
self.finder_wrapper_show()
else:
self.select_find_result(-1)
if self.actions_processing:
if not self.any_find_result:
self.finder_wrapper_show()
else:
self.select_find_result(-1)

#@restore_status_line
@block_actions_processing
@gui_block
def find_next(self):
if not self.any_find_result:
self.finder_wrapper_show()
else:
self.select_find_result(1)
if self.actions_processing:
if not self.any_find_result:
self.finder_wrapper_show()
else:
self.select_find_result(1)

def find_save_results(self):
self.find_items()
Expand Down Expand Up @@ -2487,8 +2488,6 @@ def find_items(self):
self.find_result_index=-1
self.find_next()



def get_child_of_name(self,item,child_name):
self_tree = self.tree
for child in self_tree.get_children(item):
Expand All @@ -2498,6 +2497,7 @@ def get_child_of_name(self,item,child_name):
return child
return None

@block_actions_processing
def select_find_result(self,mod):
status_to_set=None
self_tree = self.tree
Expand Down Expand Up @@ -2683,14 +2683,10 @@ def tree_on_mouse_button_press(self,event):
self.hide_tooltip()
self.popup_unpost()

if self.actions_processing:
tree=event.widget

region = tree.identify("region", event.x, event.y)

if region == 'separator':
return None
tree=self.tree
region = tree.identify("region", event.x, event.y)

if region != 'separator':
if region == 'heading':
col_nr = tree.identify_column(event.x)
colname = col_nr if col_nr=='#0' else tree.column(col_nr,'id')
Expand All @@ -2708,15 +2704,7 @@ def tree_on_mouse_button_press(self,event):

self.tree_sel_change(item)

#prevents processing of expanding nodes
#return "break"

return None

return "break"

sel_item = None

def tree_semi_focus(self):
tree = self.tree

Expand Down Expand Up @@ -2773,8 +2761,8 @@ def context_menu_show(self,event):
if tree.identify("region", event.x, event.y) == 'heading':
return

if not self.actions_processing:
return
#if not self.actions_processing:
# return

tree.focus_set()
self.tree_on_mouse_button_press(event)
Expand Down

0 comments on commit 1be2358

Please sign in to comment.