#Python makes such great use of that horizontal real estate. /s
@lattera I don't know about that. This is the code trying to tell you something, right? If you don't like huge indents, then don't use such huge cyclomatic complexity. Even with the most hurried and superficial refactor it fits just fine in 80 character lines, and in reality I'd make better use of Pythonic idioms and features to simplify and improve readability way more than this...
@lattera Like, some of these functions feel like they might benefit from being methods on classes, which eliminates many of the passed around variables. A lot of the cleanup actions should probably be happening in context managers. The exceptions could probably be changed from a "catch, log and carry on" style into a "raise and forget" style. All of which, and more, would render the core, inner part of the code more succinct and readable.