Merge lp:~frankban/lpsetup/bug-1034602-handle-target-dir into lp:lpsetup
| Status: | Merged |
|---|---|
| Approved by: | Francesco Banconi on 2012-08-24 |
| Approved revision: | 83 |
| Merged at revision: | 77 |
| Proposed branch: | lp:~frankban/lpsetup/bug-1034602-handle-target-dir |
| Merge into: | lp:lpsetup |
| Diff against target: |
174 lines (+94/-5) 4 files modified
lpsetup/handlers.py (+27/-2) lpsetup/tests/subcommands/test_smoke.py (+5/-2) lpsetup/tests/test_handlers.py (+57/-0) lpsetup/tests/utils.py (+5/-1) |
| To merge this branch: | bzr merge lp:~frankban/lpsetup/bug-1034602-handle-target-dir |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Francesco Banconi (community) | Approve on 2012-08-24 | ||
| Brad Crittenden (community) | 2012-08-24 | Approve on 2012-08-24 | |
|
Review via email:
|
|||
Commit Message
handle_target_dir validates the provided directory.
Description of the Change
= Summary =
handle_target_dir (used by update subcommand) should raise an error if the target dir does not exist or is not writable.
== Implementation ==
I decided to also add another validation: handle_target_dir fails if the target dir does not look like a Launchpad branch. This way we can avoid `update` to start, create required directories (eggs, yui etc...), and then crash because `update-sourcecode` can not be found in the target dir.
== Other changes ==
Updated dry run smoke tests to pass a valid target dir to `lp-setup update`.
Added tests for handle_target_dir.
Defined `test_template_dir` at module level in lpsetup.
| Launchpad QA Bot (lpqabot) wrote : | # |
The attempt to merge lp:~frankban/lpsetup/bug-1034602-handle-target-dir into lp:lpsetup failed. Below is the output from the failed tests.
+ set -o errexit
++ grep -v distribute_setup.py
++ find . -name build -prune -o -name '*.py'
+ pyfiles='./setup.py
./lplxcip/
./lplxcip/
./lplxcip/
./lplxcip/
./lplxcip/
./lplxcip/lxcip.py
./lpsetup/utils.py
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/
./lpsetup/cli.py'
+ pocketlint ./setup.py ./lplxcip/
+ pep8 --exclude=build ./setup.py ./lplxcip/
- 83. By Francesco Banconi on 2012-08-24
-
Changes per review.
| Francesco Banconi (frankban) wrote : | # |
Thanks for your review Brad. I fixed the branch following your suggestions with one exception:
I've seen that removing the chmod clean up generates this error:
=======
ERROR: test_is_writable (lpsetup.
-------
Traceback (most recent call last):
File "/usr/lib/
rmtree(
File "/usr/lib/
onerror(
File "/usr/lib/
os.rmdir(path)
OSError: [Errno 13] Permission denied: '/tmp/tmp6TfXhT
So, the write permission missing does not prevent you from deleting the directory iself, but its contents.
The chmod cleanup is called before the rmtree cleanup because the (documented) system used is LIFO.
Maybe a try/finally block could be more explicit?

* typo: does not exist
* It is minor but I'd change "the target dir {0} is not a valid Launchpad branch" to say it is not a valid Launchpad tree. It may be a valid branch but not have a tree associated with it, i.e. devel vs sandbox.
* I think it would be cleaner to move the addCleanup in HandleTargetDir Test.setUp to be done right after the mktemp().
* Your test rely on the supposition that mktemp() will put things in /tmp. It might be more self-documenting and future proof if you extracted the actual directory using os.path.dirname and use that instead.
* The test_exists test is a bit fragile in that other processes could create that same directory after you remove it. Highly unlikely. But, you could avoid the appearance of a problem by using a subdirectory inside temporary directory as something you know does not exist. Picky, for sure.
* In test_is_writable your cleanup is either unnecessary because rmtree doesn't care and removes it anyway or it depends on the chmod cleanup being called before the rmtree cleanup. I just verified it is the former, rmtree does not care about write permissions when removing an owned tree, so the chmod cleanup is unnecessary.
This is a great improvement. Thanks.