Browse files

Some refactors

  • Loading branch information...
1 parent 0f50561 commit 6a38c4812c0d2d574c07c1d69381aeb7ae537f92 @andreafrancia committed Aug 12, 2012
Showing with 82 additions and 43 deletions.
  1. +51 −7 TODO.txt
  2. +6 −0 bugs.txt
  3. +8 −8 integration_tests/test_trash_put.py
  4. +17 −13 trashcli/trash.py
  5. +0 −15 unit_tests/test_characterization.py
View
58 TODO.txt
@@ -1,3 +1,53 @@
+Working on:
+ - Fixing exit code when fail to trash files:
+ - decide exit code values
+ - document exit code values (in manpages)
+ - write a test testing trash-put with non-existent
+ x clean up test_trash_put.py
+ x describe_trash_put --> when_
+
+ - implement and refactor:
+ - find a better name for TrashPutReporter
+ - make TrashPutReport store exit code, initialized to SUCCESS
+ - make TrashPutCmd#run return the exit_code from the reporter
+
+ - Removing the TrashDirectory hierarchy:
+ - Remove HomeTrashDirectory
+ - move the behaviour of name() to TrashDirectory
+ - remove import in test_trash.py
+ - make HomeTrashDirectory a factory for TestTrashedFile
+ - Remove references to VolumeTrashDirectory
+ - trash.py
+ - test_trash.py
+ - Collapse check:
+ - Move Method1VolumeTrashDirectory:check to a Strategy
+ - trash.py
+ - test_trash.py
+ - in Method1VolumeTrashDirectoryTest factor out "chmod +/-t dir"
+
+TrashDirectory collaborators:
+ - os.path.normpath
+ - os.path.basename
+ - os.path.abspath
+ - os.path.exists
+ - os.path.join
+ - os.path.isabs
+ - os.chmod
+ - os.open/os.write/os.close
+ - TrashInfo
+ - TrashedFile
+ - datetime
+ - shutil.move
+
+GlobalTrashCan
+ - enumerates possible TrashDirectories for a file to be trashed
+ - enumerates all trashed files
+ - trash a file in the right location
+ - knows when a file should be skipped
+ - knows when a file can be trashed in a TrashDir
+ - enumerates all TrashDir of a Volume
+ - compose method 1 and method 2 TrashDir
+
Features backlog:
- trash-list should handle .trashinfo from home trashdir that contains
relative path
@@ -17,11 +67,10 @@ Features backlog:
- trash-rm '*.o'
- trash-empty should empty even the mac trash directory
-To be fixed:
+Design todo:
- invalidate Google Code download and put a redirect to PyPi
- get rid of logging package
- get rid of the IOError exception raising on file is not in the same volume
- - consolidate TrashDirectory abstract and the AvailableTrashDir abstraction
- get rid of TrashDirectory.info_dir and files_dir properties
- remove all the duplication
- all_info_files, trashed_files and for_all_trashed_files
@@ -45,10 +94,5 @@ Test to be ported to nosetests:
- should refuse to create the $topdir/.Trash/$uid directory if the
$topdir/.Trash is not sticky
-Bug reported on external trackers:
- x trash-empty crashed with GetoptError in short_has_arg(): option -2 not
- recognized,
- url: https://bugs.launchpad.net/ubuntu/+source/trash-cli/+bug/1015877
- status: solved on Thu Jun 21 12:50:03 CEST 2012
View
6 bugs.txt
@@ -0,0 +1,6 @@
+Bug reported on external trackers:
+ x trash-empty crashed with GetoptError in short_has_arg(): option -2 not
+ recognized,
+ url: https://bugs.launchpad.net/ubuntu/+source/trash-cli/+bug/1015877
+ status: solved on Thu Jun 21 12:50:03 CEST 2012
+
View
16 integration_tests/test_trash_put.py
@@ -5,7 +5,7 @@
from trashcli.trash import TrashPutCmd
@istest
-class describe_trash_put_command_when_deleting_a_file:
+class when_deleting_a_file:
@istest
def it_should_remove_the_file(self):
@@ -18,7 +18,7 @@ def it_should_remove_it_silently(self):
self.output_should_be('')
def a_trashinfo_file_should_have_been_created(self):
-
+
file('sandbox/XDG_DATA_HOME/Trash/info/foo.trashinfo').read()
def setUp(self):
@@ -28,16 +28,14 @@ def setUp(self):
self.run_trashput = TrashPutRunner(
environ = {'XDG_DATA_HOME': 'sandbox/XDG_DATA_HOME' }
)
-
+
self.stderr_should_be = self.run_trashput.err.should_be
self.output_should_be = self.run_trashput.out.should_be
self.run_trashput('trash-put', 'sandbox/foo')
-import os
-exists = os.path.exists
@istest
-class describe_trash_put_command_on_dot_arguments:
+class when_fed_with_dot_arguments:
def test_dot_argument_is_skipped(self):
having_file('other_argument')
@@ -98,15 +96,16 @@ def test_dot_dot_argument_is_skipped_even_in_subdirs(self):
def setUp(self):
self.run_trashput = TrashPutRunner()
self.stderr_should_be = self.run_trashput.err.should_be
-
+
+import os
class TrashPutRunner:
def __init__(self, environ = os.environ):
from .output_collector import OutputCollector
self.out = OutputCollector()
self.err = OutputCollector()
self.environ = environ
def __call__(self, *argv):
- TrashPutCmd(
+ TrashPutCmd(
stdout = self.out,
stderr = self.err,
environ = self.environ
@@ -116,3 +115,4 @@ def file_should_have_been_deleted(path):
import os
assert not os.path.exists('sandbox/foo')
+exists = os.path.exists
View
30 trashcli/trash.py
@@ -317,7 +317,7 @@ def trashed_files(self):
for trashedfile in trash_dir.trashed_files():
yield trashedfile
- def trash(self,file) :
+ def trash(self, file) :
"""
Trash a file in the appropriate trash directory.
If the file belong to the same volume of the trash home directory it
@@ -364,23 +364,31 @@ def file_could_be_trashed_in(self,file_to_be_trashed,trash_dir_path):
def _trash_directories(self) :
"""Return a generator of all TrashDirectories in the filesystem"""
- yield self._home_trash_dir()
+ for td in self._home_trash_dir():
+ yield td
for mount_point in self.list_mount_points():
volume = mount_point
yield self._volume_trash_dir1(volume)
yield self._volume_trash_dir2(volume)
def _possible_trash_directories_for(self,file):
- yield self._home_trash_dir()
+ for td in self._home_trash_dir():
+ yield td
for td in self.trash_directories_for_volume(self.volume_of_parent(file)):
yield td
- def trash_directories_for_volume(self,volume):
+ def trash_directories_for_volume(self, volume):
yield self._volume_trash_dir1(volume)
yield self._volume_trash_dir2(volume)
def _home_trash_dir(self) :
- trash_dir = HomeTrashDirectory(self._home_trash_dir_path())
- trash_dir.store_absolute_paths()
- return trash_dir
- def _volume_trash_dir1(self,volume):
+ paths = []
+ home_trashcan_if_possible(self.environ, paths.append)
+
+ result = []
+ for trash_dir_path in paths:
+ trash_dir = HomeTrashDirectory(trash_dir_path)
+ trash_dir.store_absolute_paths()
+ result.append(trash_dir)
+ return result
+ def _volume_trash_dir1(self, volume):
"""
Return the method (1) volume trash dir ($topdir/.Trash/$uid).
"""
@@ -399,10 +407,6 @@ def _volume_trash_dir2(self, volume) :
trash_dir = TrashDirectory(trash_directory_path,volume)
trash_dir.store_relative_paths()
return trash_dir
- def _home_trash_dir_path(self):
- result = []
- home_trashcan_if_possible(self.environ, result.append)
- return result[0]
def for_all_trashed_file(self, action):
for trashedfile in self.trashed_files():
@@ -598,7 +602,7 @@ def run(self, argv):
if len(args) <= 0:
parser.error("Please specify the files to trash.")
- reporter=TrashPutReporter(self.get_logger(options.verbose,argv[0]))
+ reporter = TrashPutReporter(self.get_logger(options.verbose,argv[0]))
self.trashcan = GlobalTrashCan(
reporter = reporter,
View
15 unit_tests/test_characterization.py
@@ -1,15 +0,0 @@
-# Copyright (C) 2011 Andrea Francia Trivolzio(PV) Italy
-
-from nose.tools import istest
-
-from trashcli.trash import GlobalTrashCan
-
-@istest
-class GlobalTrashCanTest:
-
- def test_home_dir_path(self):
- a=GlobalTrashCan(environ = {'XDG_DATA_HOME': './XDG_DATA_HOME'})
- home_trash = a._home_trash_dir_path()
-
- assert './XDG_DATA_HOME/Trash' == home_trash
-

0 comments on commit 6a38c48

Please sign in to comment.