[WIP] Groom migration scripts.

### Motivation
Fix issue #956.

### Changelog
* Use context managers aggressively.
* Groom imports.
* Install a `main` function in every script.
* Process `sys.argv` through `argparse` (by @lolosk).
* Print an error message if a wrong command is given (by @lolosk).

### TODO:
* Unit-test the migration scripts.

@lolosk: Please review. If you like to do some of the `TODO` work, do a PR on my PR.
Clarification: You are suggesting to factor the entire `main` function or something else?