Last active
November 6, 2015 21:28
-
-
Save martin-ueding/41827b4e566eda32168a to your computer and use it in GitHub Desktop.
Install TeXLive documentation on Fedora 22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
# Copyright © 2015 Martin Ueding <dev@martin-ueding.de> | |
# Licensed under The MIT License | |
''' | |
Installs documentation packages for all installed TeXLive packages on Fedora | |
22. | |
''' | |
import argparse | |
import subprocess | |
def get_texlive_packages(): | |
''' | |
Obtains all TeXLive packages that are installed on the system. | |
http://unix.stackexchange.com/a/240826/8251 | |
''' | |
command = ['rpm', '--qf', r'%{name}\n', '-qa', 'texlive-*'] | |
lines = subprocess.check_output(command).decode().strip().split('\n') | |
return lines | |
def convert_to_doc(packages): | |
''' | |
Converts the list of packages into documentation packages. | |
''' | |
return [package + '-doc' for package in packages] | |
def package_exists(package): | |
''' | |
Checks whether a given package exists. | |
''' | |
print('Checking', package) | |
try: | |
subprocess.check_output(['dnf', 'info', package]) | |
except subprocess.CalledProcessError: | |
return False | |
else: | |
return True | |
def get_installable(): | |
packages = get_texlive_packages() | |
doc_packages = convert_to_doc(packages) | |
return filter(package_exists, doc_packages) | |
def main(): | |
options = _parse_args() | |
installable = get_installable() | |
command = ['sudo', 'dnf', 'install'] + sorted(installable) | |
print() | |
print(' '.join(command)) | |
subprocess.call(command) | |
def _parse_args(): | |
''' | |
Parses the command line arguments. | |
:return: Namespace with arguments. | |
:rtype: Namespace | |
''' | |
parser = argparse.ArgumentParser(description='') | |
options = parser.parse_args() | |
return options | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment