add idents class and move functions

This commit is contained in:
Louis Abel 2023-03-29 01:04:44 -07:00
parent f022ed15d4
commit 5d27335c7e
Signed by: label
GPG Key ID: B37E62D143879B36
3 changed files with 107 additions and 97 deletions

View File

@ -9,6 +9,7 @@ from empanadas.util.check import (
from empanadas.util.shared import ( from empanadas.util.shared import (
Shared, Shared,
ArchCheck, ArchCheck,
Idents,
) )
from empanadas.util.dnf_utils import ( from empanadas.util.dnf_utils import (

View File

@ -35,7 +35,7 @@ import productmd.treeinfo
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
from empanadas.common import Color, _rootdir from empanadas.common import Color, _rootdir
from empanadas.util import Shared, ArchCheck from empanadas.util import Shared, ArchCheck, Idents
class IsoBuild: class IsoBuild:
""" """
@ -516,7 +516,7 @@ class IsoBuild:
discname = f'{self.shortname}-{self.major_version}.{self.minor_version}{rclevel}-{arch}-boot.iso' discname = f'{self.shortname}-{self.major_version}.{self.minor_version}{rclevel}-{arch}-boot.iso'
isobootpath = os.path.join(iso_to_go, discname) isobootpath = os.path.join(iso_to_go, discname)
manifest = f'{isoboothpath}.manifest' manifest = f'{isobootpath}.manifest'
link_name = f'{self.shortname}-{arch}-boot.iso' link_name = f'{self.shortname}-{arch}-boot.iso'
link_manifest = link_name + '.manifest' link_manifest = link_name + '.manifest'
latest_link_name = f'{self.shortname}-{self.major_version}-latest-{arch}-boot.iso' latest_link_name = f'{self.shortname}-{self.major_version}-latest-{arch}-boot.iso'
@ -1209,12 +1209,12 @@ class IsoBuild:
if isinstance(p, dict): if isinstance(p, dict):
tree = p tree = p
else: else:
tree = self._scanning(p) tree = Idents.scanning(p)
result = self._merging(result, tree) result = Idents.merging(result, tree)
for p in exclusive_paths: for p in exclusive_paths:
tree = self._scanning(p) tree = Idents.scanning(p)
result = self._merging(result, tree, exclusive=True) result = Idents.merging(result, tree, exclusive=True)
# Resolves possible symlinks # Resolves possible symlinks
for key in result.keys(): for key in result.keys():
@ -1260,7 +1260,7 @@ class IsoBuild:
# the boot.iso manifest to exclude a file # the boot.iso manifest to exclude a file
if self.iso_map['xorrisofs']: if self.iso_map['xorrisofs']:
fx = open(xorrspath, "w") fx = open(xorrspath, "w")
for zm in sorted(result, key=self._sorting): for zm in sorted(result, key=Idents.sorting):
found = False found = False
replace = False replace = False
for upda in update: for upda in update:
@ -1282,7 +1282,7 @@ class IsoBuild:
fh = open(filepath, "w") fh = open(filepath, "w")
self.log.info(Color.WARN + 'Nothing should be excluded in legacy ' + self.log.info(Color.WARN + 'Nothing should be excluded in legacy ' +
'genisoimage. Ignoring exclude list.') 'genisoimage. Ignoring exclude list.')
for zl in sorted(result, key=self._sorting): for zl in sorted(result, key=Idents.sorting):
#found = False #found = False
#for excl in exclude: #for excl in exclude:
# if fnmatch(zl, excl): # if fnmatch(zl, excl):
@ -1293,94 +1293,6 @@ class IsoBuild:
fh.write("%s=%s\n" % (zl, u[zl])) fh.write("%s=%s\n" % (zl, u[zl]))
fh.close() fh.close()
def _scanning(self, p):
"""
Scan tree
"""
path = os.path.abspath(p)
result = {}
for root, dirs, files in os.walk(path):
for file in files:
abspath = os.path.join(root, file)
relpath = kobo.shortcuts.relative_path(abspath, path.rstrip("/") + "/")
result[relpath] = abspath
# Include empty directories too
if root != path:
abspath = os.path.join(root, "")
relpath = kobo.shortcuts.relative_path(abspath, path.rstrip("/") + "/")
result[relpath] = abspath
return result
def _merging(self, tree_a, tree_b, exclusive=False):
"""
Merge tree
"""
result = tree_b.copy()
all_dirs = set(
[os.path.dirname(dirn).rstrip("/") for dirn in result if os.path.dirname(dirn) != ""]
)
for dirn in tree_a:
dn = os.path.dirname(dirn)
if exclusive:
match = False
for x in all_dirs:
if dn == x or dn.startswith("%s/" % x):
match = True
break
if match:
continue
if dirn in result:
continue
result[dirn] = tree_a[dirn]
return result
def _sorting(self, k):
"""
Sorting using the is_rpm and is_image funcs. Images are first, extras
next, rpm's last.
"""
rolling = (0 if self._is_image(k) else 2 if self._is_rpm(k) else 1, k)
return rolling
def _is_rpm(self, k):
"""
Is this an RPM? :o
"""
result = k.endswith(".rpm")
return result
def _is_image(self, k):
"""
Is this an image? :o
"""
if (
k.startswith("images/") or
k.startswith("isolinux/") or
k.startswith("EFI/") or
k.startswith("etc/") or
k.startswith("ppc/")
):
return True
if (
k.endswith(".img") or
k.endswith(".ins")
):
return True
return False
def _get_vol_id(self):
"""
Gets a volume ID
"""
def run_pull_generic_images(self): def run_pull_generic_images(self):
""" """
Pulls generic images built in peridot and places them where they need Pulls generic images built in peridot and places them where they need

View File

@ -1159,7 +1159,7 @@ class Shared:
""" """
This is for normal dnf syncs. This is very slow. This is for normal dnf syncs. This is very slow.
""" """
cmd = Shared.reposync_cmd() cmd = Shared.reposync_cmd(logger)
sync_single_arch = False sync_single_arch = False
arches_to_sync = data.arches arches_to_sync = data.arches
if arch: if arch:
@ -1261,3 +1261,100 @@ class Shared:
) )
logger.info('Syncing complete') logger.info('Syncing complete')
class Idents:
"""
Identifiers or locators
"""
@staticmethod
def scanning(p):
"""
Scan tree
"""
path = os.path.abspath(p)
result = {}
for root, dirs, files in os.walk(path):
for file in files:
abspath = os.path.join(root, file)
relpath = kobo.shortcuts.relative_path(abspath, path.rstrip("/") + "/")
result[relpath] = abspath
# Include empty directories too
if root != path:
abspath = os.path.join(root, "")
relpath = kobo.shortcuts.relative_path(abspath, path.rstrip("/") + "/")
result[relpath] = abspath
return result
@staticmethod
def merging(tree_a, tree_b, exclusive=False):
"""
Merge tree
"""
result = tree_b.copy()
all_dirs = set(
[os.path.dirname(dirn).rstrip("/") for dirn in result if os.path.dirname(dirn) != ""]
)
for dirn in tree_a:
dn = os.path.dirname(dirn)
if exclusive:
match = False
for x in all_dirs:
if dn == x or dn.startswith("%s/" % x):
match = True
break
if match:
continue
if dirn in result:
continue
result[dirn] = tree_a[dirn]
return result
@staticmethod
def sorting(k):
"""
Sorting using the is_rpm and is_image funcs. Images are first, extras
next, rpm's last.
"""
rolling = (0 if Idents.is_image(k) else 2 if Idents.is_rpm(k) else 1, k)
return rolling
@staticmethod
def is_rpm(k):
"""
Is this an RPM? :o
"""
result = k.endswith(".rpm")
return result
@staticmethod
def is_image(k):
"""
Is this an image? :o
"""
if (
k.startswith("images/") or
k.startswith("isolinux/") or
k.startswith("EFI/") or
k.startswith("etc/") or
k.startswith("ppc/")
):
return True
if (
k.endswith(".img") or
k.endswith(".ins")
):
return True
return False
@staticmethod
def get_vol_id(opts):
"""
Gets a volume ID
"""