-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathypkg-install-deps
executable file
·173 lines (147 loc) · 5.32 KB
/
ypkg-install-deps
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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# This file is part of ypkg2
#
# Copyright 2015-2017 Ikey Doherty <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
from ypkg2 import console_ui
from ypkg2.ypkgspec import YpkgSpec
from pisi.db.filesdb import FilesDB
from pisi.db.installdb import InstallDB
from pisi.db.packagedb import PackageDB
from ypkg2 import pkgconfig_dep, pkgconfig32_dep
from ypkg2.main import show_version
import sys
import os
import subprocess
import argparse
def main():
spec = YpkgSpec()
parser = argparse.ArgumentParser(description="Ypkg Build Dep Installer")
parser.add_argument("-n", "--no-colors", help="Disable color output",
action="store_true")
parser.add_argument("-v", "--version", action="store_true",
help="Show version information and exit")
parser.add_argument("-f", "--force", help="Force install dependencies, "
"i.e. no prompt", action="store_true")
parser.add_argument("-D", "--output-dir", type=str,
help="Ignored in ypkg-install-deps")
# Main file
parser.add_argument("filename", help="Path to the ypkg YAML file")
args = parser.parse_args()
# Kill colors
if args.no_colors:
console_ui.allow_colors = False
# Show version
if args.version:
show_version()
# Grab filename
if not args.filename:
console_ui.emit_error("Error", "Please provide a filename")
print("")
parser.print_help()
sys.exit(1)
if not spec.load_from_path(args.filename):
sys.exit(1)
pc32deps = set()
pcdeps = set()
ndeps = set()
idb = InstallDB()
pdb = PackageDB()
fdb = FilesDB()
console_ui.emit_info("BuildDep", "Checking build-deps for {}-{}-{}".
format(spec.pkg_name, spec.pkg_version,
spec.pkg_release))
if spec.pkg_builddeps:
for dep in spec.pkg_builddeps:
em32 = pkgconfig32_dep.match(dep)
if em32:
pc32deps.add(em32.group(1))
continue
em = pkgconfig_dep.match(dep)
if em:
pcdeps.add(em.group(1))
continue
if not idb.has_package(dep):
ndeps.add(dep)
# Get the global known pkgconfig providers
pkgConfigs, pkgConfigs32 = pdb.get_pkgconfig_providers()
for i in pc32deps:
local = False
pkg = None
# Try global pkgconfig names first.
if i in pkgConfigs32:
pkg = pdb.get_package(pkgConfigs32[i])
elif i in pkgConfigs:
pkg = pdb.get_package(pkgConfigs[i])
# Try the filesdb
if not pkg:
local = True
nom = fdb.get_pkgconfig32_provider(i)
if nom:
pkg = idb.get_package_by_pkgconfig32(nom[0])
if not pkg:
nom = fdb.get_pkgconfig_provider(i)
if nom:
pkg = idb.get_package_by_pkgconfig(nom[0])
if local:
console_ui.emit_warning("pkgconfig32:{}".format(i),
"This dependency is not in any repo")
if not pkg:
console_ui.emit_error("BuildDep", "pkgconfig32({}) build dep "
"doesn't exist in the repository.".format(i))
sys.exit(1)
if not idb.has_package(pkg.name):
ndeps.add(pkg.name)
for i in pcdeps:
local = False
pkg = None
if i in pkgConfigs:
pkg = pdb.get_package(pkgConfigs[i])
if not pkg:
nom = fdb.get_pkgconfig_provider(i)
if nom:
pkg = idb.get_package_by_pkgconfig(nom[0])
local = True
if local:
console_ui.emit_warning("pkgconfig:{}".format(i),
"This dependency is not in any repo")
if not pkg:
console_ui.emit_error("BuildDep", "pkgconfig({}) build dep"
" does not exist in the repository.".
format(i))
sys.exit(1)
if not idb.has_package(pkg.name):
ndeps.add(pkg.name)
if len(ndeps) < 1:
console_ui.emit_success("BuildDep", "All build deps satisfied")
sys.exit(0)
if os.geteuid() != 0:
cmd = "sudo eopkg install {}".format(" ".join(ndeps))
else:
cmd = "eopkg install {}".format(" ".join(ndeps))
if args.force:
cmd += " --yes-all"
if args.no_colors:
cmd += " -N"
invalid = [x for x in ndeps if not pdb.has_package(x)]
if len(invalid) > 0:
console_ui.emit_error("BuildDep", "Unknown build deps: {}".
format(" ".join(invalid)))
sys.exit(1)
console_ui.emit_info("BuildDep", "Requesting installation of: {}".
format(", ".join(ndeps)))
try:
subprocess.check_call(cmd, shell=True)
except Exception as e:
console_ui.emit_error("BuildDep", "Failed to install build deps")
sys.exit(1)
sys.exit(0)
if __name__ == "__main__":
main()