Blob Blame History Raw
From 9d02d75f09b8e6612acb22eb0a9777df63397730 Mon Sep 17 00:00:00 2001
From: Jan Dobes <jdobes@redhat.com>
Date: Thu, 12 Oct 2017 10:20:54 +0200
Subject: [PATCH 18/18] adapt setup.py for both py2 and py3

(cherry picked from commit 84ef184850f29638f07d2540a9ec35b4fb6c5095)

Conflicts:
  setup.py
---
 setup.py | 376 ++++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 203 insertions(+), 173 deletions(-)

diff --git a/setup.py b/setup.py
index 045abd7..38ee962 100644
--- a/setup.py
+++ b/setup.py
@@ -4,12 +4,13 @@ import sys
 import os.path
 from distutils.core import setup, Extension
 import string
-import yaml # PyYAML
+if sys.version_info[0] == 2:
+    import yaml # PyYAML
+    import Cheetah.Template as Template
 try:
     import subprocess
 except:
     import cobbler.sub_process as subprocess
-import Cheetah.Template as Template
 import time
 
 VERSION = "2.0.7"
@@ -67,63 +68,64 @@ def gen_config():
     templatify(MODULES_TEMPLATE, defaults, os.path.join(OUTPUT_DIR, "modules.conf"))
     templatify(SETTINGS_TEMPLATE, defaults, os.path.join(OUTPUT_DIR, "settings"))
 
-if __name__ == "__main__":
+
+def py2_setup():
     gen_build_version()
     gen_config()
 
     # etc configs
-    etcpath     = "/etc/cobbler"
-    initpath    = "/etc/init.d"
-    rotpath       = "/etc/logrotate.d"
-    powerpath   = etcpath + "/power"
-    pxepath     = etcpath + "/pxe"
-    reppath     = etcpath + "/reporting"
-    zonepath    = etcpath + "/zone_templates"
+    etcpath = "/etc/cobbler"
+    initpath = "/etc/init.d"
+    rotpath = "/etc/logrotate.d"
+    powerpath = etcpath + "/power"
+    pxepath = etcpath + "/pxe"
+    reppath = etcpath + "/reporting"
+    zonepath = etcpath + "/zone_templates"
 
     # lib paths
-    libpath     = "/var/lib/cobbler"
-    backpath    = libpath + "/backup"
-    trigpath    = libpath + "/triggers"
+    libpath = "/var/lib/cobbler"
+    backpath = libpath + "/backup"
+    trigpath = libpath + "/triggers"
     snippetpath = libpath + "/snippets"
-    kickpath    = libpath + "/kickstarts"
-    dbpath      = libpath + "/config"
-    loadpath    = libpath + "/loaders"
+    kickpath = libpath + "/kickstarts"
+    dbpath = libpath + "/config"
+    loadpath = libpath + "/loaders"
 
     # share paths
-    sharepath   = "/usr/share/cobbler"
-    itemplates  = sharepath + "/installer_templates"
-    wwwtmpl     = sharepath + "/webui_templates"
-    manpath     = "share/man/man1"
-    spool_koan  = "/var/spool/koan"
+    sharepath = "/usr/share/cobbler"
+    itemplates = sharepath + "/installer_templates"
+    wwwtmpl = sharepath + "/webui_templates"
+    manpath = "share/man/man1"
+    spool_koan = "/var/spool/koan"
 
     # www paths
-    wwwpath  = "/var/www/cobbler"
+    wwwpath = "/var/www/cobbler"
     if os.path.exists("/etc/SuSE-release"):
-        wwwconf  = "/etc/apache2/conf.d"
+        wwwconf = "/etc/apache2/conf.d"
     elif os.path.exists("/etc/debian_version"):
-        wwwconf  = "/etc/apache2/conf.d"
+        wwwconf = "/etc/apache2/conf.d"
     else:
-        wwwconf  = "/etc/httpd/conf.d"
+        wwwconf = "/etc/httpd/conf.d"
 
-    wwwcon   = "/var/www/cobbler_webui_content"
+    wwwcon = "/var/www/cobbler_webui_content"
     vw_localmirror = wwwpath + "/localmirror"
-    vw_kickstarts  = wwwpath + "/kickstarts"
-    vw_kickstarts_sys  = wwwpath + "/kickstarts_sys"
+    vw_kickstarts = wwwpath + "/kickstarts"
+    vw_kickstarts_sys = wwwpath + "/kickstarts_sys"
     vw_repomirror = wwwpath + "/repo_mirror"
-    vw_ksmirror   = wwwpath + "/ks_mirror"
-    vw_ksmirrorc  = wwwpath + "/ks_mirror/config"
-    vw_images     = wwwpath + "/images"
-    vw_distros    = wwwpath + "/distros"
-    vw_systems    = wwwpath + "/systems"
-    vw_profiles   = wwwpath + "/profiles"
-    vw_links      = wwwpath + "/links"
-    vw_aux        = wwwpath + "/aux"
-    modpython     = wwwpath + "/web"
-    modwsgisvc    = wwwpath + "/svc"
-    modpythonsvc  = modwsgisvc
+    vw_ksmirror = wwwpath + "/ks_mirror"
+    vw_ksmirrorc = wwwpath + "/ks_mirror/config"
+    vw_images = wwwpath + "/images"
+    vw_distros = wwwpath + "/distros"
+    vw_systems = wwwpath + "/systems"
+    vw_profiles = wwwpath + "/profiles"
+    vw_links = wwwpath + "/links"
+    vw_aux = wwwpath + "/aux"
+    modpython = wwwpath + "/web"
+    modwsgisvc = wwwpath + "/svc"
+    modpythonsvc = modwsgisvc
 
     # log paths
-    logpath  = "/var/log/cobbler"
+    logpath = "/var/log/cobbler"
     logpath2 = logpath + "/kicklog"
     logpath3 = logpath + "/syslog"
     logpath4 = "/var/log/httpd/cobbler"
@@ -132,123 +134,123 @@ if __name__ == "__main__":
     logpath7 = logpath + "/tasks"
 
     # django content
-    dj_config    = "/etc/httpd/conf.d/"
+    dj_config = "/etc/httpd/conf.d/"
     dj_templates = "/usr/share/cobbler/web/cobbler_web/templates"
-    dj_webui     = "/usr/share/cobbler/web/cobbler_web"
-    dj_webui2    = "/usr/share/cobbler/web/cobbler_web/templatetags"
-    dj_webui_proj= "/usr/share/cobbler/web"
-    dj_sessions  = "/var/lib/cobbler/webui_sessions"
-    dj_js        = "/var/www/cobbler_webui_content/"
+    dj_webui = "/usr/share/cobbler/web/cobbler_web"
+    dj_webui2 = "/usr/share/cobbler/web/cobbler_web/templatetags"
+    dj_webui_proj = "/usr/share/cobbler/web"
+    dj_sessions = "/var/lib/cobbler/webui_sessions"
+    dj_js = "/var/www/cobbler_webui_content/"
 
     setup(
         name="cobbler",
-        version = VERSION,
-        author = "Michael DeHaan",
-        author_email = "mdehaan@redhat.com",
-        url = "http://fedorahosted.org/cobbler/",
-        license = "GPL",
-        packages = [
+        version=VERSION,
+        author="Michael DeHaan",
+        author_email="mdehaan@redhat.com",
+        url="http://fedorahosted.org/cobbler/",
+        license="GPL",
+        packages= [
             "cobbler",
             "cobbler/modules",
             "koan"
         ],
-        scripts = [
+        scripts=[
             "scripts/cobbler",
             "scripts/cobblerd",
             "scripts/cobbler-ext-nodes",
             "scripts/koan",
             "scripts/cobbler-register"
         ],
-        data_files = [
+        data_files=[
             (modpythonsvc, ['scripts/services.py']),
-            (modwsgisvc,   ['scripts/services.wsgi']),
+            (modwsgisvc, ['scripts/services.wsgi']),
 
             # miscellaneous config files
-            (rotpath,  ['config/cobblerd_rotate']),
-            (wwwconf,  ['config/cobbler.conf']),
-            (wwwconf,  ['config/cobbler_wsgi.conf']),
-            (libpath,  ['config/cobbler_hosts']),
-            (etcpath,  ['config/modules.conf']),
-            (etcpath,  ['config/users.digest']),
-            (etcpath,  ['config/rsync.exclude']),
-            (etcpath,  ['config/users.conf']),
-            (etcpath,  ['config/cheetah_macros']),
+            (rotpath, ['config/cobblerd_rotate']),
+            (wwwconf, ['config/cobbler.conf']),
+            (wwwconf, ['config/cobbler_wsgi.conf']),
+            (libpath, ['config/cobbler_hosts']),
+            (etcpath, ['config/modules.conf']),
+            (etcpath, ['config/users.digest']),
+            (etcpath, ['config/rsync.exclude']),
+            (etcpath, ['config/users.conf']),
+            (etcpath, ['config/cheetah_macros']),
             (initpath, ['config/cobblerd']),
-            (etcpath,  ['config/settings']),
+            (etcpath, ['config/settings']),
 
             # django webui content
-            (dj_config,    [ 'config/cobbler_web.conf' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/blank.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/empty.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/enoaccess.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/error_page.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/header.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/index.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/item.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/ksfile_edit.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/ksfile_list.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/snippet_edit.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/snippet_list.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/master.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/message.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/paginate.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/settings.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/generic_edit.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/generic_list.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/generic_delete.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/generic_rename.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/events.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/eventlog.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/import.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/task_created.tmpl' ]),
-            (dj_templates, [ 'web/cobbler_web/templates/check.tmpl' ]),
+            (dj_config, ['config/cobbler_web.conf']),
+            (dj_templates, ['web/cobbler_web/templates/blank.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/empty.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/enoaccess.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/error_page.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/header.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/index.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/item.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/ksfile_edit.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/ksfile_list.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/snippet_edit.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/snippet_list.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/master.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/message.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/paginate.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/settings.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/generic_edit.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/generic_list.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/generic_delete.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/generic_rename.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/events.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/eventlog.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/import.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/task_created.tmpl']),
+            (dj_templates, ['web/cobbler_web/templates/check.tmpl']),
 
             # django code, private to cobbler-web application
-            (dj_webui,       [ 'web/cobbler_web/__init__.py' ]),
-            (dj_webui_proj,  [ 'web/__init__.py' ]),
-            (dj_webui_proj,  [ 'web/urls.py' ]),
-            (dj_webui_proj,  [ 'web/manage.py' ]),
-            (dj_webui_proj,  [ 'web/settings.py' ]),
-            (dj_webui,       [ 'web/cobbler_web/urls.py' ]),
-            (dj_webui,       [ 'web/cobbler_web/views.py' ]),
-            (dj_webui2,      [ 'web/cobbler_web/templatetags/site.py' ]),
-            (dj_webui2,      [ 'web/cobbler_web/templatetags/__init__.py' ]),
-            (dj_sessions,  []),
+            (dj_webui, ['web/cobbler_web/__init__.py']),
+            (dj_webui_proj, ['web/__init__.py']),
+            (dj_webui_proj, ['web/urls.py']),
+            (dj_webui_proj, ['web/manage.py']),
+            (dj_webui_proj, ['web/settings.py']),
+            (dj_webui, ['web/cobbler_web/urls.py']),
+            (dj_webui, ['web/cobbler_web/views.py']),
+            (dj_webui2, ['web/cobbler_web/templatetags/site.py']),
+            (dj_webui2, ['web/cobbler_web/templatetags/__init__.py']),
+            (dj_sessions, []),
 
             # backups for upgrades
             (backpath, []),
 
             # for --version support across distros
-            (libpath,  ['config/version']),
+            (libpath, ['config/version']),
 
             # bootloaders and syslinux support files
             # we only package zpxe.rexx because it's source
             # user supplies the others
-            (loadpath,  ['scripts/zpxe.rexx']),
+            (loadpath, ['scripts/zpxe.rexx']),
 
             # database/serializer
-            (dbpath + "/distros.d",  []),
+            (dbpath + "/distros.d", []),
             (dbpath + "/profiles.d", []),
-            (dbpath + "/systems.d",  []),
-            (dbpath + "/repos.d",    []),
-            (dbpath + "/images.d",   []),
+            (dbpath + "/systems.d", []),
+            (dbpath + "/repos.d", []),
+            (dbpath + "/images.d", []),
 
             # sample kickstart files
-            (kickpath,  ['kickstarts/legacy.ks']),
-            (kickpath,  ['kickstarts/sample.ks']),
-            (kickpath,  ['kickstarts/sample_end.ks']),
-            (kickpath,  ['kickstarts/default.ks']),
-            (kickpath,  ['kickstarts/pxerescue.ks']),
+            (kickpath, ['kickstarts/legacy.ks']),
+            (kickpath, ['kickstarts/sample.ks']),
+            (kickpath, ['kickstarts/sample_end.ks']),
+            (kickpath, ['kickstarts/default.ks']),
+            (kickpath, ['kickstarts/pxerescue.ks']),
 
             # seed files for debian
-            (kickpath,  ['kickstarts/sample.seed']),
+            (kickpath, ['kickstarts/sample.seed']),
 
             # templates for DHCP, DNS, TFTP, RSYNC
-            (etcpath,  ['templates/dhcp.template']),
-            (etcpath,  ['templates/dnsmasq.template']),
-            (etcpath,  ['templates/named.template']),
-            (etcpath,  ['templates/zone.template']),
-            (etcpath,  ['templates/rsync.template']),
+            (etcpath, ['templates/dhcp.template']),
+            (etcpath, ['templates/dnsmasq.template']),
+            (etcpath, ['templates/named.template']),
+            (etcpath, ['templates/zone.template']),
+            (etcpath, ['templates/rsync.template']),
 
             # templates for netboot configs
             (pxepath,  ['templates/pxedefault.template']),
@@ -283,7 +285,7 @@ if __name__ == "__main__":
             (powerpath, ['templates/power_virsh.template']),
 
             # templates for reporting
-            (reppath,   ['templates/build_report_email.template']),
+            (reppath, ['templates/build_report_email.template']),
 
             # templates for setup
             (itemplates, ['installer_templates/modules.conf.template']),
@@ -313,12 +315,12 @@ if __name__ == "__main__":
             (snippetpath, ['snippets/log_ks_post']),
 
             # documentation
-            (manpath,  ['docs/cobbler.1.gz']),
-            (manpath,  ['docs/koan.1.gz']),
-            (manpath,  ['docs/cobbler-register.1.gz']),
+            (manpath, ['docs/cobbler.1.gz']),
+            (manpath, ['docs/koan.1.gz']),
+            (manpath, ['docs/cobbler-register.1.gz']),
 
             # logfiles
-            (logpath,  []),
+            (logpath, []),
             (logpath2, []),
             (logpath3, []),
             (logpath4, []),
@@ -330,72 +332,100 @@ if __name__ == "__main__":
             (spool_koan, []),
 
             # web page directories that we own
-            (vw_localmirror,    []),
-            (vw_kickstarts,     []),
+            (vw_localmirror, []),
+            (vw_kickstarts, []),
             (vw_kickstarts_sys, []),
-            (vw_repomirror,     []),
-            (vw_ksmirror,       []),
-            (vw_ksmirrorc,      []),
-            (vw_distros,        []),
-            (vw_images,         []),
-            (vw_systems,        []),
-            (vw_profiles,       []),
-            (vw_links,          []),
-            (vw_aux,            []),
+            (vw_repomirror, []),
+            (vw_ksmirror, []),
+            (vw_ksmirrorc, []),
+            (vw_distros, []),
+            (vw_images, []),
+            (vw_systems, []),
+            (vw_profiles, []),
+            (vw_links, []),
+            (vw_aux, []),
 
             # zone-specific templates directory
-            (zonepath,    []),
+            (zonepath, []),
 
             # Web UI templates for object viewing & modification
             # FIXME: other templates to add as they are created.
             # slurp in whole directory?
 
             # Web UI support files
-            (wwwcon,            ['web/content/style.css']),
-            (wwwcon,            ['web/content/logo-cobbler.png']),
-            (modpython,         ['web/content/index.html']),
-            (wwwpath + "/pub",  []),
-            (dj_js,             ['web/content/cobbler.js']),
+            (wwwcon, ['web/content/style.css']),
+            (wwwcon, ['web/content/logo-cobbler.png']),
+            (modpython, ['web/content/index.html']),
+            (wwwpath + "/pub", []),
+            (dj_js, ['web/content/cobbler.js']),
             # FIXME: someday Fedora/EPEL will package these and then we should not embed them then.
-            (dj_js,             ['web/content/jquery-1.3.2.js']),
-            (dj_js,             ['web/content/jquery-1.3.2.min.js']),
-            (dj_js,             ['web/content/jsGrowl_jquery.js']),
-            (dj_js,             ['web/content/jsGrowl.js']),
-            (dj_js,             ['web/content/jsgrowl_close.png']),
-            (dj_js,             ['web/content/jsgrowl_corners.png']),
-            (dj_js,             ['web/content/jsgrowl_middle_hover.png']),
-            (dj_js,             ['web/content/jsgrowl_corners_hover.png']),
-            (dj_js,             ['web/content/jsgrowl_side_hover.png']),
-            (dj_js,             ['web/content/jsGrowl.css']),
+            (dj_js, ['web/content/jquery-1.3.2.js']),
+            (dj_js, ['web/content/jquery-1.3.2.min.js']),
+            (dj_js, ['web/content/jsGrowl_jquery.js']),
+            (dj_js, ['web/content/jsGrowl.js']),
+            (dj_js, ['web/content/jsgrowl_close.png']),
+            (dj_js, ['web/content/jsgrowl_corners.png']),
+            (dj_js, ['web/content/jsgrowl_middle_hover.png']),
+            (dj_js, ['web/content/jsgrowl_corners_hover.png']),
+            (dj_js, ['web/content/jsgrowl_side_hover.png']),
+            (dj_js, ['web/content/jsGrowl.css']),
 
             # Anamon script
-            (vw_aux,            ['aux/anamon', 'aux/anamon.init']),
+            (vw_aux, ['aux/anamon', 'aux/anamon.init']),
 
             # Directories to hold cobbler triggers
-            ("%s/add/distro/pre" % trigpath,      []),
-            ("%s/add/distro/post" % trigpath,     []),
-            ("%s/add/profile/pre" % trigpath,     []),
-            ("%s/add/profile/post" % trigpath,    []),
-            ("%s/add/system/pre" % trigpath,      []),
-            ("%s/add/system/post" % trigpath,     []),
-            ("%s/add/repo/pre" % trigpath,        []),
-            ("%s/add/repo/post" % trigpath,       []),
-            ("%s/delete/distro/pre" % trigpath,   []),
-            ("%s/delete/distro/post" % trigpath,  []),
-            ("%s/delete/profile/pre" % trigpath,  []),
+            ("%s/add/distro/pre" % trigpath, []),
+            ("%s/add/distro/post" % trigpath, []),
+            ("%s/add/profile/pre" % trigpath, []),
+            ("%s/add/profile/post" % trigpath, []),
+            ("%s/add/system/pre" % trigpath, []),
+            ("%s/add/system/post" % trigpath, []),
+            ("%s/add/repo/pre" % trigpath, []),
+            ("%s/add/repo/post" % trigpath, []),
+            ("%s/delete/distro/pre" % trigpath, []),
+            ("%s/delete/distro/post" % trigpath, []),
+            ("%s/delete/profile/pre" % trigpath, []),
             ("%s/delete/profile/post" % trigpath, []),
-            ("%s/delete/system/pre" % trigpath,   []),
-            ("%s/delete/system/post" % trigpath,  []),
-            ("%s/delete/repo/pre" % trigpath,     []),
-            ("%s/delete/repo/post" % trigpath,    []),
-            ("%s/delete/repo/post" % trigpath,    []),
-            ("%s/install/pre" % trigpath,         []),
-            ("%s/install/post" % trigpath,        []),
-            ("%s/sync/pre" % trigpath,            []),
-            ("%s/sync/post" % trigpath,           []),
-            ("%s/change" % trigpath,              [])
+            ("%s/delete/system/pre" % trigpath, []),
+            ("%s/delete/system/post" % trigpath, []),
+            ("%s/delete/repo/pre" % trigpath, []),
+            ("%s/delete/repo/post" % trigpath, []),
+            ("%s/delete/repo/post" % trigpath, []),
+            ("%s/install/pre" % trigpath, []),
+            ("%s/install/post" % trigpath, []),
+            ("%s/sync/pre" % trigpath, []),
+            ("%s/sync/post" % trigpath, []),
+            ("%s/change" % trigpath, [])
         ],
-        description = SHORT_DESC,
-        long_description = LONG_DESC
+        description=SHORT_DESC,
+        long_description=LONG_DESC
     )
 
+
+def py3_setup():
+    # Only koan is ready for Python 3
+    setup(
+        name='koan',
+        version=VERSION,
+        description=SHORT_DESC,
+        long_description=LONG_DESC,
+        author='Jan Dobes',
+        author_email='jdobes@redhat.com',
+        url='http://www.github.com/spacewalkproject',
+        packages=['koan'],
+        license='GPLv2',
+        scripts=[
+            "scripts/koan",
+            "scripts/cobbler-register"
+        ],
+    )
+
+if __name__ == "__main__":
+    if sys.version_info[0] == 3:
+        py3_setup()
+    else:
+        py2_setup()
+
+
+
+
-- 
2.5.5