trash-cli icon indicating copy to clipboard operation
trash-cli copied to clipboard

`--verbose` option is too talkative for multiple entries

Open KSR-Yasuda opened this issue 5 years ago • 3 comments

Verbose log is a bit too much for multiple entries deletion.

As below, shows trash-dir search logs for each entries.

Couldn't it be more mild?

% trash --version
trash 0.17.1.14
% touch 1 2 3 4 5
% trash -v 1 2 3 4 5
trash: Volume of file: /mnt/tmp
trash: Trash-dir: /home/USER/.local/share/Trash from volume: /
trash: found unusable .Trash dir (should be a dir): /mnt/tmp/.Trash
trash: Trash-dir: /mnt/tmp/.Trash-1000 from volume: /mnt/tmp
trash: '1' trashed in /mnt/tmp/.Trash-1000
trash: Volume of file: /mnt/tmp
trash: Trash-dir: /home/USER/.local/share/Trash from volume: /
trash: found unusable .Trash dir (should be a dir): /mnt/tmp/.Trash
trash: Trash-dir: /mnt/tmp/.Trash-1000 from volume: /mnt/tmp
trash: '2' trashed in /mnt/tmp/.Trash-1000
trash: Volume of file: /mnt/tmp
trash: Trash-dir: /home/USER/.local/share/Trash from volume: /
trash: found unusable .Trash dir (should be a dir): /mnt/tmp/.Trash
trash: Trash-dir: /mnt/tmp/.Trash-1000 from volume: /mnt/tmp
trash: '3' trashed in /mnt/tmp/.Trash-1000
trash: Volume of file: /mnt/tmp
trash: Trash-dir: /home/USER/.local/share/Trash from volume: /
trash: found unusable .Trash dir (should be a dir): /mnt/tmp/.Trash
trash: Trash-dir: /mnt/tmp/.Trash-1000 from volume: /mnt/tmp
trash: '4' trashed in /mnt/tmp/.Trash-1000
trash: Volume of file: /mnt/tmp
trash: Trash-dir: /home/USER/.local/share/Trash from volume: /
trash: found unusable .Trash dir (should be a dir): /mnt/tmp/.Trash
trash: Trash-dir: /mnt/tmp/.Trash-1000 from volume: /mnt/tmp
trash: '5' trashed in /mnt/tmp/.Trash-1000

rm command just tells only entry deletion in verbose mode.
I would like such use.

The current trash deletion logs are buried in other logs.

% touch 1 2 3 4 5
% rm -v 1 2 3 4 5
removed '1'
removed '2'
removed '3'
removed '4'
removed '5'

Of course I know that this is for entries in different paths,
which can be in different mount points and have different trash-dirs...

How is setting up a new option to show trash-dir search log?

KSR-Yasuda avatar Jan 24 '20 05:01 KSR-Yasuda

Such as this:

diff --git a/trashcli/put.py b/trashcli/put.py
index e5ac2a3..54c3497 100644
--- a/trashcli/put.py
+++ b/trashcli/put.py
@@ -62,6 +62,7 @@ class TrashPutCmd:
             return e.code
         else:
             if options.verbose: logger.be_verbose()
+            if options.debug: logger.be_debug()
             if options.trashdir:
                 self.trashdir = options.trashdir
 
@@ -109,7 +110,11 @@ Report bugs to https://github.com/andreafrancia/trash-cli/issues""")
                           "--verbose",
                           action="store_true",
                           dest="verbose",
-                          help="explain what is being done")
+                          help="Verbose log output")
+        parser.add_option("--debug",
+                          action="store_true",
+                          dest="debug",
+                          help="Debug log output")
         original_print_help = parser.print_help
         def patched_print_help():
             original_print_help(self.stdout)
@@ -312,8 +317,15 @@ class MyLogger:
         self.program_name = program_name
         self.stderr=stderr
         self.verbose = False
+        self.debugLog = False
     def be_verbose(self):
         self.verbose = True
+    def be_debug(self):
+        self.debugLog = True
+        self.verbose = True
+    def debug(self,message):
+        if self.debugLog:
+            self.emit(message)
     def info(self,message):
         if self.verbose:
             self.emit(message)
@@ -346,13 +358,13 @@ class TrashPutReporter:
         self.logger.info("'%s' trashed in %s" % (trashee,
                                                  shrinkuser(trash_directory)))
     def found_unsercure_trash_dir_symlink(self, trash_dir_path):
-        self.logger.info("found unsecure .Trash dir (should not be a symlink): %s"
+        self.logger.debug("found unsecure .Trash dir (should not be a symlink): %s"
                 % trash_dir_path)
     def invalid_top_trash_is_not_a_dir(self, trash_dir_path):
-        self.logger.info("found unusable .Trash dir (should be a dir): %s"
+        self.logger.debug("found unusable .Trash dir (should be a dir): %s"
                 % trash_dir_path)
     def found_unsecure_trash_dir_unsticky(self, trash_dir_path):
-        self.logger.info("found unsecure .Trash dir (should be sticky): %s"
+        self.logger.debug("found unsecure .Trash dir (should be sticky): %s"
                 % trash_dir_path)
     def unable_to_trash_file_in_because(self,
                                         file_to_be_trashed,
@@ -360,7 +372,7 @@ class TrashPutReporter:
         self.logger.info("Failed to trash %s in %s, because :%s" % (
            file_to_be_trashed, shrinkuser(trash_directory), error))
     def trash_dir_with_volume(self, trash_dir_path, volume_path):
-        self.logger.info("Trash-dir: %s from volume: %s" % (trash_dir_path,
+        self.logger.debug("Trash-dir: %s from volume: %s" % (trash_dir_path,
                                                             volume_path))
     def exit_code(self):
         if not self.some_file_has_not_be_trashed:
@@ -368,7 +380,7 @@ class TrashPutReporter:
         else:
             return EX_IOERR
     def volume_of_file(self,volume):
-        self.logger.info("Volume of file: %s" % volume)
+        self.logger.debug("Volume of file: %s" % volume)
 
 def parent_realpath(path):
     parent = os.path.dirname(path)

--verbose mode (Only show trashed logs)

% touch 1 2 3 4 5
% ./trash-put --verbose 1 2 3 4 5
trash-put: '1' trashed in /mnt/tmp/.Trash-1000
trash-put: '2' trashed in /mnt/tmp/.Trash-1000
trash-put: '3' trashed in /mnt/tmp/.Trash-1000
trash-put: '4' trashed in /mnt/tmp/.Trash-1000
trash-put: '5' trashed in /mnt/tmp/.Trash-1000

--debug mode (Same as the current --verbose mode)

% touch 1 2 3 4 5
% ./trash-put --debug 1 2 3 4 5
trash-put: Volume of file: /mnt/tmp
trash-put: Trash-dir: /home/USER/.local/share/Trash from volume: /
trash-put: found unusable .Trash dir (should be a dir): /mnt/tmp/.Trash
trash-put: Trash-dir: /mnt/tmp/.Trash-1000 from volume: /mnt/tmp
trash-put: '1' trashed in /mnt/tmp/.Trash-1000
trash-put: Volume of file: /mnt/tmp
trash-put: Trash-dir: /home/USER/.local/share/Trash from volume: /
trash-put: found unusable .Trash dir (should be a dir): /mnt/tmp/.Trash
trash-put: Trash-dir: /mnt/tmp/.Trash-1000 from volume: /mnt/tmp
trash-put: '2' trashed in /mnt/tmp/.Trash-1000
trash-put: Volume of file: /mnt/tmp
trash-put: Trash-dir: /home/USER/.local/share/Trash from volume: /
trash-put: found unusable .Trash dir (should be a dir): /mnt/tmp/.Trash
trash-put: Trash-dir: /mnt/tmp/.Trash-1000 from volume: /mnt/tmp
trash-put: '3' trashed in /mnt/tmp/.Trash-1000
trash-put: Volume of file: /mnt/tmp
trash-put: Trash-dir: /home/USER/.local/share/Trash from volume: /
trash-put: found unusable .Trash dir (should be a dir): /mnt/tmp/.Trash
trash-put: Trash-dir: /mnt/tmp/.Trash-1000 from volume: /mnt/tmp
trash-put: '4' trashed in /mnt/tmp/.Trash-1000
trash-put: Volume of file: /mnt/tmp
trash-put: Trash-dir: /home/USER/.local/share/Trash from volume: /
trash-put: found unusable .Trash dir (should be a dir): /mnt/tmp/.Trash
trash-put: Trash-dir: /mnt/tmp/.Trash-1000 from volume: /mnt/tmp
trash-put: '5' trashed in /mnt/tmp/.Trash-1000

KSR-Yasuda avatar Jan 24 '20 08:01 KSR-Yasuda

I think this is a really good idea and the above method looks great. (Although I'd change help="Verbose log output") to help="verbose log output") for capitalization consistency.)

I actually came here looking for exactly this!

k4j8 avatar Feb 12 '20 01:02 k4j8

The new version of trash-cli should solve this problem.

$ trash-put --version
0.23.11.10
$ touch 1 2 3 4 5
$ trash-put -v 1 2 3 4 5
trash-put: '1' trashed in ~/.local/share/Trash
trash-put: '2' trashed in ~/.local/share/Trash
trash-put: '3' trashed in ~/.local/share/Trash
trash-put: '4' trashed in ~/.local/share/Trash
trash-put: '5' trashed in ~/.local/share/Trash

andreafrancia avatar Nov 10 '23 07:11 andreafrancia