From 643e51926cb33b020b1a5b2726239e96a754b65f Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Thu, 26 Nov 2009 09:45:03 -0500 Subject: [PATCH] Replace NamedTemporaryFile with mkstemp in invirt-build-conf and invirt-submit-build. NamedTemporaryFile lacks the delete kwarg in Python 2.5, meaning that files are always deleted when the fd is closed. svn path=/trunk/packages/invirt-dev/; revision=2567 --- invirt-build-conf | 10 ++++++---- invirt-submit-build | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/invirt-build-conf b/invirt-build-conf index 4c5039f..b7c3bdd 100755 --- a/invirt-build-conf +++ b/invirt-build-conf @@ -29,21 +29,23 @@ def main(): # Python could really use a file-like object that gets written to # a temporary path and moved to its final resting place on # .close(). Oh well. - conf = tempfile.NamedTemporaryFile(delete=False) + conf_fd, conf_name = tempfile.mkstemp() + conf = os.fdopen(conf_fd) build_handler = '/usr/sbin/invirt-submit-build' for pocket in config.git.pockets: acl = authz.expandAdmin(getattr(config.git.pockets, pocket).acl, None) - acl_fd = tempfile.NamedTemporaryFile(delete=False) + acl_fd, acl_name = tempfile.mkstemp() + acl_fd = os.fdopen(acl_fd) print >>acl_fd, '\n'.join(user(a) for a in acl) acl_path = os.path.join('/etc/remctl/acl/build-%s' % pocket) - os.rename(acl_fd.name, acl_path) + os.rename(acl_name, acl_path) print >>conf, 'build %s %s %s' % (pocket, build_handler, acl_path) - os.rename(conf, '/etc/remctl/conf.d/build') + os.rename(conf_name, '/etc/remctl/conf.d/build') if __name__ == '__main__': diff --git a/invirt-submit-build b/invirt-submit-build index caa949f..713f3da 100755 --- a/invirt-submit-build +++ b/invirt-submit-build @@ -43,9 +43,10 @@ def main(): # To keep from triggering the Invirtibuilder before we've actually # written the file out, first write the queue entry to a temporary # file, and then move it into the queue directory. - q = tempfile.NamedTemporaryFile(delete=False) + q_fd, q_name = tempfile.mkstemp() + q = os.fdopen(q_fd) print >>q, "%s %s %s %s" % (pocket, package, commit, principal) - os.rename(q.name, q_path) + os.rename(q_name, q_path) if __name__ == '__main__': -- 1.7.9.5