Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install W32TeX on Wine
#!/usr/bin/python
# install-w32tex.py -- Install W32TeX on Wine environment
# Copyright (c) 2012--2014 Kazuki Maeda <kmaeda@kmaeda.net>
import os
import sys
import time
# default values
#SRC_URI = 'http://ftp.kddilabs.jp/TeX/ptex-win32/current/'
SRC_URI = 'http://core.ring.gr.jp/pub/text/TeX/ptex-win32/current/'
# You can retrieve old archives from
# http://eplang.jp/w32tex/archive/YYYY/MM/DD/current/
PREFIX = os.environ['HOME'] + '/.wine/drive_c/w32tex'
DISTFILES = '/distfiles'
DBPKG = '/var/db/pkg'
NOINSTALLPKGS = ['luatex-dev-w32', 'otf', 'otfdevel', 'w32tex-src']
NOINSTALLDIRS = ['TLW64', 'win64']
tarext = '.tar.xz'
def makedirs(dir):
if not os.access(dir, os.F_OK):
try:
os.makedirs(dir)
except Exception as e:
sys.exit(sys.argv[0] + ': Cannot make directory (' + str(e) + ')')
print('>>> Mirroring ' + SRC_URI + ' to ' + PREFIX+DISTFILES)
makedirs(PREFIX+DISTFILES)
mirrorcommand = 'lftp -c "open ' + SRC_URI + '; lcd ' + PREFIX+DISTFILES + '; mirror -v --delete -I *' + tarext
for pkgname in NOINSTALLPKGS:
mirrorcommand += ' -X ' + pkgname + tarext
for dirname in NOINSTALLDIRS:
mirrorcommand += ' -x ' + dirname
mirrorcommand += '"'
if os.system(mirrorcommand):
sys.exit(sys.argv[0] + ': Cannot mirror ' + SRC_URI)
makedirs(PREFIX)
makedirs(PREFIX+DBPKG)
numoldpkg = 0
print('\n>>> Removing outdated packages from ' + PREFIX)
pkglist = os.listdir(PREFIX+DBPKG)
pkglist.sort()
for pkgname in pkglist:
removeflag = False
if not os.access(PREFIX+DISTFILES+'/'+pkgname+tarext, os.F_OK):
removeflag = True
try:
f = open(PREFIX+DBPKG+'/'+pkgname, 'r')
lines = f.readlines()
f.close()
except Exception as e:
sys.stderr.write(sys.argv[0] + ': Cannot read package database file ' + ' (' + str(e) + ')\n')
continue
for i in range(0, len(lines)):
lines[i] = lines[i].rstrip('\n')
if not removeflag and lines[0] != time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(os.path.getmtime(PREFIX+DISTFILES+'/'+pkgname+tarext))):
removeflag = True
if removeflag:
print(' \033[1;32m*\033[0m Removing ' + pkgname + ' (' + lines[0] + ')')
for i in range(len(lines)-1, 0, -1):
if os.access(PREFIX+'/'+lines[i], os.F_OK):
if lines[i][-1:] == '/':
if os.listdir(PREFIX+'/'+lines[i]) == []:
os.system('rmdir "' + PREFIX+'/'+lines[i] + '"')
else:
os.system('rm "' + PREFIX+'/'+lines[i] + '"')
os.system('rm "' + PREFIX+DBPKG+'/'+pkgname + '"')
numoldpkg += 1
if numoldpkg > 0:
print('\n>>> ' + str(numoldpkg) + ' outdated packages were removed.')
else:
print(' \033[1;32m*\033[0m No outdated packages were found on your system.')
print('\n>>> Installing new packages to ' + PREFIX)
pkglist = os.listdir(PREFIX+DISTFILES)
pkglist.sort()
numnewpkg = 0
for pkgtar in pkglist:
if pkgtar[-len(tarext):] == tarext:
pkgname = pkgtar[:-len(tarext)]
if not pkgname in NOINSTALLPKGS and not os.access(PREFIX+DBPKG+'/'+pkgname, os.F_OK):
pkgver = time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(os.path.getmtime(PREFIX+DISTFILES+'/'+pkgtar)))
print(' \033[1;32m*\033[0m Unpacking ' + pkgtar + ' (' + pkgver + ')')
if os.system('echo ' + pkgver + ' > ' + PREFIX+DBPKG+'/'+pkgname):
sys.stderr.write(sys.argv[0] + ': Cannot create package database file for ' + pkgname + '\n')
if os.system('tar Jxfv ' + PREFIX+DISTFILES+'/'+pkgtar + ' -C ' + PREFIX + ' >> ' + PREFIX+DBPKG+'/'+pkgname):
sys.exit(sys.argv[0] + ': Cannot unpack ' + pkgtar)
numnewpkg += 1
if numnewpkg > 0:
print('\n>>> ' + str(numnewpkg) + ' new packages were installed.')
else:
print(' \033[1;32m*\033[0m No new packages were found on your system.')
print('')
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.