diff -Nru trash-cli-0.12.6/debian/changelog trash-cli-0.12.7/debian/changelog --- trash-cli-0.12.6/debian/changelog 2012-06-21 21:34:06.000000000 +0000 +++ trash-cli-0.12.7/debian/changelog 2012-06-23 10:21:54.000000000 +0000 @@ -1,3 +1,9 @@ +trash-cli (0.12.7-1) unstable; urgency=low + + * New upstream release. + + -- Stefano Karapetsas Fri, 22 Jun 2012 16:17:20 +0200 + trash-cli (0.12.6-1) unstable; urgency=low * New upstream release (Closes: #677663, LP: #1015877) diff -Nru trash-cli-0.12.6/docs/how-to-build-and-upload-a-new-release.txt trash-cli-0.12.7/docs/how-to-build-and-upload-a-new-release.txt --- trash-cli-0.12.6/docs/how-to-build-and-upload-a-new-release.txt 2012-06-21 12:24:46.000000000 +0000 +++ trash-cli-0.12.7/docs/how-to-build-and-upload-a-new-release.txt 2012-06-22 14:15:56.000000000 +0000 @@ -1,12 +1,43 @@ To build a release ------------------ +Update the version number: + + vim trashcli/trash.py + +Run all tests: -Register the new version of the software on pypi + nosetests - python setup register -Then create a tarball and upload it to pypi: +Test the installation from tarball: + python setup.py sdist + tarball=trash-cli-0.12.7.tar.gz + + scp dist/$tarball root@192.168.56.101: + + ssh root@192.168.56.101 " + tar xvfz $tarball + cd ${tarball%%.tar.gz} + python setup.py install + trash-put --help + " + +Test the installation using easy_install: + + ssh root@192.168.56.101 " + apt-get install python-setuptools + easy_install "$tarball" + trash-put --help + " + +Register and upload: + + python setup.py register python setup.py sdist upload +Now you can tag the repo status: + + git tag $(python setup.py --version) + -EOF diff -Nru trash-cli-0.12.6/HISTORY.txt trash-cli-0.12.7/HISTORY.txt --- trash-cli-0.12.6/HISTORY.txt 2012-06-21 12:24:46.000000000 +0000 +++ trash-cli-0.12.7/HISTORY.txt 2012-06-22 14:15:56.000000000 +0000 @@ -1,3 +1,9 @@ +0.12.7: + - fixed trash-empty crashed with GetoptError in short_has_arg(): option -2 + not recognized (see + https://bugs.launchpad.net/ubuntu/+source/trash-cli/+bug/1015877 ) + - fixed inclusion of README.rst when creating distribution package + 0.12.6: - add Donate button on README diff -Nru trash-cli-0.12.6/integration_tests/test_trash_empty.py trash-cli-0.12.7/integration_tests/test_trash_empty.py --- trash-cli-0.12.6/integration_tests/test_trash_empty.py 2012-06-21 12:24:46.000000000 +0000 +++ trash-cli-0.12.7/integration_tests/test_trash_empty.py 2012-06-22 14:15:56.000000000 +0000 @@ -1,6 +1,8 @@ # Copyright (C) 2011 Andrea Francia Trivolzio(PV) Italy -from nose.tools import assert_equals, assert_items_equal, istest +from nose.tools import (assert_equals, + assert_items_equal, + istest) from trashcli.trash import EmptyCmd from StringIO import StringIO @@ -233,3 +235,36 @@ trash-empty 1.2.3 """)) +class describe_trash_empty_command_line__on_invalid_options(): + def setUp(self): + self.err, self.out = StringIO(), StringIO() + self.cmd = EmptyCmd( + err = self.err, + out = self.out, + environ = {}) + + def it_should_fail(self): + + self.exit_code = self.cmd.run('trash-empty', '-2') + + exit_code_for_command_line_usage = 64 + assert_equals(exit_code_for_command_line_usage, self.exit_code) + + def it_should_complain_to_the_standard_error(self): + + self.exit_code = self.cmd.run('trash-empty', '-2') + + assert_equals(self.err.getvalue(), dedent("""\ + trash-empty: invalid option -- '2' + """)) + + def test_with_a_different_option(self): + + self.cmd.run('trash-empty', '-3') + + assert_equals(self.err.getvalue(), dedent("""\ + trash-empty: invalid option -- '3' + """)) + + + diff -Nru trash-cli-0.12.6/MANIFEST.in trash-cli-0.12.7/MANIFEST.in --- trash-cli-0.12.6/MANIFEST.in 2012-06-21 12:24:46.000000000 +0000 +++ trash-cli-0.12.7/MANIFEST.in 2012-06-22 14:15:56.000000000 +0000 @@ -1,3 +1,4 @@ include requirements-dev.txt include ez_setup.py +include README.rst graft man diff -Nru trash-cli-0.12.6/README.rst trash-cli-0.12.7/README.rst --- trash-cli-0.12.6/README.rst 2012-06-21 12:24:46.000000000 +0000 +++ trash-cli-0.12.7/README.rst 2012-06-22 14:15:56.000000000 +0000 @@ -34,7 +34,7 @@ 2007-08-30 12:36:00 /home/andrea/foo 2007-08-30 12:39:41 /home/andrea/foo -Restore a trashed file +Restore a trashed file:: $ restore-trash 0 2007-08-30 12:36:00 /home/andrea/foo diff -Nru trash-cli-0.12.6/TODO.txt trash-cli-0.12.7/TODO.txt --- trash-cli-0.12.6/TODO.txt 2012-06-21 12:24:46.000000000 +0000 +++ trash-cli-0.12.7/TODO.txt 2012-06-22 14:15:56.000000000 +0000 @@ -31,6 +31,7 @@ - get rid of TimeUtils.parse_iso8601 if not used - rename remove_file in to remove_existing_file - refactor TrashPutCmd for simplicity + Test to be ported to nosetests: - trash-put: - trash in home trashcan @@ -44,3 +45,10 @@ - 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 + + diff -Nru trash-cli-0.12.6/trashcli/cmds.py trash-cli-0.12.7/trashcli/cmds.py --- trash-cli-0.12.6/trashcli/cmds.py 2012-06-21 12:24:46.000000000 +0000 +++ trash-cli-0.12.7/trashcli/cmds.py 2012-06-22 14:15:56.000000000 +0000 @@ -22,7 +22,7 @@ def empty(): from trashcli.trash import EmptyCmd - EmptyCmd( + return EmptyCmd( out=sys.stdout, err=sys.stderr, environ=os.environ, diff -Nru trash-cli-0.12.6/trashcli/trash.py trash-cli-0.12.7/trashcli/trash.py --- trash-cli-0.12.6/trashcli/trash.py 2012-06-21 12:24:46.000000000 +0000 +++ trash-cli-0.12.7/trashcli/trash.py 2012-06-22 14:15:56.000000000 +0000 @@ -1,7 +1,7 @@ # Copyright (C) 2007-2011 Andrea Francia Trivolzio(PV) Italy from __future__ import absolute_import -version='0.12.6' +version='0.12.7' import os import logging @@ -876,20 +876,31 @@ self.short_options = '' self.long_options = [] self.actions = dict() + self._on_invalid_option = do_nothing + def __call__(self, argv): program_name = argv[0] - from getopt import getopt - options, arguments = getopt(argv[1:], - self.short_options, - self.long_options) - - for option, value in options: - if option in self.actions: - self.actions[option](program_name) - return - for argument in arguments: - self.argument_action(argument) - self.default_action() + from getopt import getopt, GetoptError + + try: + options, arguments = getopt(argv[1:], + self.short_options, + self.long_options) + except GetoptError, e: + invalid_option = e.opt + self._on_invalid_option(program_name, invalid_option) + else: + for option, value in options: + if option in self.actions: + self.actions[option](program_name) + return + for argument in arguments: + self.argument_action(argument) + self.default_action() + + def on_invalid_option(self, action): + self._on_invalid_option = action + def on_help(self, action): self.add_option('help', action, 'h') @@ -911,6 +922,10 @@ def as_default(self, default_action): self.default_action = default_action +# Error codes (from os on *nix, hard coded for Windows): +EX_USAGE = getattr(os, 'EX_USAGE', 64) +EX_OK = getattr(os, 'EX_OK' , 0) + class EmptyCmd(): def __init__(self, out, err, environ, now = datetime.now, @@ -940,12 +955,24 @@ def run(self, *argv): self._maybe_delete = self._delete_both + self.exit_code = EX_OK + parse = Parser() parse.on_help(PrintHelp(self.description, self.println)) parse.on_version(PrintVersion(self.println, self.version)) parse.on_argument(self.set_deletion_date_criteria) parse.as_default(self._empty_all_trashdirs) + parse.on_invalid_option(self.report_invalid_option_usage) + parse(argv) + + return self.exit_code + + def report_invalid_option_usage(self, program_name, option): + self.err.write( + "{program_name}: invalid option -- '{option}'\n".format(**locals())) + self.exit_code |= EX_USAGE + def set_deletion_date_criteria(self, arg): self.max_age_in_days = int(arg) self._maybe_delete = self._delete_according_date diff -Nru trash-cli-0.12.6/unit_tests/test_parser.py trash-cli-0.12.7/unit_tests/test_parser.py --- trash-cli-0.12.6/unit_tests/test_parser.py 2012-06-21 12:24:46.000000000 +0000 +++ trash-cli-0.12.7/unit_tests/test_parser.py 2012-06-22 14:15:56.000000000 +0000 @@ -13,3 +13,13 @@ parser(['trash-list', '--raw']) on_raw.assert_called_with('trash-list') + + @istest + def how_getopt_works_with_an_invalid_option(self): + invalid_option_callback = MagicMock() + parser = Parser() + parser.on_invalid_option(invalid_option_callback) + + parser(['command-name', '-x']) + + invalid_option_callback.assert_called_with('command-name', 'x')