+def open_output_file(filename):
+ fullpath = os.path.abspath(os.path.join(g.destination_dir, filename))
+ full_dir = os.path.dirname(fullpath)
+ create = not os.path.isdir(full_dir)
+ if create:
+ os.makedirs(full_dir)
+ try:
+ return open(fullpath, 'w')
+ except:
+ if create:
+ os.removedirs(full_dir)
+
+