refactor: change os calls not supported by GAE sandbox

The Google Appengine sandbox restricts certain calls from
the os module. Refactor these to methods available on a file
object.