Commit 6b34cb9 Revert "refactor metadata.py to use productmd's compose.dump for composeinfo"

1 file Authored by dmach 2 years ago , Committed by Adam Miller 2 years ago ,
Revert "refactor metadata.py to use productmd's compose.dump for composeinfo"

This reverts commit 40b8ccb3acdc7dd869e4aa32f1ad672ff01bd0ea.

    
  1 @@ -14,6 +14,7 @@
  2   # along with this program; if not, write to the Free Software
  3   # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  4   
  5 + 
  6   import os
  7   import time
  8   
  9 @@ -60,8 +61,102 @@
 10       description = get_description(compose, variant, arch)
 11       return create_media_repo(path, description, timestamp)
 12   
 13 + 
 14 + def compose_to_composeinfo(compose):
 15 +     ci = productmd.composeinfo.ComposeInfo()
 16 + 
 17 +     # compose
 18 +     ci.compose.id = compose.compose_id
 19 +     ci.compose.type = compose.compose_type
 20 +     ci.compose.date = compose.compose_date
 21 +     ci.compose.respin = compose.compose_respin
 22 +     ci.compose.label = compose.compose_label
 23 + 
 24 +     # product
 25 +     ci.product.name = compose.conf["product_name"]
 26 +     ci.product.version = compose.conf["product_version"]
 27 +     ci.product.short = compose.conf["product_short"]
 28 +     ci.product.is_layered = compose.conf.get("product_is_layered", False)
 29 + 
 30 +     # base product
 31 +     if ci.product.is_layered:
 32 +         ci.base_product.name = compose.conf["base_product_name"]
 33 +         ci.base_product.version = compose.conf["base_product_version"]
 34 +         ci.base_product.short = compose.conf["base_product_short"]
 35 + 
 36 +     def dump_variant(variant, parent=None):
 37 +         var = productmd.composeinfo.Variant(ci)
 38 + 
 39 +         tree_arches = compose.conf.get("tree_arches", None)
 40 +         if tree_arches and not (set(variant.arches) & set(tree_arches)):
 41 +             return None
 42 + 
 43 +         # variant details
 44 +         var.id = variant.id
 45 +         var.uid = variant.uid
 46 +         var.name = variant.name
 47 +         var.type = variant.type
 48 +         var.arches = set(variant.arches)
 49 + 
 50 +         if var.type == "layered-product":
 51 +             var.product.name = variant.product_name
 52 +             var.product.short = variant.product_short
 53 +             var.product.version = variant.product_version
 54 +             var.product.is_layered = True
 55 + 
 56 +         for arch in variant.arches:
 57 +             # paths: binaries
 58 +             var.os_tree[arch] = relative_path(compose.paths.compose.os_tree(arch=arch, variant=variant, create_dir=False).rstrip("/") + "/", compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 59 +             var.repository[arch] = relative_path(compose.paths.compose.repository(arch=arch, variant=variant, create_dir=False).rstrip("/") + "/", compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 60 +             var.packages[arch] = relative_path(compose.paths.compose.packages(arch=arch, variant=variant, create_dir=False).rstrip("/") + "/", compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 61 +             iso_dir = compose.paths.compose.iso_dir(arch=arch, variant=variant, create_dir=False) or ""
 62 +             if iso_dir and os.path.isdir(os.path.join(compose.paths.compose.topdir(), iso_dir)):
 63 +                 var.isos[arch] = relative_path(iso_dir, compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 64 +             jigdo_dir = compose.paths.compose.jigdo_dir(arch=arch, variant=variant, create_dir=False) or ""
 65 +             if jigdo_dir and os.path.isdir(os.path.join(compose.paths.compose.topdir(), jigdo_dir)):
 66 +                 var.jigdos[arch] = relative_path(jigdo_dir, compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 67 + 
 68 +             # paths: sources
 69 +             var.source_tree[arch] = relative_path(compose.paths.compose.os_tree(arch="source", variant=variant, create_dir=False).rstrip("/") + "/", compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 70 +             var.source_repository[arch] = relative_path(compose.paths.compose.repository(arch="source", variant=variant, create_dir=False).rstrip("/") + "/", compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 71 +             var.source_packages[arch] = relative_path(compose.paths.compose.packages(arch="source", variant=variant, create_dir=False).rstrip("/") + "/", compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 72 +             source_iso_dir = compose.paths.compose.iso_dir(arch="source", variant=variant, create_dir=False) or ""
 73 +             if source_iso_dir and os.path.isdir(os.path.join(compose.paths.compose.topdir(), source_iso_dir)):
 74 +                 var.source_isos[arch] = relative_path(source_iso_dir, compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 75 +             source_jigdo_dir = compose.paths.compose.jigdo_dir(arch="source", variant=variant, create_dir=False) or ""
 76 +             if source_jigdo_dir and os.path.isdir(os.path.join(compose.paths.compose.topdir(), source_jigdo_dir)):
 77 +                 var.source_jigdos[arch] = relative_path(source_jigdo_dir, compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 78 + 
 79 +             # paths: debug
 80 +             var.debug_tree[arch] = relative_path(compose.paths.compose.debug_tree(arch=arch, variant=variant, create_dir=False).rstrip("/") + "/", compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 81 +             var.debug_repository[arch] = relative_path(compose.paths.compose.debug_repository(arch=arch, variant=variant, create_dir=False).rstrip("/") + "/", compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 82 +             var.debug_packages[arch] = relative_path(compose.paths.compose.debug_packages(arch=arch, variant=variant, create_dir=False).rstrip("/") + "/", compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 83 +             '''
 84 +             # XXX: not suported (yet?)
 85 +             debug_iso_dir = compose.paths.compose.debug_iso_dir(arch=arch, variant=variant) or ""
 86 +             if debug_iso_dir:
 87 +                 var.debug_iso_dir[arch] = relative_path(debug_iso_dir, compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 88 +             debug_jigdo_dir = compose.paths.compose.debug_jigdo_dir(arch=arch, variant=variant) or ""
 89 +             if debug_jigdo_dir:
 90 +                 var.debug_jigdo_dir[arch] = relative_path(debug_jigdo_dir, compose.paths.compose.topdir().rstrip("/") + "/").rstrip("/")
 91 +             '''
 92 + 
 93 +         for v in variant.get_variants(recursive=False):
 94 +             x = dump_variant(v, parent=variant)
 95 +             if x is not None:
 96 +                 var.add(x)
 97 +         return var
 98 + 
 99 +     for variant_id in sorted(compose.variants):
100 +         variant = compose.variants[variant_id]
101 +         v = dump_variant(variant)
102 +         if v is not None:
103 +             ci.variants.add(v)
104 +     return ci
105 + 
106 + 
107   def write_compose_info(compose):
108 -     ci = compose.dumps()
109 +     ci = compose_to_composeinfo(compose)
110   
111       msg = "Writing composeinfo"
112       compose.log_info("[BEGIN] %s" % msg)