def testBasePath(self) : # prepare os.environ['HOME'] = "/home/test" instance = GlobalTrashCan() # execute td = instance.home_trash_dir() # verify self.assertEqual(Path("/"), td.volume)
def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr): trashsystem = GlobalTrashCan() parser = get_option_parser() (options, args) = parser.parse_args(argv) for trashed_file in trashsystem.trashed_files(): print "%s %s" % (trashed_file.deletion_date, trashed_file.path)
def test_volume_trash_dir2(self) : # prepare instance = GlobalTrashCan(getuid=self.a_fake_getuid_which_always_returns(999)) # execute result = instance.volume_trash_dir2(Volume(Path("/mnt/disk"))) # check self.assert_(isinstance(result,TrashDirectory)) self.assertEqual(Path('/mnt/disk/.Trash-999'), result.path)
def test_the_attempt_of_deleting_a_dot_directory_should_signaled_as_error(self): argument="." class StubReporter: def __init__(self): self.has_been_called=False def unable_to_trash_dot_entries(self,file): self.has_been_called=True assert_equals(file, argument) reporter=StubReporter() trashcan = GlobalTrashCan(reporter=reporter) trashcan.trash('.') assert_true(reporter.has_been_called)
def run(self,argv): parser = self.get_option_parser() (options, args) = parser.parse_args(argv[1:]) if len(args) <= 0: parser.error("Please specify the files to trash.") reporter=Reporter(self.get_logger(options.verbose,argv[0])) self.trashcan=GlobalTrashCan(reporter=reporter) self.trash_all(args)
class TrashPutCmd: def __init__(self, stdout, stderr): self.stdout=stdout self.stderr=stderr def run(self,argv): parser = self.get_option_parser() (options, args) = parser.parse_args(argv[1:]) if len(args) <= 0: parser.error("Please specify the files to trash.") reporter=Reporter(self.get_logger(options.verbose,argv[0])) self.trashcan=GlobalTrashCan(reporter=reporter) self.trash_all(args) def trash_all(self, args): for arg in args : self.trash(arg) def trash(self, arg): self.trashcan.trash(Path(arg)) def get_option_parser(self): from trashcli import version from optparse import OptionParser from trashcli.cli.util import NoWrapFormatter parser = OptionParser(usage="%prog [OPTION]... FILE...", description="Put files in trash", version="%%prog %s" % version, formatter=NoWrapFormatter(), epilog= """To remove a file whose name starts with a `-', for example `-foo', use one of these commands: trash -- -foo trash ./-foo Report bugs to http://code.google.com/p/trash-cli/issues""") parser.add_option("-d", "--directory", action="store_true", help="ignored (for GNU rm compatibility)") parser.add_option("-f", "--force", action="store_true", help="ignored (for GNU rm compatibility)") parser.add_option("-i", "--interactive", action="store_true", help="ignored (for GNU rm compatibility)") parser.add_option("-r", "-R", "--recursive", action="store_true", help="ignored (for GNU rm compatibility)") parser.add_option("-v", "--verbose", action="store_true", help="explain what is being done", dest="verbose") return parser def get_logger(self,verbose,argv0): import os.path class MyLogger: def __init__(self, stderr): self.program_name = os.path.basename(argv0) self.stderr=stderr def info(self,message): if verbose: self.emit(message) def warning(self,message): self.emit(message) def emit(self, message): self.stderr.write("%s: %s\n" % (self.program_name,message)) return MyLogger(self.stderr)
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