-
Notifications
You must be signed in to change notification settings - Fork 0
/
mariner-pkg-query.py
executable file
·96 lines (80 loc) · 2.96 KB
/
mariner-pkg-query.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
#!/usr/bin/python3
__author__ = "Eric Desrochers"
__maintainer = "Eric Desrochers"
__version__ = "1.0"
__status__ = "Development"
import argparse
import dnf
import sys
from prettytable import PrettyTable
parser=argparse.ArgumentParser(
description='''Remotely query the Mariner archive database about packages''')
parser.add_argument('package', nargs=1, help='Package name')
args=parser.parse_args()
# If no argument is pass to the script
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
# [Workaround] Redirecting stderr to /dev/null for repo with no repodata/respomd.xml
f = open('/dev/null', 'w')
sys.stderr = f
# Setting up the cache
cachedir = '_dnf_cache_dir'
# Configuration
base = dnf.Base()
conf = base.conf
conf.cachedir = cachedir
conf.skip_if_unavailable = True
# Prettytable
myTable = PrettyTable(["Mariner", "Name", "DebugInfo", "Version", "Arch", "Repo"])
def cm1():
"""
Function to find package in Mariner 1.0
"""
cmver = float(1)
cm1_repos = ["base", "Microsoft", "coreui", "extras", "update"]
for cm1_repo in cm1_repos:
x86repo_name = "x86_64_cm1_" + cm1_repo
arm64repo_name = "arm64_cm1_" + cm1_repo
base.repos.add_new_repo(x86repo_name, conf,
baseurl=["https://packages.microsoft.com/cbl-mariner/1.0/prod/"+ cm1_repo + "/" + "x86_64" + "/rpms"])
base.repos.add_new_repo(arm64repo_name, conf,
baseurl=["https://packages.microsoft.com/cbl-mariner/1.0/prod/"+ cm1_repo + "/" + "aarch64" + "/rpms"])
base.fill_sack(load_system_repo=False)
result = base.sack.query().filter(name=sys.argv[1]).available().latest()
if result:
for pkg in result:
repo = pkg.reponame.split("_")
myTable.add_row([cmver, pkg.name, pkg.debug_name, pkg.evr, pkg.arch, repo[-1]])
else:
myTable.add_row([cmver,"--", "--", "--", "--", "--"])
def cm2():
"""
Function to find package in Mariner 1.0
"""
cmver = float(2)
cm2_repos = ["base", "Microsoft", "extended", "extras", "nvidia"]
for cm2_repo in cm2_repos:
x86repo_name = "x86_64_cm2_" + cm2_repo
arm64repo_name = "arm64_cm2_" + cm2_repo
base.repos.add_new_repo(x86repo_name, conf,
baseurl=["https://packages.microsoft.com/cbl-mariner/2.0/prod/" + cm2_repo + "/" + "x86_64"])
base.repos.add_new_repo(arm64repo_name, conf,
baseurl=["https://packages.microsoft.com/cbl-mariner/2.0/prod/" + cm2_repo + "/" + "aarch64"])
base.fill_sack(load_system_repo=False)
result = base.sack.query().filter(name=sys.argv[1]).available().latest()
if result:
for pkg in result:
repo = pkg.reponame.split("_")
myTable.add_row([cmver, pkg.name, pkg.debug_name, pkg.evr, pkg.arch, repo[-1]])
else:
myTable.add_row([cmver,"--", "--", "--", "--", "--"])
def cm_report():
"""
Prettytable format reporting
"""
print(myTable)
# Executing functions
cm1()
cm2()
cm_report()