~james-page/merge-o-matic/ubuntu-opnestack

« back to all changes in this revision

Viewing changes to momlib.py

  • Committer: Colin Watson
  • Date: 2016-11-18 21:42:52 UTC
  • Revision ID: cjwatson@canonical.com-20161118214252-tdd66o1pxu10wuji
Encapsulate atomic file writing in an AtomicFile context manager.

Show diffs side-by-side

added added

removed removed

Lines of Context:
380
380
        return
381
381
 
382
382
    logging.info("Updating %s", tree.subdir(ROOT, filename))
383
 
    with open("%s.new" % filename, "w") as sources:
 
383
    with tree.AtomicFile(filename) as sources:
384
384
        shell.run(("apt-ftparchive", "sources", pooldir), chdir=ROOT,
385
385
                  stdout=sources)
386
 
    os.rename("%s.new" % filename, filename)
387
386
 
388
387
def get_pool_sources(distro, package):
389
388
    """Parse the Sources file for a package in the pool."""
709
708
def write_rss(filename, rss):
710
709
    """Write out an RSS feed."""
711
710
    ensure(filename)
712
 
    tree = ElementTree.ElementTree(rss)
713
 
    tree.write(filename + ".new")
714
 
    os.rename(filename + ".new", filename)
 
711
    etree = ElementTree.ElementTree(rss)
 
712
    with tree.AtomicFile(filename) as fd:
 
713
        etree.write(fd)
715
714
 
716
715
def append_rss(rss, title, link, author=None, filename=None):
717
716
    """Append an element to an RSS feed."""