start using templates for reposync

This commit is contained in:
Louis Abel 2022-06-11 10:49:37 -07:00
parent 6c25a81241
commit b376c168bb
Signed by untrusted user: label
GPG Key ID: B37E62D143879B36
5 changed files with 78 additions and 52 deletions

View File

@ -12,5 +12,5 @@ r = Checks(rlvars, config['arch'])
r.check_valid_arch() r.check_valid_arch()
#a = RepoSync(rlvars, config, major="9", repo="ResilientStorage", parallel=True, ignore_debug=False, ignore_source=False) #a = RepoSync(rlvars, config, major="9", repo="ResilientStorage", parallel=True, ignore_debug=False, ignore_source=False)
a = RepoSync(rlvars, config, major="9", repo="ResilientStorage", parallel=True, ignore_debug=False, ignore_source=False) a = RepoSync(rlvars, config, major="9", repo="ResilientStorage", parallel=True, ignore_debug=False, ignore_source=False, hashed=True)
a.run() #a.run()

View File

@ -0,0 +1,20 @@
{%- for repo in repos -%}
[{{ repo.name }}]
name={{repo.name}}
baseurl={{ repo.baseurl }}
enabled=1
gpgcheck=0
[{{ repo.name }}-debug]
name={{repo.name}}
baseurl={{ repo.baseurl }}-debug
enabled=1
gpgcheck=0
[{{ repo.name }}-source]
name={{repo.name}}
baseurl={{ repo.srcbaseurl }}
enabled=1
gpgcheck=0
{% endfor %}

View File

@ -0,0 +1,4 @@
#!/bin/bash
set -o pipefail
{{ dnf_plugin_cmd }}
{{ sync_cmd }}

View File

@ -0,0 +1,5 @@
#!/bin/bash
set -o pipefail
{{ arch_force_cp }}
{{ dnf_plugin_cmd }}
{{ sync_cmd }}

View File

@ -14,6 +14,7 @@ import time
import re import re
#import pipes #import pipes
from common import Color from common import Color
from jinja2 import Environment, FileSystemLoader
#HAS_LIBREPO = True #HAS_LIBREPO = True
#try: #try:
@ -73,6 +74,10 @@ class RepoSync:
self.repo = repo self.repo = repo
self.extra_files = rlvars['extra_files'] self.extra_files = rlvars['extra_files']
# Templates
file_loader = FileSystemLoader('templates')
self.tmplenv = Environment(loader=file_loader)
# each el can have its own designated container to run stuff in, # each el can have its own designated container to run stuff in,
# otherwise we'll just default to the default config. # otherwise we'll just default to the default config.
self.container = config['container'] self.container = config['container']
@ -300,18 +305,22 @@ class RepoSync:
a a
)) ))
sync_log = ("{}/{}-{}-{}.log").format(
log_root,
repo_name,
a,
self.date_stamp
)
sync_cmd = ("/usr/bin/dnf reposync -c {}.{} --download-metadata " sync_cmd = ("/usr/bin/dnf reposync -c {}.{} --download-metadata "
"--repoid={} -p {} --forcearch {} --norepopath 2>&1 " "--repoid={} -p {} --forcearch {} --norepopath 2>&1 "
"| tee -a {}/{}-{}-{}.log").format( "| tee -a {}").format(
self.dnf_config, self.dnf_config,
a, a,
r, r,
os_sync_path, os_sync_path,
a, a,
log_root, sync_log,
repo_name,
a,
self.date_stamp
) )
debug_sync_cmd = ("/usr/bin/dnf reposync -c {}.{} " debug_sync_cmd = ("/usr/bin/dnf reposync -c {}.{} "
@ -345,20 +354,25 @@ class RepoSync:
self.date_stamp self.date_stamp
) )
sync_template = self.tmplenv.get_template('reposync.tmpl')
sync_output = sync_template.render(
arch_force_cp=arch_force_cp,
dnf_plugin_cmd=dnf_plugin_cmd,
sync_cmd=sync_cmd
)
debug_sync_template = self.tmplenv.get_template('reposync.tmpl')
debug_sync_output = debug_sync_template.render(
arch_force_cp=arch_force_cp,
dnf_plugin_cmd=debug_dnf_plugin_cmd,
sync_cmd=debug_sync_cmd
)
entry_point_open = open(entry_point_sh, "w+") entry_point_open = open(entry_point_sh, "w+")
debug_entry_point_open = open(debug_entry_point_sh, "w+") debug_entry_point_open = open(debug_entry_point_sh, "w+")
entry_point_open.write('#!/bin/bash\n') entry_point_open.write(sync_output)
entry_point_open.write('set -o pipefail\n') debug_entry_point_open.write(debug_sync_output)
entry_point_open.write(arch_force_cp + '\n')
entry_point_open.write(dnf_plugin_cmd + '\n')
entry_point_open.write(sync_cmd + '\n')
debug_entry_point_open.write('#!/bin/bash\n')
debug_entry_point_open.write('set -o pipefail\n')
debug_entry_point_open.write(arch_force_cp + '\n')
debug_entry_point_open.write(debug_dnf_plugin_cmd + '\n')
debug_entry_point_open.write(debug_sync_cmd + '\n')
entry_point_open.close() entry_point_open.close()
debug_entry_point_open.close() debug_entry_point_open.close()
@ -400,11 +414,14 @@ class RepoSync:
self.date_stamp self.date_stamp
) )
source_sync_template = self.tmplenv.get_template('reposync-src.tmpl')
source_sync_output = source_sync_template.render(
dnf_plugin_cmd=source_dnf_plugin_cmd,
sync_cmd=source_sync_cmd
)
source_entry_point_open = open(source_entry_point_sh, "w+") source_entry_point_open = open(source_entry_point_sh, "w+")
source_entry_point_open.write('#!/bin/bash\n') source_entry_point_open.write(source_sync_output)
source_entry_point_open.write('set -o pipefail\n')
source_entry_point_open.write(source_dnf_plugin_cmd + '\n')
source_entry_point_open.write(source_sync_cmd + '\n')
source_entry_point_open.close() source_entry_point_open.close()
os.chmod(source_entry_point_sh, 0o755) os.chmod(source_entry_point_sh, 0o755)
@ -545,11 +562,9 @@ class RepoSync:
if not os.path.exists(dest_path): if not os.path.exists(dest_path):
os.makedirs(dest_path, exist_ok=True) os.makedirs(dest_path, exist_ok=True)
config_file = open(fname, "w+") config_file = open(fname, "w+")
repolist = []
for repo in self.repos: for repo in self.repos:
#if 'all' in repo:
# prehashed = ''
constructed_url = '{}/{}/repo/{}{}/$basearch'.format( constructed_url = '{}/{}/repo/{}{}/$basearch'.format(
self.repo_base_url, self.repo_base_url,
self.project_id, self.project_id,
@ -557,13 +572,6 @@ class RepoSync:
repo, repo,
) )
constructed_url_debug = '{}/{}/repo/{}{}/$basearch-debug'.format(
self.repo_base_url,
self.project_id,
prehashed,
repo,
)
constructed_url_src = '{}/{}/repo/{}{}/src'.format( constructed_url_src = '{}/{}/repo/{}{}/src'.format(
self.repo_base_url, self.repo_base_url,
self.project_id, self.project_id,
@ -571,27 +579,16 @@ class RepoSync:
repo, repo,
) )
# normal repodata = {
config_file.write('[%s]\n' % repo) 'name': repo,
config_file.write('name=%s\n' % repo) 'baseurl': constructed_url,
config_file.write('baseurl=%s\n' % constructed_url) 'srcbaseurl': constructed_url_src
config_file.write("enabled=1\n") }
config_file.write("gpgcheck=0\n\n") repolist.append(repodata)
# debug
config_file.write('[%s-debug]\n' % repo)
config_file.write('name=%s debug\n' % repo)
config_file.write('baseurl=%s\n' % constructed_url_debug)
config_file.write("enabled=1\n")
config_file.write("gpgcheck=0\n\n")
# src
config_file.write('[%s-source]\n' % repo)
config_file.write('name=%s source\n' % repo)
config_file.write('baseurl=%s\n' % constructed_url_src)
config_file.write("enabled=1\n")
config_file.write("gpgcheck=0\n\n")
template = self.tmplenv.get_template('repoconfig.tmpl')
output = template.render(repos=repolist)
config_file.write(output)
config_file.close() config_file.close()
return fname return fname