config_opts['root'] = 'sdl-8-x86_64-computational-mellanox'
config_opts['target_arch'] = 'x86_64'
config_opts['legal_host_arches'] = ('x86_64',)
config_opts['chroot_setup_cmd'] = 'install tar gcc-c++ redhat-rpm-config springdale-release which xz sed make bzip2 gzip gcc coreutils unzip shadow-utils diffutils cpio bash gawk rpm-build info patch util-linux findutils grep epel-rpm-macros kernel-rpm-macros'
config_opts['dist'] = 'el8'  # only useful for --resultdir variable subst
config_opts['extra_chroot_dirs'] = [ '/run/lock', ]
config_opts['releasever'] = '8'
config_opts['package_manager'] = 'dnf'
#config_opts['module_enable'] = ['list', 'of', 'modules']
#config_opts['module_install'] = ['module1/profile', 'module2/profile']
config_opts['macros']['%rhel'] = "8"
config_opts['macros']['%dist'] = ".sdl8"
#config_opts['environment']['RHEL_ALLOW_PYTHON2_FOR_BUILD'] = '1'

config_opts['scm_opts']['git_get'] = 'git clone SCM_BRN git://golf/rpms/SCM_PKG.git SCM_PKG'
config_opts['scm_opts']['ext_src_dir_prefix'] = 'file:///data/sources'

# default stream modlues
def_modules = [ 'go-toolset-rhel8', 'httpd-2.4', 'javapackages-tools-201801', 'llvm-toolset-rhel8', 'perl-5.26',
		'mariadb-10.3', 'llvm-toolset-rhel8', 'python27-2.7',
                'python36-3.6', 'ruby-2.6', 'rust-toolset-rhel8', 'scala-2.10', 'swig-3.0', 'virt-rhel']

config_opts['files']['/etc/hosts'] = """
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
#::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
::1         localhost6 localhost6.localdomain6
128.112.129.178 ernie.princeton.edu
128.112.130.63 raas03.princeton.edu
"""
config_opts['files']['/etc/nsswitch.conf'] = """
passwd:     sss files systemd
group:      sss files systemd
netgroup:   sss files
automount:  sss files
services:   sss files
shadow:     files sss
hosts:      files dns
bootparams: files
ethers:     files
netmasks:   files
networks:   files
protocols:  files
rpc:        files
publickey:  files
aliases:    files
"""

config_opts['yum.conf'] = """
[main]
keepcache=1
debuglevel=2
reposdir=/dev/null
logfile=/var/log/yum.log
retries=20
obsoletes=1
gpgcheck=0
assumeyes=1
install_weak_deps=0
syslog_ident=mock
syslog_device=
mdpolicy=group:primary
best=1
metadata_expire=0
module_platform_id=platform:el8

[core]
name=core
gpgcheck=0
baseurl=file:///data/springdale/8/$basearch/os/BaseOS

[core-updates]
name=core-updates
gpgcheck=0
baseurl=file:///data/springdale/updates/8/BaseOS/$basearch

[appstream]
name=appstream
gpgcheck=0
baseurl=file:///data/springdale/8/$basearch/os/AppStream/Packages

[appstream-updates]
name=appstream-updates
gpgcheck=0
baseurl=file:///data/springdale/updates/8/AppStream/$basearch/Packages

[unsupported]
name=unsupported
gpgcheck=0
baseurl=/data/springdale/unsupported/8/$basearch/

[computational]
name=computational
gpgcheck=0
baseurl=/data/springdale/computational/8/$basearch/

[computational-mellanox]
name=computational-mellanox
gpgcheck=0
baseurl=/data/springdale/computational/mellanox/8/$basearch/

[buildsys]
name=buildsys
gpgcheck=0
baseurl=/data/puias/buildsys/8/os/x86_64

"""

for name,loc in [('', '/data/springdale/8/' + config_opts['target_arch'] + '/os/AppStream/'), ('updates-', '/data/springdale/updates/8/AppStream/'+config_opts['target_arch']+'/') ]:
  for onedir in os.listdir(loc):
    if onedir == 'Packages' or onedir == 'repodata':
      continue
    if config_opts['target_arch'] in loc:
      onedird = loc + onedir
    else:
      onedird = loc + onedir + '/' + config_opts['target_arch']
    if os.path.isdir(onedird):
      #print("Adding",onedird)
      config_opts['yum.conf'] += "\r\n[module-" + name + onedir.replace('+','_') + "]\r\n"
      config_opts['yum.conf'] += "name = Appstream" + name + onedir + "\r\n"
      config_opts['yum.conf'] += "baseurl = file://" + onedird + "\r\n"
      if onedir not in def_modules:
        config_opts['yum.conf'] += "enabled = 0\r\n"
      config_opts['yum.conf'] += "gpgcheck = 0\r\n"
      config_opts['yum.conf'] += "module_hotfixes = 1\r\n"
