forked from minimization/content-resolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feedback_pipeline.py
executable file
·7402 lines (5735 loc) · 302 KB
/
feedback_pipeline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3
import argparse, yaml, tempfile, os, subprocess, json, jinja2, datetime, copy, re, dnf, pprint, urllib.request, sys, koji
import concurrent.futures
import rpm_showme as showme
from functools import lru_cache
import multiprocessing, asyncio
# Features of this new release
# - multiarch from the ground up!
# - more resilient
# - better internal data structure
# - user-defined views
###############################################################################
### Help ######################################################################
###############################################################################
# Configs:
# TYPE: KEY: ID:
# - repo repos repo_id
# - env_conf envs env_id
# - workload_conf workloads workload_id
# - label labels label_id
# - conf_view views view_id
#
# Data:
# TYPE: KEY: ID:
# - pkg pkgs/repo_id/arch NEVR
# - env envs env_id:repo_id:arch_id
# - workload workloads workload_id:env_id:repo_id:arch_id
# - view views view_id:repo_id:arch_id
#
#
#
###############################################################################
### Some initial stuff ########################################################
###############################################################################
class SettingsError(Exception):
# Error in global settings for Feedback Pipeline
# Settings to be implemented, now hardcoded below
pass
class ConfigError(Exception):
# Error in user-provided configs
pass
class RepoDownloadError(Exception):
# Error in downloading repodata
pass
class BuildGroupAnalysisError(Exception):
# Error while processing buildroot build group
pass
class KojiRootLogError(Exception):
pass
class AnalysisError(Exception):
pass
def log(msg):
print(msg, file=sys.stderr)
def err_log(msg):
print("ERROR LOG: {}".format(msg), file=sys.stderr)
class SetEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, set):
return list(obj)
if isinstance(obj, jinja2.Environment):
return ""
return json.JSONEncoder.default(self, obj)
def dump_data(path, data):
with open(path, 'w') as file:
json.dump(data, file, cls=SetEncoder)
def load_data(path):
with open(path, 'r') as file:
data = json.load(file)
return data
def size(num, suffix='B'):
for unit in ['','k','M','G']:
if abs(num) < 1024.0:
return "%3.1f %s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f %s%s" % (num, 'T', suffix)
def pkg_id_to_name(pkg_id):
pkg_name = pkg_id.rsplit("-",2)[0]
return pkg_name
def workload_id_to_conf_id(workload_id):
workload_conf_id = workload_id.split(":")[0]
return workload_conf_id
def pkg_placeholder_name_to_id(placeholder_name):
placeholder_id = "{name}-000-placeholder.placeholder".format(name=placeholder_name)
return placeholder_id
def pkg_placeholder_name_to_nevr(placeholder_name):
placeholder_id = "{name}-000-placeholder".format(name=placeholder_name)
return placeholder_id
def url_to_id(url):
# strip the protocol
if url.startswith("https://"):
url = url[8:]
elif url.startswith("http://"):
url = url[7:]
# strip a potential leading /
if url.endswith("/"):
url = url[:-1]
# and replace all non-alphanumeric characters with -
regex = re.compile('[^0-9a-zA-Z]')
return regex.sub("-", url)
def datetime_now_string():
return datetime.datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
def load_settings():
settings = {}
parser = argparse.ArgumentParser()
parser.add_argument("configs", help="Directory with YAML configuration files. Only files ending with '.yaml' are accepted.")
parser.add_argument("output", help="Directory to contain the output.")
parser.add_argument("--use-cache", dest="use_cache", action='store_true', help="Use local data instead of pulling Content Resolver. Saves a lot of time! Needs a 'cache_data.json' file at the same location as the script is at.")
parser.add_argument("--dev-buildroot", dest="dev_buildroot", action='store_true', help="Buildroot grows pretty quickly. Use a fake one for development.")
parser.add_argument("--dnf-cache-dir", dest="dnf_cache_dir_override", help="Override the dnf cache_dir.")
args = parser.parse_args()
settings["configs"] = args.configs
settings["output"] = args.output
settings["use_cache"] = args.use_cache
settings["dev_buildroot"] = args.dev_buildroot
settings["dnf_cache_dir_override"] = args.dnf_cache_dir_override
settings["root_log_deps_cache_path"] = "cache_root_log_deps.json"
settings["max_subprocesses"] = 10
settings["allowed_arches"] = ["aarch64", "ppc64le", "s390x", "x86_64"]
settings["weird_packages_that_can_not_be_installed"] = ["glibc32"]
return settings
###############################################################################
### Loading user-provided configs #############################################
###############################################################################
# Configs:
# TYPE: KEY: ID:
# - repo repos repo_id
# - env envs env_id
# - workload workloads workload_id
# - label labels label_id
# - view views view_id
def _load_config_repo(document_id, document, settings):
raise NotImplementedError("Repo v1 is not supported. Please migrate to repo v2.")
def _load_config_repo_v2(document_id, document, settings):
config = {}
config["id"] = document_id
# Step 1: Mandatory fields
try:
# Name is an identifier for humans
config["name"] = str(document["data"]["name"])
# A short description, perhaps hinting the purpose
config["description"] = str(document["data"]["description"])
# Who maintains it? This is just a freeform string
# for humans to read. In Fedora, a FAS nick is recommended.
config["maintainer"] = str(document["data"]["maintainer"])
# Where does this repository come from?
# Right now, only Fedora repositories are supported,
# defined by their releasever.
config["source"] = {}
config["source"]["repos"] = {}
if "repos" not in config["source"]:
raise KeyError
# Only Fedora repos supported at this time.
# Fedora release.
config["source"]["releasever"] = str(document["data"]["source"]["releasever"])
# List of architectures
config["source"]["architectures"] = []
for arch_raw in document["data"]["source"]["architectures"]:
arch = str(arch_raw)
if arch not in settings["allowed_arches"]:
log(" Warning: {file}.yaml lists an unsupported architecture: {arch}. Moving on...".format(
file=document_id,
arch=arch))
continue
config["source"]["architectures"].append(str(arch))
except KeyError:
raise ConfigError("'{file}.yaml' - There's something wrong with the mandatory fields. Sorry I don't have more specific info.".format(file=document_id))
for id, repo_data in document["data"]["source"]["repos"].items():
name = repo_data.get("name", id)
priority = repo_data.get("priority", 100)
exclude = repo_data.get("exclude", None)
limit_arches = repo_data.get("limit_arches", None)
koji_api_url = repo_data.get("koji_api_url", None)
koji_files_url = repo_data.get("koji_files_url", None)
config["source"]["repos"][id] = {}
config["source"]["repos"][id]["id"] = id
config["source"]["repos"][id]["name"] = name
try:
config["source"]["repos"][id]["baseurl"] = repo_data["baseurl"]
except KeyError:
raise ConfigError("'{file}.yaml' - is invalid. Repo {id} doesn't list baseurl.".format(
file=yml_file,
id=id))
config["source"]["repos"][id]["priority"] = priority
config["source"]["repos"][id]["exclude"] = exclude
config["source"]["repos"][id]["limit_arches"] = limit_arches
config["source"]["repos"][id]["koji_api_url"] = koji_api_url
config["source"]["repos"][id]["koji_files_url"] = koji_files_url
# Step 2: Optional fields
config["source"]["composeinfo"] = document["data"]["source"].get("composeinfo", None)
config["source"]["base_buildroot_override"] = []
if "base_buildroot_override" in document["data"]["source"]:
for pkg_name in document["data"]["source"]["base_buildroot_override"]:
config["source"]["base_buildroot_override"].append(str(pkg_name))
return config
def _load_config_env(document_id, document, settings):
config = {}
config["id"] = document_id
# Step 1: Mandatory fields
try:
# Name is an identifier for humans
config["name"] = str(document["data"]["name"])
# A short description, perhaps hinting the purpose
config["description"] = str(document["data"]["description"])
# Who maintains it? This is just a freeform string
# for humans to read. In Fedora, a FAS nick is recommended.
config["maintainer"] = str(document["data"]["maintainer"])
# Different instances of the environment, one per repository.
config["repositories"] = []
for repo in document["data"]["repositories"]:
config["repositories"].append(str(repo))
# Packages defining this environment.
# This list includes packages for all
# architectures — that's the one to use by default.
config["packages"] = []
for pkg in document["data"]["packages"]:
config["packages"].append(str(pkg))
# Labels connect things together.
# Workloads get installed in environments with the same label.
# They also get included in views with the same label.
config["labels"] = []
for repo in document["data"]["labels"]:
config["labels"].append(str(repo))
except KeyError:
raise ConfigError("'{file}.yaml' - There's something wrong with the mandatory fields. Sorry I don't have more specific info.".format(file=document_id))
# Step 2: Optional fields
# Architecture-specific packages.
config["arch_packages"] = {}
for arch in settings["allowed_arches"]:
config["arch_packages"][arch] = []
if "arch_packages" in document["data"]:
for arch, pkgs in document["data"]["arch_packages"].items():
if arch not in settings["allowed_arches"]:
log(" Warning: {file}.yaml lists an unsupported architecture: {arch}. Moving on...".format(
file=document_id,
arch=arch
))
continue
for pkg_raw in pkgs:
pkg = str(pkg_raw)
config["arch_packages"][arch].append(pkg)
# Extra installation options.
# The following are now supported:
# - "include-docs" - include documentation packages
# - "include-weak-deps" - automatically pull in "recommends" weak dependencies
config["options"] = []
if "options" in document["data"]:
if "include-docs" in document["data"]["options"]:
config["options"].append("include-docs")
if "include-weak-deps" in document["data"]["options"]:
config["options"].append("include-weak-deps")
# Comps groups
config["groups"] = []
if "groups" in document["data"]:
for module in document["data"]["groups"]:
config["groups"].append(module)
return config
def _load_config_workload(document_id, document, settings):
config = {}
config["id"] = document_id
# Step 1: Mandatory fields
try:
if "data" not in document:
raise ConfigError(f"Missing 'data' field in {document_id}")
for key in document["data"]:
if key not in [
"arch_packages",
"description",
"groups",
"labels",
"maintainer",
"name",
"options",
"package_placeholders",
"packages",
]:
raise ConfigError(f"Unknown key '{key}' in 'data' section of {document_id}")
# Name is an identifier for humans
config["name"] = str(document["data"]["name"])
# A short description, perhaps hinting the purpose
config["description"] = str(document["data"]["description"])
# Who maintains it? This is just a freeform string
# for humans to read. In Fedora, a FAS nick is recommended.
config["maintainer"] = str(document["data"]["maintainer"])
# Labels connect things together.
# Workloads get installed in environments with the same label.
# They also get included in views with the same label.
config["labels"] = []
for repo in document["data"]["labels"]:
config["labels"].append(str(repo))
except KeyError:
raise ConfigError("'{file}.yaml' - There's something wrong with the mandatory fields. Sorry I don't have more specific info.".format(file=document_id))
# Step 2: Optional fields
# Packages defining this workload.
# This list includes packages for all
# architectures — that's the one to use by default.
config["packages"] = []
# This workaround allows for "packages" to be left empty in the config
try:
for pkg in document["data"]["packages"]:
config["packages"].append(str(pkg))
except (TypeError, KeyError):
pass # Because it's now valid
#log(" Warning: {file} has an empty 'packages' field defined which is invalid. Moving on...".format(
# file=document_id
#))
# Architecture-specific packages.
config["arch_packages"] = {}
for arch in settings["allowed_arches"]:
config["arch_packages"][arch] = []
if "arch_packages" in document["data"]:
for arch, pkgs in document["data"]["arch_packages"].items():
if arch not in settings["allowed_arches"]:
log(" Warning: {file}.yaml lists an unsupported architecture: {arch}. Moving on...".format(
file=document_id,
arch=arch
))
continue
# This workaround allows for "arch_packages/ARCH" to be left empty in the config
try:
for pkg_raw in pkgs:
pkg = str(pkg_raw)
config["arch_packages"][arch].append(pkg)
except TypeError:
log(" Warning: {file} has an empty 'arch_packages/{arch}' field defined which is invalid. Moving on...".format(
file=document_id,
arch=arch
))
# Extra installation options.
# The following are now supported:
# - "include-docs" - include documentation packages
# - "include-weak-deps" - automatically pull in "recommends" weak dependencies
config["options"] = []
if "options" in document["data"]:
if "include-docs" in document["data"]["options"]:
config["options"].append("include-docs")
if "include-weak-deps" in document["data"]["options"]:
config["options"].append("include-weak-deps")
if "strict" in document["data"]["options"]:
config["options"].append("strict")
# Comps groups
config["groups"] = []
if "groups" in document["data"]:
for module in document["data"]["groups"]:
config["groups"].append(module)
# Package placeholders
# Add packages to the workload that don't exist (yet) in the repositories.
config["package_placeholders"] = {}
config["package_placeholders"]["pkgs"] = {}
config["package_placeholders"]["srpms"] = {}
if "package_placeholders" in document["data"]:
if isinstance(document["data"]["package_placeholders"], list):
for srpm in document["data"]["package_placeholders"]:
srpm_name = srpm["srpm_name"]
if not srpm_name:
continue
build_dependencies = srpm.get("build_dependencies", [])
limit_arches = srpm.get("limit_arches", [])
rpms = srpm.get("rpms", [])
all_rpm_arches = set()
config["package_placeholders"]["srpms"][srpm_name] = {}
config["package_placeholders"]["srpms"][srpm_name]["name"] = srpm_name
config["package_placeholders"]["srpms"][srpm_name]["buildrequires"] = build_dependencies
config["package_placeholders"]["srpms"][srpm_name]["limit_arches"] = limit_arches
for rpm in rpms:
rpm_name = rpm.get("rpm_name", None)
if not rpm_name:
continue
description = rpm.get("description", "Description not provided.")
dependencies = rpm.get("dependencies", [])
rpm_limit_arches = rpm.get("limit_arches", [])
if limit_arches and rpm_limit_arches:
rpm_limit_arches = list(set(limit_arches) & set(rpm_limit_arches))
elif limit_arches and not rpm_limit_arches:
rpm_limit_arches = limit_arches
all_rpm_arches.update(rpm_limit_arches)
config["package_placeholders"]["pkgs"][rpm_name] = {}
config["package_placeholders"]["pkgs"][rpm_name]["name"] = rpm_name
config["package_placeholders"]["pkgs"][rpm_name]["description"] = description
config["package_placeholders"]["pkgs"][rpm_name]["requires"] = dependencies
config["package_placeholders"]["pkgs"][rpm_name]["limit_arches"] = rpm_limit_arches
config["package_placeholders"]["pkgs"][rpm_name]["srpm"] = srpm_name
if not limit_arches and all_rpm_arches:
config["package_placeholders"]["srpms"][srpm_name]["limit_arches"] = list(all_rpm_arches)
return config
def _load_config_label(document_id, document, settings):
config = {}
config["id"] = document_id
# Step 1: Mandatory fields
try:
# Name is an identifier for humans
config["name"] = str(document["data"]["name"])
# A short description, perhaps hinting the purpose
config["description"] = str(document["data"]["description"])
# Who maintains it? This is just a freeform string
# for humans to read. In Fedora, a FAS nick is recommended.
config["maintainer"] = str(document["data"]["maintainer"])
except KeyError:
raise ConfigError("'{file}.yaml' - There's something wrong with the mandatory fields. Sorry I don't have more specific info.".format(file=document_id))
# Step 2: Optional fields
# none here
return config
def _load_config_compose_view(document_id, document, settings):
config = {}
config["id"] = document_id
config["type"] = "compose"
# Step 1: Mandatory fields
try:
# Name is an identifier for humans
config["name"] = str(document["data"]["name"])
# A short description, perhaps hinting the purpose
config["description"] = str(document["data"]["description"])
# Who maintains it? This is just a freeform string
# for humans to read. In Fedora, a FAS nick is recommended.
config["maintainer"] = str(document["data"]["maintainer"])
# Labels connect things together.
# Workloads get installed in environments with the same label.
# They also get included in views with the same label.
config["labels"] = []
for repo in document["data"]["labels"]:
config["labels"].append(str(repo))
# Choose one repository that gets used as a source.
config["repository"] = str(document["data"]["repository"])
except KeyError:
raise ConfigError("'{file}.yaml' - There's something wrong with the mandatory fields. Sorry I don't have more specific info.".format(file=document_id))
# Step 2: Optional fields
# Buildroot strategy
config["buildroot_strategy"] = "none"
if "buildroot_strategy" in document["data"]:
if str(document["data"]["buildroot_strategy"]) in ["none", "root_logs"]:
config["buildroot_strategy"] = str(document["data"]["buildroot_strategy"])
# Limit this view only to the following architectures
config["architectures"] = []
if "architectures" in document["data"]:
for arch in document["data"]["architectures"]:
config["architectures"].append(str(arch))
if not len(config["architectures"]):
config["architectures"] = settings["allowed_arches"]
# Packages to be flagged as unwanted
config["unwanted_packages"] = []
if "unwanted_packages" in document["data"]:
for pkg in document["data"]["unwanted_packages"]:
config["unwanted_packages"].append(str(pkg))
# Packages to be flagged as unwanted on specific architectures
config["unwanted_arch_packages"] = {}
for arch in settings["allowed_arches"]:
config["unwanted_arch_packages"][arch] = []
if "unwanted_arch_packages" in document["data"]:
for arch, pkgs in document["data"]["unwanted_arch_packages"].items():
if arch not in settings["allowed_arches"]:
log(" Warning: {file}.yaml lists an unsupported architecture: {arch}. Moving on...".format(
file=document_id,
arch=arch
))
continue
for pkg_raw in pkgs:
pkg = str(pkg_raw)
config["unwanted_arch_packages"][arch].append(pkg)
# SRPMs (components) to be flagged as unwanted
config["unwanted_source_packages"] = []
if "unwanted_source_packages" in document["data"]:
for pkg in document["data"]["unwanted_source_packages"]:
config["unwanted_source_packages"].append(str(pkg))
return config
def _load_config_addon_view(document_id, document, settings):
config = {}
config["id"] = document_id
config["type"] = "addon"
# Step 1: Mandatory fields
try:
# Name is an identifier for humans
config["name"] = str(document["data"]["name"])
# A short description, perhaps hinting the purpose
config["description"] = str(document["data"]["description"])
# Who maintains it? This is just a freeform string
# for humans to read. In Fedora, a FAS nick is recommended.
config["maintainer"] = str(document["data"]["maintainer"])
# Labels connect things together.
# Workloads get installed in environments with the same label.
# They also get included in views with the same label.
config["labels"] = []
for repo in document["data"]["labels"]:
config["labels"].append(str(repo))
# Choose one repository that gets used as a source.
config["base_view_id"] = str(document["data"]["base_view_id"])
config["repository"] = str(document["data"]["repository"])
except KeyError:
raise ConfigError("'{file}.yaml' - There's something wrong with the mandatory fields. Sorry I don't have more specific info.".format(file=document_id))
# Step 2: Optional fields
# Packages to be flagged as unwanted
config["unwanted_packages"] = []
if "unwanted_packages" in document["data"]:
for pkg in document["data"]["unwanted_packages"]:
config["unwanted_packages"].append(str(pkg))
# Packages to be flagged as unwanted on specific architectures
config["unwanted_arch_packages"] = {}
for arch in settings["allowed_arches"]:
config["unwanted_arch_packages"][arch] = []
if "unwanted_arch_packages" in document["data"]:
for arch, pkgs in document["data"]["unwanted_arch_packages"].items():
if arch not in settings["allowed_arches"]:
log(" Warning: {file}.yaml lists an unsupported architecture: {arch}. Moving on...".format(
file=document_id,
arch=arch
))
continue
for pkg_raw in pkgs:
pkg = str(pkg_raw)
config["unwanted_arch_packages"][arch].append(pkg)
# SRPMs (components) to be flagged as unwanted
config["unwanted_source_packages"] = []
if "unwanted_source_packages" in document["data"]:
for pkg in document["data"]["unwanted_source_packages"]:
config["unwanted_source_packages"].append(str(pkg))
return config
def _load_config_unwanted(document_id, document, settings):
config = {}
config["id"] = document_id
# Step 1: Mandatory fields
try:
if "data" not in document:
raise ConfigError(f"Missing 'data' field in {document_id}")
for key in document["data"]:
if key not in [
"description",
"labels",
"maintainer",
"name",
"unwanted_arch_packages",
"unwanted_arch_source_packages",
"unwanted_packages",
"unwanted_source_packages",
]:
raise ConfigError(f"Unknown key '{key}' in 'data' section of {document_id}")
# Name is an identifier for humans
config["name"] = str(document["data"]["name"])
# A short description, perhaps hinting the purpose
config["description"] = str(document["data"]["description"])
# Who maintains it? This is just a freeform string
# for humans to read. In Fedora, a FAS nick is recommended.
config["maintainer"] = str(document["data"]["maintainer"])
# Labels connect things together.
# Workloads get installed in environments with the same label.
# They also get included in views with the same label.
config["labels"] = []
for repo in document["data"]["labels"]:
config["labels"].append(str(repo))
except KeyError:
raise ConfigError("'{file}.yaml' - There's something wrong with the mandatory fields. Sorry I don't have more specific info.".format(file=document_id))
# Step 2: Optional fields
# Packages to be flagged as unwanted
config["unwanted_packages"] = []
if "unwanted_packages" in document["data"]:
for pkg in document["data"]["unwanted_packages"]:
config["unwanted_packages"].append(str(pkg))
# Packages to be flagged as unwanted on specific architectures
config["unwanted_arch_packages"] = {}
for arch in settings["allowed_arches"]:
config["unwanted_arch_packages"][arch] = []
if "unwanted_arch_packages" in document["data"]:
for arch, pkgs in document["data"]["unwanted_arch_packages"].items():
if arch not in settings["allowed_arches"]:
log(" Warning: {file}.yaml lists an unsupported architecture: {arch}. Moving on...".format(
file=document_id,
arch=arch
))
continue
for pkg_raw in pkgs:
pkg = str(pkg_raw)
config["unwanted_arch_packages"][arch].append(pkg)
# SRPMs (components) to be flagged as unwanted
config["unwanted_source_packages"] = []
if "unwanted_source_packages" in document["data"]:
for pkg in document["data"]["unwanted_source_packages"]:
config["unwanted_source_packages"].append(str(pkg))
# SRPMs (components) to be flagged as unwanted on specific architectures
config["unwanted_arch_source_packages"] = {}
for arch in settings["allowed_arches"]:
config["unwanted_arch_source_packages"][arch] = []
if "unwanted_arch_source_packages" in document["data"]:
for arch, pkgs in document["data"]["unwanted_arch_source_packages"].items():
if arch not in settings["allowed_arches"]:
log(" Warning: {file}.yaml lists an unsupported architecture: {arch}. Moving on...".format(
file=document_id,
arch=arch
))
continue
for pkg_raw in pkgs:
pkg = str(pkg_raw)
config["unwanted_arch_source_packages"][arch].append(pkg)
return config
def _load_config_buildroot(document_id, document, settings):
config = {}
config["id"] = document_id
# Step 1: Mandatory fields
try:
# Who maintains it? This is just a freeform string
# for humans to read. In Fedora, a FAS nick is recommended.
config["maintainer"] = str(document["data"]["maintainer"])
# What view is this for
config["view_id"] = str(document["data"]["view_id"])
except KeyError:
raise ConfigError("'{file}.yaml' - There's something wrong with the mandatory fields. Sorry I don't have more specific info.".format(file=document_id))
# Step 2: Optional fields
config["base_buildroot"] = {}
for arch in settings["allowed_arches"]:
config["base_buildroot"][arch] = []
if "base_buildroot" in document["data"]:
for arch, pkgs in document["data"]["base_buildroot"].items():
if arch not in settings["allowed_arches"]:
log(" Warning: {file}.yaml lists an unsupported architecture: {arch}. Moving on...".format(
file=document_id,
arch=arch
))
continue
if pkgs:
for pkg_raw in pkgs:
pkg = str(pkg_raw)
config["base_buildroot"][arch].append(pkg)
config["source_packages"] = {}
for arch in settings["allowed_arches"]:
config["source_packages"][arch] = {}
if "source_packages" in document["data"]:
for arch, srpms_dict in document["data"]["source_packages"].items():
if arch not in settings["allowed_arches"]:
log(" Warning: {file}.yaml lists an unsupported architecture: {arch}. Moving on...".format(
file=document_id,
arch=arch
))
continue
if not srpms_dict:
continue
for srpm_name, srpm_data in srpms_dict.items():
requires = []
if "requires" in srpm_data:
try:
for pkg_raw in srpm_data["requires"]:
requires.append(str(pkg_raw))
except TypeError:
log(" Warning: {file} has an empty 'requires' field defined which is invalid. Moving on...".format(
file=document_id
))
continue
config["source_packages"][arch][str(srpm_name)] = {}
config["source_packages"][arch][str(srpm_name)]["requires"] = requires
return config
def _load_json_data_buildroot_pkg_relations(document_id, document, settings):
config = {}
config["id"] = document_id
try:
# View ID
config["view_id"] = document["data"]["view_id"]
# Arch
arch = document["data"]["arch"]
if arch not in settings["allowed_arches"]:
raise ConfigError("Error: '{file}.json' lists an unsupported architecture: {arch}.".format(
file=document_id,
arch=arch
))
config["arch"] = arch
#pkg_relations
config["pkg_relations"] = document["data"]["pkgs"]
except KeyError:
raise ConfigError("'{file}.yaml' - There's something wrong with the mandatory fields. Sorry I don't have more specific info.".format(file=document_id))
return config
def get_configs(settings):
log("")
directory = settings["configs"]
if "allowed_arches" not in settings:
err_log("System error: allowed_arches not configured")
raise SettingsError
if not settings["allowed_arches"]:
err_log("System error: no allowed_arches not configured")
raise SettingsError
configs = {}
configs["repos"] = {}
configs["envs"] = {}
configs["workloads"] = {}
configs["labels"] = {}
configs["views"] = {}
configs["unwanteds"] = {}
configs["buildroots"] = {}
configs["buildroot_pkg_relations"] = {}
# Step 1: Load all configs
serious_error_messages = set()
log("Loading yaml files...")
log("---------------------")
for yml_file in os.listdir(directory):
# Only accept yaml files
if not yml_file.endswith(".yaml"):
continue
document_id = yml_file.split(".yaml")[0]
try:
with open(os.path.join(directory, yml_file), "r") as file:
# Safely load the config
try:
document = yaml.safe_load(file)
except yaml.YAMLError as err:
raise ConfigError("Error loading a config '{filename}': {err}".format(
filename=yml_file,
err=err))
# Only accept yaml files stating their purpose!
if not ("document" in document and "version" in document):
raise ConfigError("'{file}.yaml' - doesn't specify the 'document' and/or the 'version' field.".format(file=yml_file))
# === Case: Repository config ===
if document["document"] not in [
"content-resolver-buildroot",
"content-resolver-compose-view",
"content-resolver-environment",
"content-resolver-label",
"content-resolver-repository",
"content-resolver-unwanted",
"content-resolver-view",
"content-resolver-view-addon",
"content-resolver-workload",
"feedback-pipeline-buildroot",
"feedback-pipeline-compose-view",
"feedback-pipeline-environment",
"feedback-pipeline-label",
"feedback-pipeline-repository",
"feedback-pipeline-unwanted",
"feedback-pipeline-view",
"feedback-pipeline-view-addon",
"feedback-pipeline-workload",
]:
raise ConfigError(f"Unknown document type: {document['document']}")
if document["document"] in ["content-resolver-repository", "feedback-pipeline-repository"]:
if document["version"] == 1:
configs["repos"][document_id] = _load_config_repo(document_id, document, settings)
elif document["version"] == 2:
configs["repos"][document_id] = _load_config_repo_v2(document_id, document, settings)
# === Case: Environment config ===
if document["document"] in ["content-resolver-environment", "feedback-pipeline-environment"]:
configs["envs"][document_id] = _load_config_env(document_id, document, settings)
# === Case: Workload config ===
if document["document"] in ["content-resolver-workload", "feedback-pipeline-workload"]:
configs["workloads"][document_id] = _load_config_workload(document_id, document, settings)
# === Case: Label config ===
if document["document"] in ["content-resolver-label", "feedback-pipeline-label"]:
configs["labels"][document_id] = _load_config_label(document_id, document, settings)
# === Case: View config ===
# (Also including the legacy "feedback-pipeline-compose-view" for backwards compatibility)
if document["document"] in ["content-resolver-view", "content-resolver-compose-view", "feedback-pipeline-view", "feedback-pipeline-compose-view"]:
configs["views"][document_id] = _load_config_compose_view(document_id, document, settings)
# === Case: View addon config ===
if document["document"] in ["content-resolver-view-addon", "feedback-pipeline-view-addon"]:
configs["views"][document_id] = _load_config_addon_view(document_id, document, settings)
# === Case: Unwanted config ===
if document["document"] in ["content-resolver-unwanted", "feedback-pipeline-unwanted"]:
configs["unwanteds"][document_id] = _load_config_unwanted(document_id, document, settings)
# === Case: Buildroot config ===
if document["document"] in ["content-resolver-buildroot", "feedback-pipeline-buildroot"]:
configs["buildroots"][document_id] = _load_config_buildroot(document_id, document, settings)
except ConfigError as err:
serious_error_messages.add(str(err))
continue
if serious_error_messages:
log("")
log(" -------------------------------------------------------------------------")
log(" | 🔥 ERRORS FOUND 🔥 (the following files will be excluded)")
log(" |")
for message in serious_error_messages:
log(" | {}".format(message))
log(" -------------------------------------------------------------------------")
log("")
if settings.get("strict", False):
raise ConfigError("Config file errors encountered in strict mode")
else:
log("")
log(" ✅ No serious errors found.")
log("")
log(" Done!")
log("")
log("")
# Step 1.5: Load all external data sources
serious_error_messages = set()
log("Loading json files...")
log("---------------------")
log("")
for json_file in os.listdir(directory):
# Only accept json files
if not json_file.endswith(".json"):
continue