jafeha / parabird

Simple script written in python to build an os independent truecrypt encrypted usb-stick containing a portable thunderbird, enigmail, torbirdy and vidalia.
GNU General Public License v3.0
11 stars 7 forks source link

build cleanup function #15

Open jafeha opened 11 years ago

jafeha commented 11 years ago

we need a cleanup function that is triggered every time the skript runs into an exception block.

jafeha commented 11 years ago

in the function we need to make sure that really all the files get removed: the os.removedirs directive seems not to remove nonempty folders. see http://stackoverflow.com/questions/303200/how-do-i-remove-delete-a-folder-that-is-not-empty-with-python for some ideas to do this. empty temporary dirs can be removed as shown in the cleaning up section at the end of the file.

cleaning up has also to check if there was a container created and mounted and has to unmount and remove it. we could consider to unmount usb sticks in within the function.

we could consider to write two functions: one for cleaning up after an exception and one for cleaning up after a successful usbstick creation.

jojoo- commented 11 years ago

i dont know it our script should unmount the stick at all. maybe only. if --device is specified.

other than that go with shutil.rmtree

jafeha commented 11 years ago

you're right about that. we're not the mounting the stick, so we should not cause trouble doing it for our users. i tried to implement that. mac os code needs some testing.

jafeha commented 11 years ago

I had some more thoughts ab out this. I want to return the PC as it was before, which means every folder that was created gets removed, the TC container gets unmounted and if the stick was mounted by the script, it should unmount it.

Thats imho best practice here.

Another problem is that the container should geht removed if the script fails. So we need either a second function not removing it at the end after a sucessful run or wie need some kind oft markers, that trigger the removal.

For a first impression, take a look at cleanup.py (most recent commit d5b8deebd920eaee223464458a2c4c2682b71673)

jafeha commented 11 years ago

i've moved the cleanup stuff to an own function here: 8eec34fe5743f worksforme so far.

we need to call that function within all our exceptions where before we call sys.exit(). mbe we need another function called cleanup_failed which also removes broken containers.

i'll close this ticket as soon as cleanup is implemented in all exceptions and broken containers get removed.

jafeha commented 11 years ago

the exceptions within the main script call the cleanup func, the functions within utils.py still won't do it, because there are some vars missing (mountpoint, tc_mountpoint).