2020-09-27 10:59:01 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
2020-12-29 21:21:17 +01:00
|
|
|
This file is part of scripts.
|
|
|
|
|
|
|
|
scripts is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2021-03-29 13:02:30 +02:00
|
|
|
the Free Software Foundation, version 3.
|
2020-12-29 21:21:17 +01:00
|
|
|
|
|
|
|
scripts is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with scripts. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2021-04-18 02:02:15 +02:00
|
|
|
Original author: Maciej Barć <xgqt@riseup.net>
|
2021-04-18 01:59:44 +02:00
|
|
|
Copyright (c) 2020-2021, src_prepare group
|
2020-12-29 21:21:17 +01:00
|
|
|
Licensed under the GNU GPL v3 License
|
|
|
|
|
2020-09-27 10:59:01 +02:00
|
|
|
Install Ebuild Dependencies
|
|
|
|
|
|
|
|
This script is strictly for working with ebuild files.
|
|
|
|
In normal situaltion when we already have a repository (/var/db/repos/repo),
|
|
|
|
to emerge dependencies we would just do "emerge --oneshot --onlydeps PKG".
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import argparse
|
2021-04-18 01:59:44 +02:00
|
|
|
import sys
|
2020-09-27 10:59:01 +02:00
|
|
|
from subprocess import call
|
|
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Install Ebuild Dependencies",
|
2021-04-18 01:59:44 +02:00
|
|
|
epilog="Copyright (c) 2020-2021, src_prepare group (License: GPLv3)"
|
2020-09-27 10:59:01 +02:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"ebuild",
|
|
|
|
nargs="*",
|
|
|
|
type=str
|
|
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
def pkg_name(pkg_str):
|
2021-04-18 01:59:44 +02:00
|
|
|
"""
|
|
|
|
Parse string and return a pkg name.
|
|
|
|
"""
|
2020-09-27 10:59:01 +02:00
|
|
|
|
|
|
|
# TODO: don't strip but force
|
|
|
|
|
|
|
|
# Strip required use
|
2021-04-18 01:59:44 +02:00
|
|
|
proper = pkg_str.split("[")[0]
|
2020-09-27 10:59:01 +02:00
|
|
|
|
|
|
|
# Strip conditional use
|
|
|
|
for i in ["$", "DEPEND", "||", "!", "?", "(", ")"]:
|
|
|
|
if i in proper:
|
|
|
|
proper = ""
|
|
|
|
|
|
|
|
return proper
|
|
|
|
|
|
|
|
|
|
|
|
def ebuild_deps(ebuild_file):
|
2021-04-18 01:59:44 +02:00
|
|
|
"""
|
|
|
|
Returns dependencies from a ebuild file.
|
|
|
|
"""
|
|
|
|
|
2020-09-27 10:59:01 +02:00
|
|
|
deps = []
|
|
|
|
adddeps = False
|
2021-04-18 01:59:44 +02:00
|
|
|
|
2020-09-27 10:59:01 +02:00
|
|
|
with open(ebuild_file) as ebuild:
|
|
|
|
for line in ebuild.read().splitlines():
|
2021-04-18 01:59:44 +02:00
|
|
|
|
|
|
|
# TODO: Find a better way to find the depend "block"
|
|
|
|
if "DEPEND" in line:
|
|
|
|
adddeps = True
|
|
|
|
|
|
|
|
elif adddeps:
|
2020-09-27 10:59:01 +02:00
|
|
|
# TODO: Find a better pkg match method
|
|
|
|
if "/" in line:
|
|
|
|
deps.append(
|
|
|
|
pkg_name(line.strip())
|
|
|
|
)
|
|
|
|
elif "\"" in line:
|
|
|
|
adddeps = False
|
2021-04-18 01:59:44 +02:00
|
|
|
|
2020-09-27 10:59:01 +02:00
|
|
|
return deps
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2021-04-18 01:59:44 +02:00
|
|
|
"""
|
|
|
|
The main function.
|
|
|
|
"""
|
2020-09-27 10:59:01 +02:00
|
|
|
print("Ebuilds:", args.ebuild)
|
|
|
|
|
2021-04-18 01:59:44 +02:00
|
|
|
if args.ebuild == []:
|
|
|
|
print("[ERROR]: No ebuilds given")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2020-09-27 10:59:01 +02:00
|
|
|
all_deps = []
|
|
|
|
|
|
|
|
for ebuild in args.ebuild:
|
|
|
|
all_deps += ebuild_deps(ebuild)
|
|
|
|
|
|
|
|
print("Dependencies:", all_deps)
|
|
|
|
|
|
|
|
# TODO: Maybe use Portage API
|
|
|
|
call(
|
|
|
|
[
|
|
|
|
"emerge",
|
|
|
|
"--autounmask",
|
|
|
|
"--noreplace",
|
|
|
|
"--oneshot"
|
|
|
|
]
|
|
|
|
+
|
|
|
|
list(filter(None, all_deps))
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|