Fix various Pep8 1.5.4 errors

Pep8 1.5.4 fixes several bugs in visual indent and spaces
detection. Adjust the code accordingly so that it passes
once we try to upgrade.

Change-Id: I5691ffd29edcb32fdbacd9da7ca71bfcabeeffe5
Use safe way through "with" statement to work with files

It's good practice to use with statement to work with files. This way files get
closed automatically at the end of the block. Fixed some cases, including some
where file wasn't closed after usage

Change-Id: I9399f2a2b7edb1cd5aa64782cd9f980f9233b827
Merge "Fix various Pep8 1.5.4 errors"
Merge "Use safe way through "with" statement to work with files"