From 224da46b2331b582577b86c3eb707f67d57800fb Mon Sep 17 00:00:00 2001
From: chengquan <chengquan3@huawei.com>
Date: Thu, 8 Aug 2019 16:15:31 +0800
Subject: [PATCH] cloud-init: add variable to forbid tmp dir

reason: add variable to forbid temporary directory

Signed-off-by: chengquan <chengquan3@huawei.com>
---
 setup.py     |  15 ++++-
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/setup.py b/setup.py
index d332273..4272db3 100755
--- a/setup.py
+++ b/setup.py
@@ -78,6 +78,8 @@ def read_requires():
     deps = subprocess.check_output(cmd)
     return deps.decode('utf-8').splitlines()
 
+# add variable to forbid tmp dir
+num = 0
 
 def render_tmpl(template, mode=None):
     """render template into a tmpdir under same dir as setup.py
@@ -99,7 +101,10 @@ def render_tmpl(template, mode=None):
         return template
 
     topdir = os.path.dirname(sys.argv[0])
-    tmpd = tempfile.mkdtemp(dir=topdir, prefix=RENDERED_TMPD_PREFIX)
+    global num
+    os.mkdir(topdir + str(num))
+    tmpd = os.path.abspath(topdir + str(num))
+    num = num + 1
     atexit.register(shutil.rmtree, tmpd)
     bname = os.path.basename(template).rstrip(tmpl_ext)
     fpath = os.path.join(tmpd, bname)
@@ -114,6 +119,9 @@ def render_tmpl(template, mode=None):
     # return path relative to setup.py
     return os.path.join(os.path.basename(tmpd), bname)
 
+def sort_files(file_list):
+    file_list.sort()
+    return file_list
 
 # User can set the variant for template rendering
 if '--distro' in sys.argv:
@@ -130,10 +138,10 @@ INITSYS_FILES = {
     'sysvinit_openrc': [f for f in glob('sysvinit/gentoo/*') if is_f(f)],
     'sysvinit_suse': [f for f in glob('sysvinit/suse/*') if is_f(f)],
     'systemd': [render_tmpl(f)
-                for f in (glob('systemd/*.tmpl') +
+                for f in sort_files((glob('systemd/*.tmpl') +
                           glob('systemd/*.service') +
                           glob('systemd/*.socket') +
-                          glob('systemd/*.target'))
+                          glob('systemd/*.target')))
                 if (is_f(f) and not is_generator(f))],
     'systemd.generators': [
         render_tmpl(f, mode=0o755)
-- 
1.8.3.1

