=== added file 'lib/lp/archivepublisher/scripts/generate_extra_overrides.py'
--- lib/lp/archivepublisher/scripts/generate_extra_overrides.py 1970-01-01 
00:00:00 +0000
+++ lib/lp/archivepublisher/scripts/generate_extra_overrides.py 2011-12-06 
15:03:58 +0000

+class AtomicFile:
+    """Facilitate atomic writing of files."""
+
+    def __init__(self, filename):
+        self.filename = filename
+        self.fd = open('%s.new' % self.filename, 'w')
+
+    def __enter__(self):
+        return self.fd
+
+    def __exit__(self, exc_type, exc_value, exc_tb):
+        self.fd.close()
+        os.rename('%s.new' % self.filename, self.filename)

Does it make sense to put the file in place if the context exits with an 
exception?

Actually this is what I don't like about the design of python context managers: 
it puts you, as the author of a context manager, in the position where you may 
have to worry about failures in the context you manage — and yet it's easy for 
the author of the context to hide them from you.  So maybe stupid is just 
better.
-- 
https://code.launchpad.net/~cjwatson/launchpad/refactor-cron-germinate/+merge/84624
Your team Launchpad code reviewers is requested to review the proposed merge of 
lp:~cjwatson/launchpad/refactor-cron-germinate into lp:launchpad.

_______________________________________________
Mailing list: https://launchpad.net/~launchpad-reviewers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~launchpad-reviewers
More help   : https://help.launchpad.net/ListHelp

Reply via email to