2018-10-07 14:24:25 +02:00
#!/usr/bin/python3
2019-04-30 17:38:32 +02:00
##
## Script to parse texlive.tlpdb and get list of files in a package
##
2020-04-12 12:38:37 +02:00
## Copyright (C) 2019-2020 Henrik Grimler
2019-04-30 17:38:32 +02:00
##
## 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.
##
## This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
2018-08-28 09:08:07 +02:00
def parse_tlpdb_to_dict ( tlpdb_path ) :
""" Reads given tlpdb database and creates dict with packages and their dependencies and files
"""
2019-03-31 22:03:43 +02:00
with open ( tlpdb_path , " r " ) as f :
2018-08-28 09:08:07 +02:00
packages = f . read ( ) . split ( " \n \n " )
pkg_dict = { }
for pkg in packages :
if not pkg == " " :
pkg_lines = pkg . split ( " \n " )
pkg_name = pkg_lines [ 0 ] . split ( " " ) [ 1 ]
# We only care about getting all the files so only check for "depend" and files
pkg_dict [ pkg_name ] = { " depends " : [ ] , " files " : [ ] }
for line in pkg_lines :
2018-10-07 14:24:25 +02:00
line_description = line . split ( " " ) [ 0 ]
if line_description == " " :
2018-08-28 09:08:07 +02:00
pkg_dict [ pkg_name ] [ " files " ] . append ( line . split ( " " ) [ 1 ] )
2018-10-07 14:24:25 +02:00
elif line_description == " depend " :
2018-08-28 09:08:07 +02:00
pkg_dict [ pkg_name ] [ " depends " ] . append ( line . split ( " " ) [ 1 ] )
return pkg_dict
2018-10-07 14:24:25 +02:00
def get_files_in_package ( package , files_in_package , visited_pkgs , visit_collections = False ) :
2018-08-28 09:08:07 +02:00
""" Prints files in package and then run itself on each dependency. Doesn ' t visit collections unless argument visit_collections=True is passed.
"""
for f in pkg_dict [ package ] [ " files " ] :
files_in_package . append ( f )
for dep in pkg_dict [ package ] [ " depends " ] :
2020-04-12 12:38:37 +02:00
print ( dep . split ( " . " ) )
if dep . split ( " . " ) [ - 1 ] == " ARCH " :
# skip arch dependent packages, which we lack since we build our own binaries
continue
if dep . split ( " - " ) [ 0 ] == " collection " or visit_collections :
2018-08-28 09:08:07 +02:00
# skip collections unless explicitly told to go through them
2020-04-12 12:38:37 +02:00
continue
if not dep in visited_pkgs :
# avoid duplicates
visited_pkgs . append ( dep )
files_in_package , visited_pkgs = get_files_in_package ( dep , files_in_package , visited_pkgs )
2018-08-28 09:08:07 +02:00
return files_in_package , visited_pkgs
2018-10-07 14:24:25 +02:00
def Files ( * args , * * kwargs ) :
2018-08-28 09:08:07 +02:00
""" Wrapper around function get_files. Prepends " collection- " to package unless prepend_collection=False is passed. Also uses visit_collections=False per default.
"""
prefix = " collection- "
bool_visit_collections = False
for k , v in kwargs . items ( ) :
if k == " prepend_collection " and not v :
prefix = " "
elif k == " visit_collections " and v :
bool_visit_collections = True
files = [ ]
2018-10-07 14:24:25 +02:00
for pkg in args [ 0 ] :
files + = get_files_in_package ( prefix + pkg , [ ] , [ ] , visit_collections = bool_visit_collections ) [ 0 ]
2018-08-28 09:08:07 +02:00
return files
2018-10-07 14:24:25 +02:00
def get_conflicting_pkgs ( package ) :
""" Returns list of packages that contain some files that are also found in ' package ' .
These packages should be listed as dependencies .
"""
2020-04-12 12:38:37 +02:00
if package in [ " basic " ] :
conflicting_pkgs = [ ]
elif package in [ " latex " ] :
conflicting_pkgs = [ " basic " ]
elif package in [ " langeuropean " , " langenglish " , " langfrench " , " langgerman " ,
" binextra " , " fontutils " , " langarabic " , " langgreek " ,
" langitalian " , " langother " , " langpolish " , " langportuguese " ,
" langspanish " , " metapost " , " fontsrecommended " , " games " ,
" luatex " , " music " , " plaingeneric " , " publishers " ,
" texworks " , " wintools " ] :
conflicting_pkgs = [ " basic " , " latex " ]
2018-10-07 14:24:25 +02:00
elif package == " langczechslovak " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " fontsextra " , " luatex " ]
2018-10-07 14:24:25 +02:00
elif package == " langcyrillic " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " fontsextra " , " fontsrecommended " ,
2018-10-07 14:24:25 +02:00
" langgreek " , " latexrecommended " ]
elif package == " formatsextra " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " langcyrillic " , " mathscience " ,
2018-10-07 14:24:25 +02:00
" fontsrecommended " , " plaingeneric " ]
elif package == " context " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " mathscience " , " fontsrecommended " ,
2018-10-07 14:24:25 +02:00
" metapost " , " xetex " ]
elif package == " langjapanese " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " langcjk " , " langchinese " ]
2018-10-07 14:24:25 +02:00
elif package == " langchinese " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " langcjk " , " fontutils " ]
2018-10-07 14:24:25 +02:00
elif package == " bibtexextra " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " binextra " ]
2018-10-07 14:24:25 +02:00
elif package == " langcjk " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " langother " ]
2018-10-07 14:24:25 +02:00
elif package == " latexrecommended " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " fontsrecommended " , " latexextra " , " pictures " , " plaingeneric " ]
2018-10-07 14:24:25 +02:00
elif package == " mathscience " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " langgreek " ]
2018-10-07 14:24:25 +02:00
elif package == " langkorean " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " langjapanese " , " langcjk " , " latexrecommended " ]
2018-10-07 14:24:25 +02:00
elif package == " latexextra " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " fontsextra " ]
2018-10-07 14:24:25 +02:00
elif package == " humanities " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " latexextra " ]
2018-10-07 14:24:25 +02:00
elif package == " pictures " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " latexextra " ]
2018-10-07 14:24:25 +02:00
elif package == " fontsextra " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " plaingeneric " ]
2018-10-07 14:24:25 +02:00
elif package == " pstricks " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " , " plaingeneric " ]
2018-10-07 14:24:25 +02:00
elif package == " xetex " :
2020-04-12 12:38:37 +02:00
conflicting_pkgs = [ " basic " , " latex " ]
2018-10-07 14:24:25 +02:00
else :
raise ValueError ( sys . argv [ 1 ] + " isn ' t a known package name " )
2018-11-17 14:07:34 +01:00
2020-04-12 12:38:37 +02:00
return conflicting_pkgs
2019-03-31 22:03:43 +02:00
import sys
tlpdb = sys . argv [ 2 ]
pkg_dict = parse_tlpdb_to_dict ( tlpdb )
2018-11-17 14:07:34 +01:00
if len ( sys . argv ) > 2 and sys . argv [ - 1 ] == " print_names " :
""" Generate dependencies to put into TERMUX_SUBPKG_DEPENDS """
2020-04-12 12:38:37 +02:00
# Strip latex and basic since those are part of termux package "texlive"
pkgs_in_texlive = [ " latex " , " basic " ]
2019-11-17 14:42:47 +01:00
dependencies = [ " texlive- " + pkg for pkg in get_conflicting_pkgs ( sys . argv [ 1 ] ) if not pkg in pkgs_in_texlive ]
2018-11-17 14:07:34 +01:00
if len ( dependencies ) > 0 :
print ( " texlive, " + " , " . join ( dependencies ) )
else :
print ( " texlive " )
else :
""" Print files which should be included in the subpackage """
2020-04-12 12:38:37 +02:00
# The last set of packages are needed to make our texlive package able to
# generate pdflatex.fmt and compile a simple LaTeX test file, so they
# should be part of texlive.
2018-11-17 14:07:34 +01:00
print ( " \n " . join ( [ " share/texlive/ " + line for line in
2020-04-12 12:38:37 +02:00
list ( set ( Files ( [ sys . argv [ 1 ] ] ) ) -
set ( Files ( get_conflicting_pkgs ( sys . argv [ 1 ] ) ) ) -
set ( Files ( [ " dehyph-exptl " , " hyphen-afrikaans " , " kpathsea " , " amsfonts " , " texlive-scripts-extra " , " l3backend " , " latexconfig " , " tex-ini-files " ] , prepend_collection = False ) ) ) ] ) )