2012-08-23 07:20:49 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import os
|
2012-08-26 02:44:51 +02:00
|
|
|
import shutil
|
2012-08-23 07:20:49 +02:00
|
|
|
import sys
|
2013-08-18 09:31:19 +02:00
|
|
|
import dbm
|
2013-04-03 21:50:13 +02:00
|
|
|
from zipfile import ZipFile
|
2012-08-23 07:20:49 +02:00
|
|
|
from subprocess import Popen, PIPE
|
|
|
|
|
2013-05-28 14:12:43 +02:00
|
|
|
PONYSAY_VERSION = '3.0.2'
|
2012-08-23 18:22:54 +02:00
|
|
|
|
2012-08-26 02:44:51 +02:00
|
|
|
manpages = [('en', 'English'), # must be first
|
2013-05-28 14:12:43 +02:00
|
|
|
('es', 'Spanish'),
|
2013-05-30 18:22:53 +02:00
|
|
|
('sv', 'Swedish'),
|
2013-05-28 14:12:43 +02:00
|
|
|
('tr', 'Turkish')]
|
2012-08-25 21:47:53 +02:00
|
|
|
|
2013-04-03 23:04:01 +02:00
|
|
|
sharedirs = [('ponies', 'xterm ponies', 'PONYDIR', True), # must be first
|
|
|
|
('ttyponies', 'tty ponies', 'TTYPONYDIR', True),
|
|
|
|
('extraponies', 'extra xterm ponies', 'XPONYDIR', True),
|
|
|
|
('extrattyponies', 'extra tty ponies', 'XTTYPONYDIR', True),
|
2013-08-18 09:31:19 +02:00
|
|
|
('ponyquotes', 'pony quotes', 'QUOTEDIR', False),
|
2013-04-03 23:04:01 +02:00
|
|
|
('balloons', 'balloon styles', 'BALLOONDIR', False)]
|
2012-08-25 21:47:53 +02:00
|
|
|
|
2012-08-25 23:05:14 +02:00
|
|
|
sharefiles = [('ucs', 'ucsmap')]
|
2012-08-26 02:44:51 +02:00
|
|
|
|
2013-04-04 14:09:18 +02:00
|
|
|
commands = ['ponysay', 'ponythink', 'ponysay-tool']
|
2012-08-26 02:44:51 +02:00
|
|
|
|
2012-08-25 23:05:14 +02:00
|
|
|
shells = [('bash', '/usr/share/bash-completion/completions/ponysay', 'GNU Bash'),
|
2012-08-25 21:47:53 +02:00
|
|
|
('fish', '/usr/share/fish/completions/ponysay.fish', 'Friendly interactive shell'),
|
2012-08-25 23:05:14 +02:00
|
|
|
('zsh', '/usr/share/zsh/site-functions/_ponysay', 'zsh')]
|
2012-08-26 02:44:51 +02:00
|
|
|
|
|
|
|
mansections = [('ponysay', '6'),
|
|
|
|
('cowsay', '1'),
|
|
|
|
('fortune', '6')]
|
2012-08-25 21:47:53 +02:00
|
|
|
|
2012-08-26 04:30:57 +02:00
|
|
|
miscfiles = [('COPYING', '/usr/share/licenses/ponysay/COPYING'),
|
2013-07-01 09:24:48 +02:00
|
|
|
('LICENSE', '/usr/share/licenses/ponysay/LICENSE'),
|
2012-08-26 04:30:57 +02:00
|
|
|
('CREDITS', '/usr/share/licenses/ponysay/CREDITS')]
|
|
|
|
|
2013-04-02 11:11:06 +02:00
|
|
|
ponysaysrc = [src + '.py' for src in
|
|
|
|
('__main__', 'common', 'ponysay', 'argparser', 'balloon',
|
2013-04-03 11:49:15 +02:00
|
|
|
'backend', 'colourstack', 'ucs', 'spellocorrecter', 'kms',
|
2013-04-04 14:09:18 +02:00
|
|
|
'list', 'metadata', 'ponysaytool')]
|
2013-04-02 11:11:06 +02:00
|
|
|
|
2012-08-26 04:22:14 +02:00
|
|
|
COPY = 'copy'
|
|
|
|
HARD = 'hard'
|
|
|
|
SYMBOLIC = 'symbolic'
|
|
|
|
|
2012-08-23 07:20:49 +02:00
|
|
|
class Setup():
|
|
|
|
def __init__(self):
|
|
|
|
usage_script = '\033[34;1msetup.py\033[21;39m'
|
2012-08-23 18:22:54 +02:00
|
|
|
usage_help = '(version | help)'
|
2012-08-26 07:09:39 +02:00
|
|
|
usage_proc = '[\033[4mconfigurations\033[24m] ([build] | prebuilt | install | (uninstall|clean)[-old] | view)'
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-23 07:20:49 +02:00
|
|
|
usage = '%s %s\n%s %s' % (usage_script, usage_help, usage_script, usage_proc)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-23 07:20:49 +02:00
|
|
|
usage = usage.replace('\033[', '\0')
|
|
|
|
for sym in ('[', ']', '(', ')', '|', '...'):
|
|
|
|
usage = usage.replace(sym, '\033[2m' + sym + '\033[22m')
|
|
|
|
usage = usage.replace('\0', '\033[')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-23 07:20:49 +02:00
|
|
|
opts = ArgParser(program = 'setup.py',
|
|
|
|
description = 'installer for ponysay',
|
|
|
|
usage = usage)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-23 18:22:54 +02:00
|
|
|
opts.add_argumentless(alternatives = ['--help'])
|
|
|
|
opts.add_argumentless(alternatives = ['--version'])
|
2012-08-27 17:32:26 +02:00
|
|
|
opts.add_argumented (alternatives = ['---DESTDIR'], arg="DESTDIR")
|
|
|
|
opts.add_argumented (alternatives = ['---PREFIX'], arg="PREFIX")
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2013-05-28 14:12:43 +02:00
|
|
|
opts.add_argumentless(help = 'Install everything that is not explicitly excluded',
|
2012-09-01 05:11:07 +02:00
|
|
|
alternatives = ['--everything', '--with-everything'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2013-05-28 14:12:43 +02:00
|
|
|
opts.add_argumentless(help = 'Install only the essentials\nNote that this can vary depending on the version',
|
2012-09-01 05:11:07 +02:00
|
|
|
alternatives = ['--minimal'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2013-05-28 14:12:43 +02:00
|
|
|
opts.add_argumentless(help = 'Install nothing (except legal documents) that is not explicitly included',
|
2012-09-01 05:11:07 +02:00
|
|
|
alternatives = ['--nothing', '--with-nothing'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 21:47:53 +02:00
|
|
|
for command in commands:
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Do not install the %s command' % (command),
|
|
|
|
alternatives = ['--without-' + command, '--without-' + command + '-command'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2013-05-28 14:12:43 +02:00
|
|
|
opts.add_argumented (help = 'Install the %s command, and set file name\nDefault = /usr/bin/%s' % (command, command),
|
2012-09-01 05:11:07 +02:00
|
|
|
alternatives = ['--with-' + command, '--with-' + command + '-command'], arg='EXEC')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Do not install a user shared cache',
|
|
|
|
alternatives = ['--without-shared-cache'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Install a user shared cache at CACHEDIR\nDefault = /var/cache/ponysay',
|
|
|
|
alternatives = [ '--with-shared-cache'], arg='CACHEDIR')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 21:47:53 +02:00
|
|
|
for shell in shells:
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Do not install completion for ' + shell[2],
|
|
|
|
alternatives = ['--without-' + shell[0], '--without-' + shell[0] + '-completion'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Set file name for the completion for ponysay in' + shell[2],
|
|
|
|
alternatives = ['--with-' + shell[0], '--with-' + shell[0] + '-completion'], arg='PONYSAY_%s_FILE' % (shell[0].upper()))
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Only install explicitly included shell completions',
|
2012-09-01 06:14:46 +02:00
|
|
|
alternatives = ['--without-shell', '--without-shell-completion'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Set share/ directory used for shell completions\nDefault = $SHAREDIR',
|
|
|
|
alternatives = ['--with-shell', '--with-shell-completion'], arg='SHAREDIR')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Do not install PDF manual\nDefault',
|
|
|
|
alternatives = ['--without-pdf', '--without-pdf-manual'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Set directory for PDF manual\nDefault = $PREFIX/doc',
|
|
|
|
alternatives = ['--with-pdf', '--with-pdf-manual'], arg='DOCDIR')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Do not compress PDF manual\nDefault',
|
|
|
|
alternatives = ['--without-pdf-compression', '--without-pdf-manual-compression'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Select compression for PDF manual\nDefault = gz, xz is also recognised',
|
|
|
|
alternatives = ['--with-pdf-compression', '--with-pdf-manual-compression'], arg='COMPRESSION')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Do not install info manual',
|
|
|
|
alternatives = ['--without-info', '--without-info-manual'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Set directory for info manual\nDefault = $SHARE/info',
|
|
|
|
alternatives = ['--with-info', '--with-info-manual'], arg='INFODIR')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Do not use install-info when installing info manual',
|
|
|
|
alternatives = ['--without-info-install', '--without-info-manual-install'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Use install-info when installing info manual, and set description\nDefault',
|
|
|
|
alternatives = ['--with-info-install', '--with-info-manual-install'], arg='DESCRIPTION')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Do not compress info manual',
|
|
|
|
alternatives = ['--without-info-compression', '--without-info-manual-compression'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Select compression for info manual\nDefault = gz, xz is also recognised',
|
|
|
|
alternatives = ['--with-info-compression', '--with-info-manual-compression'], arg='COMPRESSION')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 21:47:53 +02:00
|
|
|
for man in manpages:
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Do not install %s manpage manual' % (man[1]),
|
|
|
|
alternatives = ['--without-man-%s' % (man[0]), '--without-manpage-%s' % (man[0]), '--without-man-manual-%s' % (man[0]),
|
|
|
|
'--without-%s-man' % (man[0]), '--without-%s-manpage' % (man[0]), '--without-%s-man-manual' % (man[0])])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Set directory for %s manpage\nDefault = $SHARE/man' % (man[1]),
|
|
|
|
alternatives = ['--with-man-%s' % (man[0]), '--with-manpage-%s' % (man[0]), '--with-man-manual-%s' % (man[0]),
|
|
|
|
'--with-%s-man' % (man[0]), '--with-%s-manpage' % (man[0]), '--with-%s-man-manual' % (man[0])], arg='MANDIR')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Do not install any manpages',
|
|
|
|
alternatives = ['--without-man', '--without-manpage', '--without-man-manual'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Set directory for all man pages\nDefault = $SHARE/man',
|
|
|
|
alternatives = ['--with-man', '--with-manpage', '--with-man-manual'], arg='MANDIR')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 21:47:53 +02:00
|
|
|
for man in manpages:
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Do not compress %s manpage' % (man[1]),
|
|
|
|
alternatives = ['--without-man-%s-compression' % (man[0]), '--without-manpage-%s-compression' % (man[0]), '--without-man-manual-%s-compression' % (man[0]),
|
|
|
|
'--without-%s-man-compression' % (man[0]), '--without-%s-manpage-compression' % (man[0]), '--without-%s-man-manual-compression' % (man[0])])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 21:47:53 +02:00
|
|
|
opts.add_argumented (help = 'Select compression for %s manpage\nDefault = gz, xz is also recognised' % (man[1]),
|
2012-09-01 05:11:07 +02:00
|
|
|
alternatives = ['--with-man-%s-compression' % (man[0]), '--with-manpage-%s-compression' % (man[0]), '--with-man-manual-%s-compression' % (man[0]),
|
|
|
|
'--with-%s-man-compression' % (man[0]), '--with-%s-manpage-compression' % (man[0]), '--with-%s-man-manual-compression' % (man[0])],
|
|
|
|
arg='COMPRESSION')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Do not compress any installed manpage',
|
|
|
|
alternatives = ['--without-man-compression', '--without-manpage-compression', '--without-man-manual-compression'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Select compression for installed manpages\nDefault = gz, xz is also recognised',
|
|
|
|
alternatives = ['--with-man-compression', '--with-manpage-compression', '--with-man-manual-compression'], arg='COMPRESSION')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 21:47:53 +02:00
|
|
|
for man in mansections:
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Change the section for the %s manpage\nDefault = %s' % man,
|
|
|
|
alternatives = ['--man-section-%s' % (man[0]), '--%s-manpage-section' % (man[0]),
|
|
|
|
'--man-section-%s' % (man[0]), '--%s-manpage-section' % (man[0])], arg='SECTION')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 21:47:53 +02:00
|
|
|
for dir in sharedirs:
|
2013-04-01 19:21:03 +02:00
|
|
|
opts.add_argumentless(help = 'Do not install ' + dir[1],
|
2012-09-01 05:11:07 +02:00
|
|
|
alternatives = ['--without-' + dir[0]])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2013-04-01 19:21:03 +02:00
|
|
|
opts.add_argumentless(help = 'Install %s\nDefault' % dir[1],
|
|
|
|
alternatives = [ '--with-' + dir[0]])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Do not install UCS pony name map',
|
|
|
|
alternatives = ['--without-ucs', '--without-ucs-names'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2013-04-01 19:21:03 +02:00
|
|
|
opts.add_argumentless(help = 'Install UCS pony name map\nDefault',
|
|
|
|
alternatives = ['--with-ucs', '--with-ucs-names'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Let the installer set the env name for python in ponysay\nDefault',
|
|
|
|
alternatives = ['--without-custom-env-python'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Set the env name for python in ponysay',
|
|
|
|
alternatives = ['--with-custom-env-python'], arg='PYTHON')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Set a prefix to all implicit directories\nDefault = /usr',
|
|
|
|
alternatives = ['--prefix'], arg='PREFIX')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Change all implicit configurations to fit local user a installation for the current user',
|
|
|
|
alternatives = ['--private'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumentless(help = 'Change all implicit directories to fit installation to /opt',
|
|
|
|
alternatives = ['--opt'])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Set the system\'s directory for command executables\nDefault = $PREFIX/bin',
|
2013-06-01 08:06:21 +02:00
|
|
|
alternatives = ['--bin-dir', '--bindir'], arg='BINDIR')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2013-06-01 08:12:05 +02:00
|
|
|
opts.add_argumented (alternatives = ['--sbin-dir', '--sbindir'], arg='SBINDIR')
|
2013-06-01 08:01:38 +02:00
|
|
|
|
2012-09-29 23:08:13 +02:00
|
|
|
opts.add_argumented (help = 'Set the system\'s directory for non-executable libraries\nDefault = $PREFIX/lib/ponysay\nNot used.',
|
2013-06-01 08:06:21 +02:00
|
|
|
alternatives = ['--lib-dir', '--libdir'], arg='LIBDIR')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-29 23:08:13 +02:00
|
|
|
opts.add_argumented (help = 'Set the system\'s directory for non-command executables\nDefault = $PREFIX/libexec/ponysay\nNot used.',
|
2013-06-01 08:06:21 +02:00
|
|
|
alternatives = ['--libexec-dir', '--libexecdir'], arg='LIBEXECDIR')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Set the system\'s directory for resource files\nDefault = $PREFIX/share',
|
2013-06-01 08:06:21 +02:00
|
|
|
alternatives = ['--share-dir', '--sharedir'], arg='SHAREDIR')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-11-02 02:34:33 +01:00
|
|
|
opts.add_argumented (help = 'Set the system\'s local specific configuration directory\nDefault = /etc',
|
2013-06-01 08:06:21 +02:00
|
|
|
alternatives = ['--sysconf-dir', '--sysconfdir'], arg='SYSCONFDIR')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Set the system\'s directory for cache directories\nDefault = /var/cache',
|
2013-06-01 08:06:21 +02:00
|
|
|
alternatives = ['--cache-dir', '--cachedir'], arg='CACHEDIR')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Set off environment for installation\nEmpty by default',
|
2013-06-01 08:06:21 +02:00
|
|
|
alternatives = ['--dest-dir', '--destdir'], arg='DESTDIR')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-01 05:11:07 +02:00
|
|
|
opts.add_argumented (help = 'Set how to link identical files\nDefault = symbolic, copy and hard are also recognised',
|
|
|
|
alternatives = ['--linking'], arg='TYPE')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-11-03 07:10:18 +01:00
|
|
|
opts.add_argumented (help = 'Install all ponies or only the completely free ponies\nThis option is manditory, use strict, full, true or yes ' +
|
|
|
|
'for only free ponies,\nand partial, sloppy, false or no for all ponies',
|
2012-11-02 03:44:21 +01:00
|
|
|
alternatives = ['--freedom'], arg='FREEDOM')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-23 07:20:49 +02:00
|
|
|
opts.parse()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 01:47:58 +02:00
|
|
|
self.linking = SYMBOLIC
|
2012-08-26 04:22:14 +02:00
|
|
|
if opts.opts['--linking'] is not None:
|
|
|
|
self.linking = opts.opts['--linking'][0]
|
2013-06-01 08:30:04 +02:00
|
|
|
|
2012-11-03 03:42:28 +01:00
|
|
|
self.free = None
|
2012-11-02 03:44:21 +01:00
|
|
|
if opts.opts['--freedom'] is not None:
|
2012-11-03 07:10:18 +01:00
|
|
|
if opts.opts['--freedom'][0].lower() in ('strict', 'full', 'true', 'yes'):
|
2012-11-02 03:44:21 +01:00
|
|
|
self.free = True
|
2012-11-03 07:10:18 +01:00
|
|
|
elif opts.opts['--freedom'][0].lower() in ('partial', 'sloppy', 'false', 'no'):
|
2012-11-03 03:42:28 +01:00
|
|
|
self.free = False
|
2013-06-01 08:30:04 +02:00
|
|
|
def checkFreedom():
|
2013-06-01 08:30:44 +02:00
|
|
|
if self.free is None:
|
2013-06-01 08:30:04 +02:00
|
|
|
if (opts.opts['--version'] is None) and ((len(opts.files) != 1) or (opts.files[0] != 'version')):
|
|
|
|
print('')
|
|
|
|
print('You need to select your freedom, add --freedom=strict or --freedom=partial.')
|
|
|
|
print('')
|
|
|
|
print('--freedom=strict will install only ponies that are completely free.')
|
|
|
|
print('--freedom=partial will install all ponies, even if they are not free.')
|
|
|
|
print('')
|
|
|
|
print('')
|
|
|
|
exit(255)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 21:49:58 +02:00
|
|
|
if (opts.opts['---DESTDIR'] is not None) and (opts.opts['--dest-dir'] is None):
|
2012-08-27 17:32:26 +02:00
|
|
|
destdir = opts.opts['---DESTDIR'][0]
|
|
|
|
if len(destdir) > 0:
|
|
|
|
opts.opts['--dest-dir'] = [destdir]
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 21:49:58 +02:00
|
|
|
if (opts.opts['---PREFIX'] is not None) and (opts.opts['--prefix'] is None):
|
2012-08-27 17:32:26 +02:00
|
|
|
prefix = opts.opts['---PREFIX'][0]
|
|
|
|
if len(prefix) > 0:
|
|
|
|
opts.opts['--prefix'] = [prefix]
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 21:47:53 +02:00
|
|
|
if (len(opts.files) > 1) or (opts.opts['--help'] is not None) or ((len(opts.files) == 1) and (opts.files[0] == 'help')):
|
2012-08-23 18:22:54 +02:00
|
|
|
opts.help()
|
|
|
|
elif (opts.opts['--version'] is not None) or ((len(opts.files) == 1) and (opts.files[0] == 'version')):
|
|
|
|
print('Ponysay %s installer' % (PONYSAY_VERSION))
|
|
|
|
else:
|
|
|
|
if len(opts.files) == 0:
|
|
|
|
opts.files = ['build']
|
|
|
|
method = opts.files[0]
|
2012-08-26 00:50:35 +02:00
|
|
|
if method == 'clean': self.clean()
|
|
|
|
elif method == 'clean-old': self.cleanOld()
|
2012-08-26 00:17:58 +02:00
|
|
|
else:
|
|
|
|
conf = self.configure(opts.opts)
|
|
|
|
self.viewconf(conf)
|
2013-06-01 07:46:49 +02:00
|
|
|
os.umask(0o022)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 23:26:32 +02:00
|
|
|
if method == 'build':
|
2013-06-01 08:30:04 +02:00
|
|
|
checkFreedom()
|
2012-08-27 23:26:32 +02:00
|
|
|
self.build(conf)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 23:26:32 +02:00
|
|
|
elif method == 'prebuilt':
|
2013-06-01 08:30:04 +02:00
|
|
|
checkFreedom()
|
2012-08-27 23:26:32 +02:00
|
|
|
self.applyDestDir(conf)
|
|
|
|
self.install(conf)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 23:26:32 +02:00
|
|
|
elif method == 'install':
|
2013-06-01 08:30:04 +02:00
|
|
|
checkFreedom()
|
2012-08-27 23:26:32 +02:00
|
|
|
self.build(conf)
|
|
|
|
self.applyDestDir(conf)
|
|
|
|
self.install(conf)
|
|
|
|
self.clean()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 23:26:32 +02:00
|
|
|
elif method == 'uninstall':
|
|
|
|
self.uninstall(conf)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 23:26:32 +02:00
|
|
|
elif method == 'uninstall-old':
|
|
|
|
self.uninstallOld(conf)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 07:09:39 +02:00
|
|
|
elif not method == 'view':
|
2012-08-26 00:17:58 +02:00
|
|
|
opts.help()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 23:05:14 +02:00
|
|
|
'''
|
|
|
|
Display configurations
|
|
|
|
'''
|
|
|
|
def viewconf(self, conf):
|
|
|
|
RED = '\033[31m%s\033[39m'
|
|
|
|
GREEN = '%s\033[32m%s\033[39m'
|
|
|
|
YELLOW = '\033[33m%s\033[39m'
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 23:05:14 +02:00
|
|
|
for command in commands:
|
2012-08-26 02:44:51 +02:00
|
|
|
if conf[command] is not None: print(GREEN % ('Installing command ' + command + ' as ', conf[command]))
|
2012-08-25 23:05:14 +02:00
|
|
|
else: print(RED % ('Skipping installion of command ' + command))
|
|
|
|
if conf['shared-cache'] is not None: print(GREEN % ('Installing shared cache at ', conf['shared-cache']))
|
|
|
|
else: print(RED % ('Skipping installation of shared cache'))
|
|
|
|
for shell in [item[0] for item in shells]:
|
2012-08-25 23:41:43 +02:00
|
|
|
if conf[shell] is not None: print(GREEN % ('Installing auto-completion for ' + shell + ' as ', conf[shell]))
|
2012-08-25 23:05:14 +02:00
|
|
|
else: print(RED % ('Skipping installation of auto-completion for ' + shell))
|
|
|
|
if conf['pdf'] is not None: print(GREEN % ('Installing PDF manual to ', conf['pdf']))
|
|
|
|
else: print(RED % ('Skipping installation of PDF manual'))
|
|
|
|
if conf['pdf-compression'] is not None: print(GREEN % ('Compressing PDF manual with ', conf['pdf-compression']))
|
|
|
|
else: print(RED % ('Skipping compression of PDF manual'))
|
|
|
|
if conf['info'] is not None: print(GREEN % ('Installing info manual to ', conf['info']))
|
|
|
|
else: print(RED % ('Skipping installation of info manual'))
|
2012-08-25 23:41:43 +02:00
|
|
|
if conf['info-install'] is not None: print(GREEN % ('Installing info manual with install-info with description: ', conf['info-install']))
|
2012-08-25 23:05:14 +02:00
|
|
|
else: print(RED % ('Skipping installation of info manual with install-info'))
|
|
|
|
if conf['info-compression'] is not None: print(GREEN % ('Compressing info manual with ', conf['info-compression']))
|
|
|
|
else: print(RED % ('Skipping compression of info manual'))
|
|
|
|
for man in manpages:
|
|
|
|
key = 'man-' + man[0]
|
|
|
|
if conf[key] is not None: print(GREEN % ('Installing ' + man[1] + ' manpage to ', conf[key]))
|
|
|
|
else: print(RED % ('Skipping installation of ' + man[1] + ' manpage'))
|
|
|
|
key += '-compression'
|
|
|
|
if conf[key] is not None: print(GREEN % ('Compressing ' + man[1] + ' manpage with ', conf[key]))
|
|
|
|
else: print(RED % ('Skipping compression of ' + man[1] + ' manpage'))
|
2012-08-26 14:50:01 +02:00
|
|
|
for man in mansections: print(GREEN % ('References to manpage for ' + man[0] + ' points to section ', conf['man-section-' + man[0]]))
|
2012-08-25 23:05:14 +02:00
|
|
|
for dir in sharedirs:
|
2013-04-01 19:21:03 +02:00
|
|
|
if conf[dir[0]] is not None: print(GREEN % ('Installing ' + dir[1] + ' to ', conf['share-dir'] + '/' + dir[0]))
|
2012-08-25 23:05:14 +02:00
|
|
|
else: print(RED % ('Skipping installation of ' + dir[1]))
|
|
|
|
for file in sharefiles:
|
2013-04-01 19:21:03 +02:00
|
|
|
if conf[file[0]] is not None: print(GREEN % ('Installing ' + file[1] + ' as ', conf['share-dir'] + '/' + file[0]))
|
2012-08-25 23:05:14 +02:00
|
|
|
else: print(RED % ('Skipping installation of ' + file[1]))
|
|
|
|
if conf['custom-env-python'] is not None: print(GREEN % ('Using custom env reference in python script shebang: ', conf['custom-env-python']))
|
|
|
|
else: print(YELLOW % ('Looking for best env reference in python script shebang'))
|
2012-08-26 07:09:39 +02:00
|
|
|
for miscfile in miscfiles: print(GREEN % ('Installing ' + miscfile[0] + ' to ', conf[miscfile[0]]))
|
2012-11-02 02:34:33 +01:00
|
|
|
print('Using system configuration directory: ' + conf['sysconf-dir'])
|
2012-08-27 02:40:56 +02:00
|
|
|
print('Prefered linking style: ' + self.linking)
|
2013-06-01 08:30:04 +02:00
|
|
|
print('Using umask: 022 (only owner can do modifications)')
|
|
|
|
if self.free is None: print(YELLOW % ('\033[01m--freedom is manditory and has not be specified\033[21m'))
|
|
|
|
elif self.free: print(GREEN % ('', 'Installing only fully free parts of the package'))
|
2012-11-02 03:44:21 +01:00
|
|
|
else: print(RED % ('Installing \033[1mnot\033[21m only fully free parts of the package'))
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 23:05:14 +02:00
|
|
|
print()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 00:17:58 +02:00
|
|
|
'''
|
|
|
|
Compile ponysay
|
|
|
|
'''
|
|
|
|
def build(self, conf):
|
|
|
|
print('\033[1;34m::\033[39mCompiling...\033[21m')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 06:02:58 +02:00
|
|
|
def compressCommand(ext):
|
|
|
|
if ext == 'gz': return 'gzip -9 -f'
|
|
|
|
if ext == 'xz': return 'xz -9e -f'
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 06:02:58 +02:00
|
|
|
def compress(source, destination, ext):
|
|
|
|
print('%s < %s > %s' % (compressCommand(ext), source, destination))
|
|
|
|
(fileout, filein) = (None, None)
|
|
|
|
try:
|
|
|
|
fileout = open(destination, 'w+')
|
|
|
|
filein = open(source, 'r')
|
|
|
|
Popen(compressCommand(ext).split(' '), stdout=fileout, stdin=filein).communicate()
|
|
|
|
finally:
|
|
|
|
if fileout is not None: fileout.close()
|
|
|
|
if filein is not None: filein .close()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-10-29 22:14:04 +01:00
|
|
|
(fileout, filein) = (None, None)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 06:02:58 +02:00
|
|
|
env = conf['custom-env-python']
|
|
|
|
if env is None:
|
2012-11-03 09:52:24 +01:00
|
|
|
try:
|
|
|
|
(out, err) = Popen(['env', 'python', '--version'], stdout=PIPE, stderr=PIPE).communicate()
|
|
|
|
out = out.decode('utf8', 'replace') + err.decode('utf8', 'replace')
|
|
|
|
out = out.replace('\n', '')
|
|
|
|
env = out.split(' ')[1].split('.')[0]
|
|
|
|
if int(env) < 3: env = 'python3'
|
|
|
|
else: env = 'python'
|
|
|
|
except:
|
|
|
|
env = 'python3'
|
2012-08-26 06:02:58 +02:00
|
|
|
mane = False
|
|
|
|
for command in commands:
|
|
|
|
if conf[command] is not None:
|
|
|
|
mane = True
|
|
|
|
break
|
|
|
|
if mane:
|
2013-04-02 11:11:06 +02:00
|
|
|
for src in ponysaysrc:
|
|
|
|
try:
|
|
|
|
fileout = open('src/%s.install' % src, 'wb+')
|
|
|
|
filein = open('src/%s' % src, 'rb')
|
|
|
|
data = filein.read().decode('utf-8', 'replace')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2013-04-02 11:11:06 +02:00
|
|
|
if '#!/usr/bin/env python3' in data:
|
|
|
|
data = data.replace('#!/usr/bin/env python3', '#!/usr/bin/env ' + env)
|
|
|
|
else:
|
|
|
|
data = data.replace('#!/usr/bin/env python', '#!/usr/bin/env ' + env)
|
2013-04-03 23:49:21 +02:00
|
|
|
data = data.replace('/usr/share/ponysay/', conf['share-dir'] + ('' if conf['share-dir'].endswith('/') else '/'))
|
2013-04-02 11:11:06 +02:00
|
|
|
data = data.replace('/etc/', conf['sysconf-dir'] + ('' if conf['sysconf-dir'].endswith('/') else '/'))
|
|
|
|
data = data.replace('\nVERSION = \'dev\'', '\nVERSION = \'%s\'' % (PONYSAY_VERSION))
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2013-04-02 11:11:06 +02:00
|
|
|
fileout.write(data.encode('utf-8'))
|
|
|
|
finally:
|
|
|
|
if fileout is not None: fileout.close()
|
|
|
|
if filein is not None: filein .close()
|
2013-04-03 23:49:21 +02:00
|
|
|
print('Creating uncompressed zip file ponysay.zip with files from src: ' + ' '.join(ponysaysrc))
|
2013-04-06 20:35:31 +02:00
|
|
|
myzip = None
|
|
|
|
try:
|
|
|
|
myzip = ZipFile('ponysay.zip', 'w')
|
2013-04-03 23:49:21 +02:00
|
|
|
for src in ponysaysrc:
|
|
|
|
myzip.write('src/%s.install' % src, src)
|
2013-04-06 20:35:31 +02:00
|
|
|
finally:
|
|
|
|
myzip.close()
|
2013-04-03 20:57:50 +02:00
|
|
|
os.chmod('ponysay.zip', 0o755)
|
2012-08-26 06:02:58 +02:00
|
|
|
try:
|
2012-08-27 03:49:48 +02:00
|
|
|
fileout = open('ponysay.install', 'wb+')
|
2013-04-03 21:11:06 +02:00
|
|
|
filein = open('ponysay.zip', 'rb')
|
2013-04-02 11:11:06 +02:00
|
|
|
fileout.write(('#!/usr/bin/env %s\n' % env).encode('utf-8'))
|
|
|
|
fileout.write(filein.read())
|
2012-08-26 06:02:58 +02:00
|
|
|
finally:
|
|
|
|
if fileout is not None: fileout.close()
|
|
|
|
if filein is not None: filein .close()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 06:02:58 +02:00
|
|
|
for man in manpages:
|
|
|
|
key = 'man-' + man[0]
|
|
|
|
section = conf['man-section-ponysay']
|
|
|
|
if man is manpages[0]: lang = ''
|
|
|
|
else: lang = '.' + man[0]
|
|
|
|
if conf[key] is not None:
|
2013-05-28 14:12:43 +02:00
|
|
|
src = 'manuals/manpage' + lang + '.6'
|
2012-08-26 06:02:58 +02:00
|
|
|
dest = src + '.install'
|
|
|
|
(fileout, filein) = (None, None)
|
|
|
|
try:
|
2012-08-27 03:49:48 +02:00
|
|
|
fileout = open(dest, 'wb+')
|
|
|
|
filein = open(src, 'rb')
|
|
|
|
data = filein.read().decode('utf-8', 'replace')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 06:02:58 +02:00
|
|
|
data = data.replace('\n.TH PONYSAY 0', '\n.TH PONYSAY ' + conf['man-section-ponysay'])
|
|
|
|
for section in [item[0] for item in mansections]:
|
|
|
|
data = data.replace('\n.BR %s (0)' % (section), '\n.BR %s (%s)' % (section, conf['man-section-' + section]))
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 03:49:48 +02:00
|
|
|
fileout.write(data.encode('utf-8'))
|
2012-08-26 06:02:58 +02:00
|
|
|
finally:
|
|
|
|
if fileout is not None: fileout.close()
|
|
|
|
if filein is not None: filein .close()
|
|
|
|
src = dest
|
|
|
|
ext = conf[key + '-compression']
|
|
|
|
if ext is not None:
|
2013-05-28 14:12:43 +02:00
|
|
|
dest = 'manuals/manpage' + lang + '.6.' + ext
|
2012-08-26 07:09:39 +02:00
|
|
|
compress(src, dest, ext)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 06:02:58 +02:00
|
|
|
if conf['info'] is not None:
|
|
|
|
print('makeinfo manuals/ponysay.texinfo')
|
|
|
|
os.system('makeinfo manuals/ponysay.texinfo')
|
|
|
|
ext = conf['info-compression']
|
|
|
|
if ext is not None:
|
|
|
|
compress('ponysay.info', 'ponysay.info.' + ext, ext)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 15:27:33 +02:00
|
|
|
if conf['pdf-compression'] is not None:
|
|
|
|
ext = conf['pdf-compression']
|
|
|
|
if ext is not None:
|
|
|
|
compress('ponysay.pdf', 'ponysay.pdf.' + ext, ext)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-10-29 22:14:04 +01:00
|
|
|
for command in commands:
|
2012-10-31 22:16:04 +01:00
|
|
|
source = 'completion/ponysay'
|
|
|
|
sourceed = 'completion/ponysay.%s' % (command)
|
2012-10-29 22:14:04 +01:00
|
|
|
try:
|
|
|
|
fileout = open(sourceed, 'wb+')
|
|
|
|
filein = open(source, 'rb')
|
|
|
|
data = filein.read().decode('utf-8', 'replace')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-10-29 22:14:04 +01:00
|
|
|
if data.startswith('(ponysay\n'):
|
|
|
|
data = ('(%s ' % command) + data[len('(ponysay\n'):]
|
|
|
|
elif data.startswith('(ponysay '):
|
|
|
|
data = ('(%s ' % command) + data[len('(ponysay '):]
|
|
|
|
elif '\n(ponysay\n' in data:
|
|
|
|
edpos = data.find('\n(ponysay\n')
|
|
|
|
data = data[:edpos] + ('\n(%s\n' % command) + data[edpas + len('\n(ponysay\n'):]
|
|
|
|
elif '\n(ponysay ' in data:
|
|
|
|
data = data[:edpos] + ('\n(%s ' % command) + data[edpas + len('\n(ponysay '):]
|
|
|
|
else:
|
|
|
|
raise Exception('File %s does not look like expected' % source)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-10-29 22:14:04 +01:00
|
|
|
fileout.write(data.encode('utf-8'))
|
|
|
|
finally:
|
|
|
|
if fileout is not None: fileout.close()
|
|
|
|
if filein is not None: filein .close()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 06:02:58 +02:00
|
|
|
for shell in [item[0] for item in shells]:
|
|
|
|
if conf[shell] is not None:
|
|
|
|
for command in commands:
|
2012-10-31 22:16:04 +01:00
|
|
|
sourceed = 'completion/ponysay.%s' % (command)
|
2012-10-29 22:14:04 +01:00
|
|
|
generated = 'completion/%s-completion.%s' % (shell, command)
|
|
|
|
generatorcmd = './completion/auto-auto-complete.py %s --output %s --source %s' % (shell, generated, sourceed)
|
|
|
|
Popen(generatorcmd.split(' ')).communicate()
|
2012-08-26 15:27:33 +02:00
|
|
|
if conf[command] is not None:
|
2012-10-29 22:14:04 +01:00
|
|
|
dest = generated + '.install'
|
2012-08-26 06:02:58 +02:00
|
|
|
(fileout, filein) = (None, None)
|
|
|
|
try:
|
2012-08-27 03:49:48 +02:00
|
|
|
fileout = open(dest, 'wb+')
|
2012-10-29 22:14:04 +01:00
|
|
|
filein = open(generated, 'rb')
|
2012-08-27 03:49:48 +02:00
|
|
|
data = filein.read().decode('utf-8', 'replace')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 06:02:58 +02:00
|
|
|
data = data.replace('/usr/bin/ponysay', conf[command])
|
|
|
|
data = data.replace('/ponysay', '\0')
|
|
|
|
data = data.replace('ponysay', command)
|
2013-04-03 23:49:21 +02:00
|
|
|
data = data.replace('/usr/share/ponysay/', conf['share-dir'] if conf['share-dir'].endswith('/') else (conf['share-dir'] + '/'))
|
2012-08-26 06:02:58 +02:00
|
|
|
data = data.replace('\0', '/ponysay')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 03:49:48 +02:00
|
|
|
fileout.write(data.encode('utf-8'))
|
2012-08-26 06:02:58 +02:00
|
|
|
finally:
|
|
|
|
if fileout is not None: fileout.close()
|
|
|
|
if filein is not None: filein .close()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2013-08-18 09:31:19 +02:00
|
|
|
if conf['ponyquotes'] is not None:
|
2013-08-18 12:43:03 +02:00
|
|
|
Setup.makeQuotesDatabase('ponies', 'ponyquotes', 'share/by-master', 'share/by-image', 'share/by-file', Setup.validateFreedom if self.free else None)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2013-04-04 14:15:29 +02:00
|
|
|
for (sharedir, hasponies) in [(sharedir[0], sharedir[3]) for sharedir in sharedirs]:
|
2013-04-03 23:04:01 +02:00
|
|
|
if hasponies and os.path.isdir(sharedir):
|
2013-04-03 20:57:50 +02:00
|
|
|
for toolcommand in ('--dimensions', '--metadata'):
|
|
|
|
if not self.free:
|
2013-04-04 14:14:09 +02:00
|
|
|
print('%s, %s, %s' % ('./src/ponysaytool.py', toolcommand, sharedir))
|
|
|
|
Popen(['./src/ponysaytool.py', toolcommand, sharedir], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate()
|
2013-04-03 20:57:50 +02:00
|
|
|
else:
|
2013-04-04 14:14:09 +02:00
|
|
|
params = ['./src/ponysaytool.py', toolcommand, sharedir, '--']
|
2013-04-03 20:57:50 +02:00
|
|
|
for sharefile in os.listdir(sharedir):
|
|
|
|
if sharefile.endswith('.pony') and (sharefile != '.pony'):
|
|
|
|
if not Setup.validateFreedom(sharedir + '/' + sharefile):
|
|
|
|
print('Skipping metadata correction for %s/%s, did not pass validation process made by setup settings' % (sharedir, sharefile))
|
|
|
|
else:
|
|
|
|
params.append(sharefile)
|
2013-04-04 14:14:09 +02:00
|
|
|
print('%s, %s, %s (with files)' % ('./src/ponysaytool.py', toolcommand, sharedir))
|
2013-04-03 11:53:00 +02:00
|
|
|
Popen(params, stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 15:27:33 +02:00
|
|
|
print()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 00:17:58 +02:00
|
|
|
'''
|
|
|
|
Install compiled ponysay
|
|
|
|
'''
|
|
|
|
def install(self, conf):
|
|
|
|
print('\033[1;34m::\033[39mInstalling...\033[21m')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 03:02:34 +02:00
|
|
|
dests = []
|
2012-08-26 04:22:14 +02:00
|
|
|
for command in commands:
|
|
|
|
if conf[command] is not None:
|
|
|
|
dests.append(conf[command])
|
2012-08-27 03:02:34 +02:00
|
|
|
if len(dests) > 0:
|
|
|
|
self.cp(False, 'ponysay.install', dests)
|
|
|
|
print('Setting mode for ponysay.install copies to 755')
|
|
|
|
if self.linking == COPY:
|
|
|
|
for dest in dests:
|
|
|
|
os.chmod(dest, 0o755)
|
|
|
|
else:
|
|
|
|
os.chmod(dests[0], 0o755)
|
2012-08-26 04:22:14 +02:00
|
|
|
if conf['shared-cache'] is not None:
|
|
|
|
dir = conf['shared-cache']
|
2012-08-26 15:27:33 +02:00
|
|
|
if not os.path.exists(dir):
|
|
|
|
pdir = dir[:dir.rfind('/') + 1]
|
|
|
|
if not os.path.exists(pdir):
|
|
|
|
print('Creating intermediate-level directories needed for ' + dir)
|
|
|
|
os.makedirs(pdir)
|
2012-10-08 18:26:30 +02:00
|
|
|
print('Creating directory ' + dir)
|
|
|
|
os.mkdir(dir)
|
2013-04-04 03:23:26 +02:00
|
|
|
print('Setting permission mode mask for ' + dir + ' to 7777')
|
|
|
|
Popen('chmod -R 7777 -- \'' + dir.replace('\'', '\'\\\'\'') + '\'', shell=True).wait()
|
2012-10-08 18:30:32 +02:00
|
|
|
print('Setting group for ' + dir + ' users')
|
2012-10-08 18:58:24 +02:00
|
|
|
Popen('chown -R :users -- \'' + dir.replace('\'', '\'\\\'\'') + '\'', shell=True).wait()
|
2012-08-26 04:22:14 +02:00
|
|
|
for shell in [item[0] for item in shells]:
|
|
|
|
if conf[shell] is not None:
|
|
|
|
for command in commands:
|
|
|
|
if conf[command] is not None:
|
2012-10-29 22:14:04 +01:00
|
|
|
src = 'completion/%s-completion.%s.install' % (shell, command)
|
2012-08-26 04:22:14 +02:00
|
|
|
dest = conf[shell].replace('ponysay', command)
|
|
|
|
self.cp(False, src, [dest])
|
|
|
|
if conf['pdf'] is not None:
|
|
|
|
src = 'ponysay.pdf' + ('' if conf['pdf-compression'] is None else '.' + conf['pdf-compression'])
|
|
|
|
dest = conf['pdf'] + '/' + src
|
|
|
|
self.cp(False, src, [dest])
|
|
|
|
if conf['info'] is not None:
|
|
|
|
installinfo = []
|
|
|
|
dests = []
|
|
|
|
ext = ('' if conf['info-compression'] is None else '.' + conf['info-compression'])
|
|
|
|
src = 'ponysay.info' + ext
|
|
|
|
for command in commands:
|
|
|
|
if conf[command] is not None:
|
|
|
|
dests.append(conf['info'] + '/' + command + '.info' + ext)
|
|
|
|
if conf['info-install'] is not None:
|
|
|
|
cmdarr = ['install-info', '--entry=Miscellaneous', '--description=' + conf['info-install'], '--dir-file=' + conf['info'] + '/dir', dest]
|
|
|
|
cmd = ' '.join(['\'%s\'' % (elem.replace('\'', '\'\\\'\'')) for elem in cmdarr])
|
|
|
|
installinfo.append((cmd, 'Installing info manual ' + dest + ' with install-info'))
|
|
|
|
self.cp(False, src, dests)
|
|
|
|
for pair in installinfo:
|
|
|
|
print(pair[1])
|
|
|
|
os.system(pair[0])
|
|
|
|
for man in manpages:
|
|
|
|
key = 'man-' + man[0]
|
2012-08-26 06:02:58 +02:00
|
|
|
section = conf['man-section-ponysay']
|
|
|
|
if man is manpages[0]: sub = 'man' + section
|
|
|
|
else: sub = man[0] + '/man' + section
|
|
|
|
if man is manpages[0]: lang = ''
|
|
|
|
else: lang = '.' + man[0]
|
2012-08-26 04:22:14 +02:00
|
|
|
if conf[key] is not None:
|
2013-05-28 14:12:43 +02:00
|
|
|
src = 'manuals/manpage' + lang + '.6.' + ('install' if conf[key + '-compression'] is None else conf[key + '-compression'])
|
2012-08-26 04:22:14 +02:00
|
|
|
dests = []
|
|
|
|
for command in commands:
|
|
|
|
if conf[command] is not None:
|
2012-08-26 06:02:58 +02:00
|
|
|
dest = '%s/%s/%s.%s%s' % (conf[key], sub, command, section, '' if conf[key + '-compression'] is None else '.' + conf[key + '-compression'])
|
2012-08-26 04:22:14 +02:00
|
|
|
dests.append(dest)
|
|
|
|
self.cp(False, src, dests)
|
2013-04-01 19:21:03 +02:00
|
|
|
ponyshare = conf['share-dir']
|
|
|
|
if not ponyshare.endswith('/'):
|
|
|
|
ponyshare += '/'
|
2012-08-26 15:27:33 +02:00
|
|
|
for dir in sharedirs:
|
2012-08-26 04:22:14 +02:00
|
|
|
if conf[dir[0]] is not None:
|
2013-04-01 19:21:03 +02:00
|
|
|
self.cp(True, dir[0], [ponyshare + dir[0]], Setup.validateFreedom if self.free else None)
|
2012-08-26 04:22:14 +02:00
|
|
|
for file in sharefiles:
|
|
|
|
if conf[file[0]] is not None:
|
2013-04-01 19:21:03 +02:00
|
|
|
self.cp(False, 'share/' + file[1], [ponyshare + file[0]], Setup.validateFreedom if self.free else None)
|
2013-08-18 09:31:19 +02:00
|
|
|
if conf['ponyquotes'] is not None:
|
2013-08-18 12:43:03 +02:00
|
|
|
for file in ('by-file', 'by-image', 'by-master'):
|
2013-08-18 09:31:19 +02:00
|
|
|
self.cp(False, 'share/' + file, [ponyshare + file], Setup.validateFreedom if self.free else None)
|
2012-08-26 04:30:57 +02:00
|
|
|
for file in miscfiles:
|
2012-12-22 00:59:12 +01:00
|
|
|
self.cp(False, file[0], [conf[file[0]]], Setup.validateFreedom if self.free else None)
|
2012-08-26 15:27:33 +02:00
|
|
|
print()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 00:17:58 +02:00
|
|
|
'''
|
|
|
|
Uninstall ponysay
|
|
|
|
'''
|
|
|
|
def uninstall(self, conf):
|
|
|
|
print('\033[1;34m::\033[39mUninstalling...\033[21m')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 15:27:33 +02:00
|
|
|
(files, dirs, infos) = ([], [], [])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 02:44:51 +02:00
|
|
|
for command in commands:
|
|
|
|
if conf[command] is not None:
|
|
|
|
files.append(conf[command])
|
|
|
|
if conf['shared-cache'] is not None:
|
|
|
|
dirs.append(conf['shared-cache'])
|
|
|
|
for shell in [item[0] for item in shells]:
|
|
|
|
if conf[shell] is not None:
|
|
|
|
for command in commands:
|
|
|
|
if conf[command] is not None:
|
|
|
|
files.append(conf[shell].replace('ponysay', command))
|
|
|
|
if conf['pdf'] is not None:
|
|
|
|
files.append(conf['pdf'] + '/ponysay.pdf' + ('' if conf['pdf-compression'] is None else '.' + conf['pdf-compression']))
|
|
|
|
if conf['info'] is not None:
|
|
|
|
for command in commands:
|
|
|
|
if conf[command] is not None:
|
|
|
|
file = conf['info'] + '/' + command + '.info' + ('' if conf['info-compression'] is None else '.' + conf['info-compression'])
|
|
|
|
files.append(file)
|
|
|
|
if conf['info-install'] is not None:
|
|
|
|
infos.append(file)
|
2012-08-26 15:27:33 +02:00
|
|
|
for man in [item[0] for item in manpages]:
|
2012-08-26 02:44:51 +02:00
|
|
|
key = 'man-' + man
|
2012-08-26 06:02:58 +02:00
|
|
|
section = conf['man-section-ponysay']
|
|
|
|
if man is manpages[0]: sub = 'man' + section
|
|
|
|
else: sub = man[0] + '/man' + section
|
2012-08-26 02:44:51 +02:00
|
|
|
if conf[key] is not None:
|
|
|
|
for command in commands:
|
|
|
|
if conf[command] is not None:
|
2012-08-26 06:02:58 +02:00
|
|
|
files.append('%s/%s/%s.%s%s' % (conf[key], sub, command, section, '' if conf[key + '-compression'] is None else '.' + conf[key + '-compression']))
|
2013-04-01 19:21:03 +02:00
|
|
|
ponyshare = conf['share-dir']
|
|
|
|
if not ponyshare.endswith('/'):
|
|
|
|
ponyshare += '/'
|
2012-08-26 15:27:33 +02:00
|
|
|
for dir in sharedirs:
|
2012-08-26 02:44:51 +02:00
|
|
|
if conf[dir[0]] is not None:
|
2013-04-01 19:21:03 +02:00
|
|
|
dirs.append(ponyshare + dir[0])
|
2012-08-26 02:44:51 +02:00
|
|
|
for file in sharefiles:
|
|
|
|
if conf[file[0]] is not None:
|
2013-04-01 19:21:03 +02:00
|
|
|
files.append(ponyshare + file[0])
|
2013-08-18 09:31:19 +02:00
|
|
|
files.append(ponyshare + 'by-file')
|
2013-08-18 12:43:03 +02:00
|
|
|
files.append(ponyshare + 'by-image')
|
2013-08-18 09:31:19 +02:00
|
|
|
files.append(ponyshare + 'by-master')
|
2012-08-26 04:30:57 +02:00
|
|
|
for file in miscfiles:
|
|
|
|
files.append(conf[file[0]])
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 02:44:51 +02:00
|
|
|
for info in infos:
|
|
|
|
cmdarr = ['install-info', '--delete', '--dir-file=' + conf['info'] + '/dir', info]
|
|
|
|
cmd = ' '.join(['\'%s\'' % (elem.replace('\'', '\'\\\'\'')) for elem in cmdarr])
|
2012-08-26 04:22:14 +02:00
|
|
|
print('Uninstalling info manual ' + info + ' with install-info')
|
2012-08-26 02:44:51 +02:00
|
|
|
os.system(cmd)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 02:44:51 +02:00
|
|
|
self.removeLists(files, dirs)
|
2012-08-26 15:27:33 +02:00
|
|
|
print()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 00:17:58 +02:00
|
|
|
'''
|
|
|
|
Uninstall file ponysay no longer uses
|
|
|
|
'''
|
|
|
|
def uninstallOld(self, conf):
|
|
|
|
print('\033[1;34m::\033[39mUninstalling old files...\033[21m')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 00:17:58 +02:00
|
|
|
instdir = conf['~prefix~'] + '/usr'
|
|
|
|
files = [instdir + f for f in ['bin/ponysaylist.pl', 'bin/ponysaytruncater', 'bin/ponysay.py', 'bin/ponythink.py']]
|
|
|
|
dirs = [instdir + d for d in ['lib/ponysay', 'share/ponies', 'share/ttyponies']]
|
|
|
|
#$(instdir)/lib/ponysay/truncater
|
|
|
|
#$(instdir)/lib/ponysay/list.pl
|
|
|
|
#$(instdir)/lib/ponysay/linklist.pl
|
|
|
|
#$(instdir)/lib/ponysay/pq4ps
|
|
|
|
#$(instdir)/lib/ponysay/pq4ps.pl
|
|
|
|
#$(instdir)/lib/ponysay/pq4ps-list
|
|
|
|
#$(instdir)/lib/ponysay/pq4ps-list.pl
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 00:50:35 +02:00
|
|
|
self.removeLists(files, dirs)
|
2012-08-26 15:27:33 +02:00
|
|
|
print()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 00:17:58 +02:00
|
|
|
'''
|
|
|
|
Remove compiled files
|
|
|
|
'''
|
|
|
|
def clean(self):
|
|
|
|
print('\033[1;34m::\033[39mCleaning...\033[21m')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2013-08-18 12:43:03 +02:00
|
|
|
files = ['ponysay.info', 'ponysay.info.gz', 'ponysay.info.xz', 'ponysay.pdf.gz', 'ponysay.pdf.xz', 'ponysay.install', 'share/by-file', 'share/by-image', 'share/by-master']
|
2013-04-02 11:11:06 +02:00
|
|
|
files += ['src/%s.install' % file for file in ponysaysrc]
|
2013-08-18 09:31:19 +02:00
|
|
|
dirs = []
|
2012-08-26 04:22:14 +02:00
|
|
|
for comp in ['install', 'gz', 'xz']:
|
2012-08-26 00:17:58 +02:00
|
|
|
for man in manpages:
|
|
|
|
if man is manpages[0]: man = ''
|
2012-08-26 00:50:35 +02:00
|
|
|
else: man = '.' + man[0]
|
2012-09-01 06:05:00 +02:00
|
|
|
for sec in range(0, 9):
|
|
|
|
files.append('manuals/manpage%s.%s.%s' % (man, str(sec), comp))
|
2012-08-26 00:50:35 +02:00
|
|
|
for shell in [item[0] for item in shells]:
|
2012-08-26 07:09:39 +02:00
|
|
|
for command in commands:
|
2012-10-29 22:14:04 +01:00
|
|
|
files.append('completion/%s-completion.%s' % (shell, command))
|
|
|
|
files.append('completion/%s-completion.%s.install' % (shell, command))
|
2012-11-02 01:41:19 +01:00
|
|
|
for sharedir in [sharedir[0] for sharedir in sharedirs]:
|
|
|
|
for dimfile in ('widths', 'heights', 'onlyheights'):
|
|
|
|
files.append(sharedir + '/' + dimfile)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 00:50:35 +02:00
|
|
|
self.removeLists(files, dirs)
|
2012-08-26 15:27:33 +02:00
|
|
|
print()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 00:17:58 +02:00
|
|
|
'''
|
|
|
|
Remove compiled files ponysay is no longer compiling
|
|
|
|
'''
|
|
|
|
def cleanOld(self):
|
|
|
|
print('\033[1;34m::\033[39mCleaning old files...\033[21m')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2013-04-04 14:09:18 +02:00
|
|
|
files = ['truncater', 'ponysaytruncater', 'ponysay.py.install', 'ponysay.install~', 'ponysay.zip']
|
2013-08-18 09:31:19 +02:00
|
|
|
dirs = ['quotes']
|
2012-08-26 04:22:14 +02:00
|
|
|
for shell in [item[0] for item in shells]:
|
|
|
|
files.append('completion/%s-completion.%s.install' % (shell, 'sh' if shell == 'bash' else shell))
|
|
|
|
files.append('completion/%s-completion-think.%s' % (shell, 'sh' if shell == 'bash' else shell))
|
2012-10-29 22:14:04 +01:00
|
|
|
for shell in [item[0] for item in shells]:
|
|
|
|
for command in commands:
|
|
|
|
files.append('completion/%s-completion.%s.%s' % (shell, 'sh' if shell == 'bash' else shell, command))
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 00:50:35 +02:00
|
|
|
self.removeLists(files, dirs)
|
2012-08-26 15:27:33 +02:00
|
|
|
print()
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2013-08-18 09:31:19 +02:00
|
|
|
'''
|
|
|
|
Generate quotes database
|
|
|
|
'''
|
|
|
|
@staticmethod
|
2013-08-18 12:43:03 +02:00
|
|
|
def makeQuotesDatabase(ponydir, quotedir, masterdb, imagedb, filedb, validatehook):
|
2013-08-18 09:31:19 +02:00
|
|
|
allponies = {}
|
|
|
|
ponies = os.listdir(quotedir,)
|
|
|
|
for pony in ponies:
|
|
|
|
parts = pony.split('.')
|
|
|
|
if len(parts) == 2:
|
|
|
|
name = parts[0]
|
|
|
|
index = parts[1]
|
|
|
|
if len(name) * len(index) > 0:
|
|
|
|
if len(index.strip('0123456789')) == 0:
|
|
|
|
if name not in allponies:
|
|
|
|
allponies[name] = set([])
|
|
|
|
allponies[name].add(int(index))
|
|
|
|
|
|
|
|
for pony in allponies.keys():
|
|
|
|
count = max(allponies[pony]) + 1
|
|
|
|
if len(allponies[pony]) != count:
|
|
|
|
print('Index error on quotes for %s' % pony, file = sys.stderr)
|
|
|
|
exit(-1)
|
|
|
|
allponies[pony] = str(count)
|
|
|
|
|
|
|
|
masters = {}
|
|
|
|
ponies = os.listdir(ponydir)
|
|
|
|
for pony in ponies:
|
|
|
|
if (validatehook is not None) and not validatehook(ponydir + '/' + pony):
|
|
|
|
continue
|
|
|
|
if pony.endswith('.pony') and (len(pony) > 5):
|
|
|
|
name = pony[:-5]
|
|
|
|
pony = '%s/%s' % (ponydir, pony)
|
|
|
|
data = None
|
|
|
|
with open(pony, 'rb') as file:
|
|
|
|
data = file.read()
|
|
|
|
data = data.decode('utf-8', 'error')
|
|
|
|
if not data.startswith('$$$\n'):
|
|
|
|
print('%s as no metadata' % pony, file = sys.stderr)
|
|
|
|
exit(-1)
|
|
|
|
data = data[3:]
|
|
|
|
data = data[:data.index('$$$\n')]
|
|
|
|
if '\n\n' in data:
|
|
|
|
data = data[:data.index('\n\n')]
|
|
|
|
master = name
|
|
|
|
if '\nMASTER:' in data:
|
|
|
|
data = data[data.index('\nMASTER:') + 9:] + '\n'
|
|
|
|
data = data[:data.index('\n')]
|
|
|
|
master = data.strip()
|
|
|
|
if master not in masters:
|
|
|
|
masters[master] = []
|
|
|
|
masters[master].append(name)
|
|
|
|
|
|
|
|
by_master = {}
|
|
|
|
by_file = {}
|
|
|
|
|
|
|
|
for master in masters:
|
|
|
|
ponies = masters[master]
|
|
|
|
if master not in allponies:
|
|
|
|
continue
|
|
|
|
count = allponies[master]
|
|
|
|
|
2013-08-18 12:43:03 +02:00
|
|
|
by_master[master] = [count] + filter(lambda p : not os.path.islink('%s/%s.pony' % (ponydir, p)), ponies)
|
2013-08-18 09:31:19 +02:00
|
|
|
for pony in ponies:
|
|
|
|
if pony not in by_file:
|
|
|
|
by_file[pony] = []
|
|
|
|
by_file[pony] += [count, master]
|
|
|
|
|
|
|
|
db = dbm.open(masterdb, 'n')
|
|
|
|
for key in by_master:
|
|
|
|
db[key] = ' '.join(by_master[key])
|
|
|
|
db.close()
|
|
|
|
|
2013-08-18 12:43:03 +02:00
|
|
|
db = dbm.open(imagedb, 'n')
|
|
|
|
for key in filter(lambda p : not os.path.islink('%s/%s.pony' % (ponydir, p)), by_file.keys()):
|
|
|
|
db[key] = ' '.join(by_file[key])
|
|
|
|
db.close()
|
|
|
|
|
2013-08-18 09:31:19 +02:00
|
|
|
db = dbm.open(filedb, 'n')
|
|
|
|
for key in by_file:
|
|
|
|
db[key] = ' '.join(by_file[key])
|
|
|
|
db.close()
|
|
|
|
|
2012-08-26 00:17:58 +02:00
|
|
|
'''
|
|
|
|
Removes listed files and directories
|
|
|
|
'''
|
|
|
|
def removeLists(self, files, dirs):
|
2012-08-26 02:44:51 +02:00
|
|
|
for file in files:
|
2012-08-26 15:27:33 +02:00
|
|
|
if os.path.isfile(file) or os.path.islink(file):
|
2012-08-26 02:44:51 +02:00
|
|
|
print('Unlinking file %s' % (file))
|
|
|
|
os.unlink(file)
|
|
|
|
dir = file
|
|
|
|
while True:
|
2012-08-26 15:27:33 +02:00
|
|
|
dir = dir[:dir.rfind('/')]
|
|
|
|
if ('/ponysay/' in (dir + '/')) and (len(os.listdir(dir)) == 0):
|
|
|
|
print('Removing newly empty directory %s' % (dir))
|
2012-08-26 02:44:51 +02:00
|
|
|
os.rmdir(dir)
|
|
|
|
else:
|
|
|
|
break;
|
|
|
|
for dir in dirs:
|
2012-08-26 15:27:33 +02:00
|
|
|
if os.path.isdir(dir) or os.path.islink(dir):
|
2012-08-26 02:44:51 +02:00
|
|
|
print('Cascadingly removing directory %s' % (dir))
|
|
|
|
if os.path.islink(dir): os.unlink(dir)
|
|
|
|
else: shutil.rmtree(dir)
|
|
|
|
while True:
|
2012-08-26 15:27:33 +02:00
|
|
|
dir = dir[:dir.rfind('/')]
|
|
|
|
if ('/ponysay/' in (dir + '/')) and (len(os.listdir(dir)) == 0):
|
|
|
|
print('Removing newly empty directory %s' % (dir))
|
2012-08-26 02:44:51 +02:00
|
|
|
os.rmdir(dir)
|
|
|
|
else:
|
|
|
|
break;
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-11-02 03:44:21 +01:00
|
|
|
'''
|
2012-12-22 00:59:12 +01:00
|
|
|
Check whether a file is fully free
|
2012-11-02 03:44:21 +01:00
|
|
|
'''
|
2012-12-22 00:59:12 +01:00
|
|
|
@staticmethod
|
|
|
|
def validateFreedom(filename):
|
|
|
|
if not os.path.isdir(filename):
|
|
|
|
if filename.endswith('.pony') and (filename != '.pony') and not filename.endswith('/.pony'):
|
|
|
|
with open(filename, 'rb') as file:
|
|
|
|
data = file.read().decode('utf8', 'replace')
|
|
|
|
if data.startswith('$$$\n') and ('\n$$$\n' in data) and not data.startswith('$$$\n$$$\n'):
|
|
|
|
data = data[4 : data.find('\n$$$\n')].split('\n')
|
|
|
|
for line in data:
|
|
|
|
if ':' not in line:
|
|
|
|
continue
|
|
|
|
line = [item.strip() for item in line.split(':')]
|
|
|
|
if (len(line) == 2) and (line[0] == 'FREE'):
|
|
|
|
return line[1].lower() == 'yes'
|
|
|
|
return False
|
2012-11-02 03:44:21 +01:00
|
|
|
return True
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 04:22:14 +02:00
|
|
|
'''
|
|
|
|
Copys a files or directory to multiple destinations
|
|
|
|
'''
|
2012-11-02 03:44:21 +01:00
|
|
|
def cp(self, recursive, source, destinations, validatehook = None):
|
|
|
|
if validatehook is not None:
|
|
|
|
if not validatehook(source):
|
|
|
|
print('Ignoring installation of file %s (did not pass validation process made by setup settings)' % source)
|
2012-12-22 01:04:34 +01:00
|
|
|
return
|
2012-08-27 03:02:34 +02:00
|
|
|
if os.path.islink(source) and (self.linking != COPY) and os.path.isdir(os.path.realpath(source)):
|
|
|
|
target = os.readlink(source)
|
|
|
|
for dest in destinations:
|
|
|
|
print('Creating symbolic link %s with target directory %s' % (dest, target))
|
|
|
|
if os.path.exists(dest):
|
|
|
|
self.removeLists([], [dest])
|
2012-09-11 11:35:55 +02:00
|
|
|
self.symlink(target, dest)
|
2012-08-27 03:02:34 +02:00
|
|
|
if os.path.islink(source) and (self.linking != COPY) and os.path.isfile(os.path.realpath(source)):
|
|
|
|
target = os.readlink(source)
|
|
|
|
if self.linking == HARD:
|
|
|
|
for dest in destinations:
|
|
|
|
print('Creating hard link %s with target file %s' % (dest, target))
|
|
|
|
if os.path.exists(dest):
|
|
|
|
self.removeLists([], [dest])
|
|
|
|
mytarget = os.path.abspath(os.path.join(os.path.dirname(dest), target))
|
|
|
|
if os.path.exists(mytarget):
|
|
|
|
os.link(mytarget, dest)
|
|
|
|
else:
|
|
|
|
print('\033[31mTarget did not exists, using symlink instead\033[39m')
|
2012-09-11 11:35:55 +02:00
|
|
|
self.symlink(target, dest)
|
2012-08-27 03:02:34 +02:00
|
|
|
else:
|
|
|
|
for dest in destinations:
|
|
|
|
print('Creating symbolic link %s with target file %s' % (dest, target))
|
|
|
|
if os.path.exists(dest):
|
|
|
|
self.removeLists([], [dest])
|
2012-09-11 11:35:55 +02:00
|
|
|
self.symlink(target, dest)
|
2012-08-26 04:22:14 +02:00
|
|
|
for dest in destinations:
|
|
|
|
dir = dest[:dest.rfind('/') + 1]
|
|
|
|
if not os.path.exists(dir):
|
|
|
|
print('Making directory ' + dir + ' with parents')
|
|
|
|
os.makedirs(dir)
|
|
|
|
if recursive:
|
|
|
|
target = destinations[0]
|
|
|
|
for dest in destinations if self.linking == COPY else [target]:
|
|
|
|
print('Copying directory %s to %s' % (source, dest))
|
|
|
|
if not os.path.exists(dest):
|
|
|
|
os.mkdir(dest)
|
2012-08-27 03:02:34 +02:00
|
|
|
links = []
|
2012-08-26 04:22:14 +02:00
|
|
|
for file in os.listdir(source):
|
|
|
|
src = source + '/' + file
|
2012-08-27 03:02:34 +02:00
|
|
|
if os.path.exists(src) and os.path.islink(src):
|
|
|
|
links.append((os.path.isdir(src), src, [dest + '/' + file]))
|
|
|
|
else:
|
2012-12-22 00:59:12 +01:00
|
|
|
self.cp(os.path.isdir(src), src, [dest + '/' + file], validatehook)
|
2012-08-27 03:02:34 +02:00
|
|
|
for link in links:
|
2012-12-22 00:59:12 +01:00
|
|
|
self.cp(link[0], link[1], link[2], validatehook)
|
2012-08-26 04:22:14 +02:00
|
|
|
if self.linking != COPY:
|
|
|
|
for dest in destinations[1:]:
|
|
|
|
print('Creating symbolic link %s with target directory %s' % (dest, target))
|
2012-08-26 15:27:33 +02:00
|
|
|
if os.path.exists(dest):
|
2012-08-27 03:02:34 +02:00
|
|
|
self.removeLists([], [dest])
|
2012-09-11 11:35:55 +02:00
|
|
|
self.symlink(target, dest)
|
2012-08-26 04:22:14 +02:00
|
|
|
else:
|
|
|
|
target = destinations[0]
|
|
|
|
for dest in destinations if self.linking == COPY else [target]:
|
|
|
|
print('Copying file %s to %s' % (source, dest))
|
|
|
|
shutil.copyfile(source, dest)
|
|
|
|
if self.linking == HARD:
|
|
|
|
for dest in destinations[1:]:
|
|
|
|
print('Creating hard link %s with target file %s' % (dest, target))
|
2012-08-26 15:27:33 +02:00
|
|
|
if os.path.exists(dest):
|
|
|
|
os.unlink(dest)
|
2012-08-26 04:22:14 +02:00
|
|
|
os.link(target, dest)
|
|
|
|
elif self.linking == SYMBOLIC:
|
|
|
|
for dest in destinations[1:]:
|
|
|
|
print('Creating symbolic link %s with target file %s' % (dest, target))
|
2012-08-26 15:27:33 +02:00
|
|
|
if os.path.exists(dest):
|
|
|
|
os.unlink(dest)
|
2012-09-11 11:35:55 +02:00
|
|
|
self.symlink(target, dest)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-11 11:35:55 +02:00
|
|
|
'''
|
|
|
|
Create a symlink with a relative path
|
|
|
|
'''
|
|
|
|
def symlink(self, target, dest):
|
|
|
|
if target.startswith('./') or target.startswith('../'):
|
|
|
|
os.symlink(target, dest)
|
|
|
|
elif '/' not in target:
|
|
|
|
os.symlink('./' + target, dest)
|
|
|
|
else:
|
|
|
|
targets = target.split('/')
|
|
|
|
dests = dest.split('/')
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-13 19:59:56 +02:00
|
|
|
while (len(targets) > 1) and (len(dests) > 1) and (targets[0] == dests[0]):
|
2012-09-11 11:35:55 +02:00
|
|
|
targets = targets[1:]
|
|
|
|
dests = dests[1:]
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-11 11:35:55 +02:00
|
|
|
if (len(dests) == 1):
|
|
|
|
targets = ['.'] + targets
|
|
|
|
else:
|
|
|
|
targets = (['..'] * (len(dests) - 1)) + targets
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-11 11:35:55 +02:00
|
|
|
os.symlink('/'.join(targets), dest)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-23 18:22:54 +02:00
|
|
|
'''
|
|
|
|
Parses configurations
|
|
|
|
'''
|
|
|
|
def configure(self, opts):
|
|
|
|
(defaults, conf) = ({}, {})
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-23 18:22:54 +02:00
|
|
|
for command in commands:
|
2012-08-25 23:41:43 +02:00
|
|
|
conf[command] = '/usr/bin/' + command
|
2012-08-23 18:22:54 +02:00
|
|
|
conf['shared-cache'] = '/var/cache/ponysay'
|
|
|
|
for shell in shells:
|
|
|
|
conf[shell[0]] = shell[1]
|
|
|
|
conf['pdf'] = '/usr/doc'
|
|
|
|
conf['pdf-compression'] = 'gz'
|
|
|
|
conf['info'] = '/usr/share/info'
|
2012-08-25 21:26:35 +02:00
|
|
|
conf['info-install'] = 'My Little Ponies for your terminal'
|
2012-08-23 18:22:54 +02:00
|
|
|
conf['info-compression'] = 'gz'
|
|
|
|
for manpage in manpages:
|
|
|
|
conf['man-' + manpage[0]] = '/usr/share/man'
|
|
|
|
conf['man-' + manpage[0] + '-compression'] = 'gz'
|
2013-04-01 19:21:03 +02:00
|
|
|
conf['custom-env-python'] = 'python3'
|
2012-08-23 18:22:54 +02:00
|
|
|
for sharedir in sharedirs:
|
2013-04-01 19:21:03 +02:00
|
|
|
conf[sharedir[0]] = True
|
2012-08-23 18:22:54 +02:00
|
|
|
for sharefile in sharefiles:
|
2013-04-01 19:21:03 +02:00
|
|
|
conf[sharefile[0]] = True
|
2012-08-26 04:30:57 +02:00
|
|
|
for miscfile in miscfiles:
|
|
|
|
conf[miscfile[0]] = miscfile[1]
|
2012-11-02 02:34:33 +01:00
|
|
|
conf['sysconf-dir'] = '/etc'
|
2013-04-01 19:21:03 +02:00
|
|
|
conf['bin-dir'] = '/usr/bin'
|
|
|
|
conf['lib-dir'] = '/usr/lib/ponysay'
|
|
|
|
conf['libexec-dir'] = '/usr/libexec/ponysay'
|
|
|
|
conf['share-dir'] = '/usr/share'
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-24 22:04:01 +02:00
|
|
|
if opts['--private'] is not None:
|
|
|
|
if opts['--prefix'] is None:
|
2012-08-25 23:41:43 +02:00
|
|
|
opts['--prefix'] = [os.environ['HOME'] + '/.local']
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-24 22:04:01 +02:00
|
|
|
prefix = '/usr'
|
|
|
|
if opts['--prefix'] is not None:
|
|
|
|
prefix = opts['--prefix'][0]
|
|
|
|
for key in conf:
|
2012-08-25 23:41:43 +02:00
|
|
|
if conf[key] not in (None, False, True):
|
|
|
|
if conf[key].startswith('/usr'):
|
|
|
|
conf[key] = prefix + conf[key][4:]
|
2012-08-26 00:17:58 +02:00
|
|
|
conf['~prefix~'] = prefix
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 21:26:35 +02:00
|
|
|
if opts['--opt'] is not None:
|
2013-04-03 23:49:21 +02:00
|
|
|
if opts['--bin-dir'] is None: opts['--bin-dir'] = ['/opt/ponysay']
|
|
|
|
if opts['--lib-dir'] is None: opts['--lib-dir'] = ['/opt/ponysay']
|
|
|
|
if opts['--libexec-dir'] is None: opts['--libexec-dir'] = ['/opt/ponysay']
|
|
|
|
if opts['--share-dir'] is None: opts['--share-dir'] = ['/opt/ponysay']
|
2012-08-25 23:41:43 +02:00
|
|
|
if opts['--with-shared-cache'] is None: opts['--with-shared-cache'] = ['/var/opt/ponysay/cache']
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-09-29 23:08:13 +02:00
|
|
|
for dir in ['bin', 'lib', 'libexec', 'share']:
|
2013-04-03 23:49:21 +02:00
|
|
|
key = dir + '-dir'
|
|
|
|
if opts['--' + key] is not None:
|
|
|
|
conf[key] = opts['--' + key][0]
|
2013-04-04 10:56:56 +02:00
|
|
|
if (dir == 'share') and (opts['--opt'] is None):
|
|
|
|
conf[key] += '/ponysay'
|
2013-04-03 23:49:21 +02:00
|
|
|
if conf[key].startswith('usr/'):
|
|
|
|
conf[key] = prefix + conf[key][3:]
|
2012-08-24 22:04:01 +02:00
|
|
|
if opts['--cache-dir'] is not None:
|
|
|
|
dir = opts['--cache-dir'][0]
|
|
|
|
for key in conf:
|
2012-08-25 23:41:43 +02:00
|
|
|
if conf[key] not in (None, False, True):
|
|
|
|
if conf[key].startswith('/var/cache'):
|
|
|
|
conf[key] = dir + conf[key][10:]
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-11-02 02:34:33 +01:00
|
|
|
if opts['--sysconf-dir'] is not None:
|
2013-04-01 19:21:03 +02:00
|
|
|
conf['sysconf-dir'] = opts['--sysconf-dir'][0]
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 23:41:43 +02:00
|
|
|
for key in conf:
|
|
|
|
defaults[key] = conf[key]
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 21:26:35 +02:00
|
|
|
if opts['--nothing'] is not None:
|
|
|
|
opts['--minimal'] = opts['--nothing']
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 23:05:14 +02:00
|
|
|
for key in ['custom-env-python']:
|
2012-08-23 18:22:54 +02:00
|
|
|
conf[key] = None
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 23:41:43 +02:00
|
|
|
if opts['--everything'] is None:
|
2012-08-25 23:05:14 +02:00
|
|
|
for key in ['pdf', 'pdf-compression']:
|
2012-08-25 21:26:35 +02:00
|
|
|
conf[key] = None
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 21:26:35 +02:00
|
|
|
nomanen = opts['--minimal'] is not None
|
|
|
|
for manpage in manpages:
|
2012-08-25 23:41:43 +02:00
|
|
|
if (manpage is not manpages[0]) or nomanen:
|
|
|
|
for key in ['man-' + manpage[0]]:
|
2012-08-25 21:26:35 +02:00
|
|
|
conf[key] = None
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 21:26:35 +02:00
|
|
|
if (opts['--private'] is not None) or (opts['--minimal'] is not None):
|
2012-08-25 23:05:14 +02:00
|
|
|
for key in ['info-install', 'shared-cache']:
|
2012-08-24 22:04:01 +02:00
|
|
|
conf[key] = None
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 21:26:35 +02:00
|
|
|
if opts['--minimal'] is not None:
|
2012-08-26 14:50:01 +02:00
|
|
|
for key in ['info'] + [item[0] for item in shells]:
|
2012-08-25 21:26:35 +02:00
|
|
|
conf[key] = None
|
2012-08-25 21:47:53 +02:00
|
|
|
for sharedir in sharedirs:
|
|
|
|
if sharedir is not sharedirs[0]:
|
|
|
|
conf[sharedir[0]] = None
|
2012-08-25 23:41:43 +02:00
|
|
|
for sharefile in sharefiles:
|
|
|
|
conf[sharefile[0]] = None
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 21:26:35 +02:00
|
|
|
if opts['--nothing'] is not None:
|
|
|
|
for command in commands:
|
2012-08-26 14:50:01 +02:00
|
|
|
conf[command] = None
|
2012-08-25 23:41:43 +02:00
|
|
|
conf[sharedirs[0][0]] = None
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-25 23:05:14 +02:00
|
|
|
for coll in [['shell', '/usr/share', [item[0] for item in shells]],
|
|
|
|
['man', '/usr/share/man', ['man-' + item[0] for item in manpages]],
|
|
|
|
['man-compression', 'gz', ['man-' + item[0] + '-compression' for item in manpages]]
|
|
|
|
]:
|
2012-08-23 18:22:54 +02:00
|
|
|
if opts['--without-' + coll[0]] is not None:
|
|
|
|
for item in coll[2]:
|
|
|
|
conf[item] = None
|
|
|
|
if opts['--with-' + coll[0]] is not None:
|
|
|
|
for item in coll[2]:
|
|
|
|
defaults[item] = conf[item] = defaults[item].replace(coll[1], coll[1] if opts['--with-' + coll[0]][0] is None else opts['--with-' + coll[0]][0]);
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-23 18:22:54 +02:00
|
|
|
for key in conf:
|
2012-08-26 14:50:01 +02:00
|
|
|
if '--with-' + key not in opts:
|
2012-08-26 07:09:39 +02:00
|
|
|
continue
|
2012-08-23 18:22:54 +02:00
|
|
|
if opts['--with-' + key] is not None:
|
|
|
|
if defaults[key] in (False, True):
|
|
|
|
conf[key] = True
|
|
|
|
else:
|
|
|
|
conf[key] = defaults[key] if opts['--with-' + key][0] is None else opts['--with-' + key][0]
|
|
|
|
if opts['--without-' + key] is not None:
|
|
|
|
conf[key] = False if defaults[key] in (False, True) else None
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-23 18:22:54 +02:00
|
|
|
for mansection in mansections:
|
|
|
|
if opts['--man-section-' + mansection[0]] is not None:
|
2012-08-26 14:50:01 +02:00
|
|
|
conf['man-section-' + mansection[0]] = opts['--man-section-' + mansection[0]][0]
|
2012-08-23 18:22:54 +02:00
|
|
|
else:
|
|
|
|
conf['man-section-' + mansection[0]] = mansection[1]
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 23:26:32 +02:00
|
|
|
self.destDir = None if opts['--dest-dir'] is None else opts['--dest-dir'][0]
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 23:26:32 +02:00
|
|
|
return conf
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 23:26:32 +02:00
|
|
|
def applyDestDir(self, conf):
|
|
|
|
if self.destDir is not None:
|
2012-08-24 22:04:01 +02:00
|
|
|
for key in conf:
|
2012-08-25 23:41:43 +02:00
|
|
|
if conf[key] not in (None, False, True):
|
2012-08-27 17:32:26 +02:00
|
|
|
if conf[key].startswith('/'):
|
2012-08-27 23:26:32 +02:00
|
|
|
conf[key] = self.destDir + conf[key]
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-27 23:26:32 +02:00
|
|
|
def unapplyDestDir(self, conf):
|
|
|
|
if self.destDir is not None:
|
|
|
|
for key in conf:
|
|
|
|
if conf[key] not in (None, False, True):
|
|
|
|
if conf[key].startswith(self.destDir):
|
|
|
|
conf[key] = conf[key][len(self.destDir):]
|
2012-08-23 07:20:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
ARGUMENTLESS = 0
|
|
|
|
ARGUMENTED = 1
|
|
|
|
'''
|
|
|
|
Simple argument parser, a strip down of the one in ponysay and slitly modified
|
|
|
|
'''
|
|
|
|
class ArgParser():
|
|
|
|
'''
|
|
|
|
Constructor.
|
|
|
|
The short description is printed on same line as the program name
|
|
|
|
'''
|
|
|
|
def __init__(self, program, description, usage, longdescription = None):
|
|
|
|
self.__program = program
|
|
|
|
self.__description = description
|
|
|
|
self.__usage = usage
|
|
|
|
self.__longdescription = longdescription
|
|
|
|
self.__arguments = []
|
|
|
|
(self.opts, self.optmap) = ({}, {})
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-23 07:20:49 +02:00
|
|
|
'''
|
|
|
|
Add option that takes no arguments
|
|
|
|
'''
|
|
|
|
def add_argumentless(self, alternatives, help = None):
|
|
|
|
ARGUMENTLESS
|
|
|
|
self.__arguments.append((ARGUMENTLESS, alternatives, None, help))
|
|
|
|
(stdalt, self.opts[stdalt]) = (alternatives[0], None)
|
|
|
|
for alt in alternatives: self.optmap[alt] = (stdalt, ARGUMENTLESS)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-23 07:20:49 +02:00
|
|
|
'''
|
|
|
|
Add option that takes one argument
|
|
|
|
'''
|
|
|
|
def add_argumented(self, alternatives, arg, help = None):
|
|
|
|
self.__arguments.append((ARGUMENTED, alternatives, arg, help))
|
|
|
|
(stdalt, self.opts[stdalt]) = (alternatives[0], None)
|
|
|
|
for alt in alternatives: self.optmap[alt] = (stdalt, ARGUMENTED)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-23 07:20:49 +02:00
|
|
|
'''
|
|
|
|
Parse arguments
|
|
|
|
'''
|
|
|
|
def parse(self, argv = sys.argv):
|
|
|
|
self.argcount = len(argv) - 1
|
|
|
|
self.files = []
|
2012-08-23 18:22:54 +02:00
|
|
|
(argqueue, optqueue, get) = ([], [], False)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-26 00:50:35 +02:00
|
|
|
for arg in argv[1:]:
|
2012-08-23 18:22:54 +02:00
|
|
|
if get:
|
|
|
|
get = False
|
2012-08-26 07:09:39 +02:00
|
|
|
if (arg is argv[-1]) or ((len(arg) > 2) and (arg[:2] in ('--', '++'))):
|
2012-08-23 18:22:54 +02:00
|
|
|
argqueue.append(None)
|
|
|
|
else:
|
|
|
|
argqueue.append(arg)
|
|
|
|
continue
|
|
|
|
if (len(arg) > 2) and (arg[:2] in ('--', '++')):
|
|
|
|
if (arg in self.optmap) and (self.optmap[arg][1] == ARGUMENTLESS):
|
|
|
|
optqueue.append(arg)
|
|
|
|
argqueue.append(None)
|
|
|
|
elif '=' in arg:
|
|
|
|
arg_opt = arg[:arg.index('=')]
|
|
|
|
if (arg_opt in self.optmap) and (self.optmap[arg_opt][1] == ARGUMENTED):
|
|
|
|
optqueue.append(arg_opt)
|
|
|
|
argqueue.append(arg[arg.index('=') + 1:])
|
2012-08-23 07:20:49 +02:00
|
|
|
else:
|
2012-08-26 04:22:14 +02:00
|
|
|
sys.stderr.write('%s: fatal: unrecognised option %s. see --help or the manual\n' % (self.__program, arg))
|
|
|
|
exit(-1)
|
2012-08-23 18:22:54 +02:00
|
|
|
elif (arg in self.optmap) and (self.optmap[arg][1] == ARGUMENTED):
|
|
|
|
optqueue.append(arg)
|
|
|
|
get = True
|
2012-08-23 07:20:49 +02:00
|
|
|
else:
|
2012-08-23 18:22:54 +02:00
|
|
|
sys.stderr.write('%s: fatal: unrecognised option %s. see --help or the manual\n' % (self.__program, arg))
|
|
|
|
exit(-1)
|
2012-08-23 07:20:49 +02:00
|
|
|
else:
|
|
|
|
self.files.append(arg)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-23 07:20:49 +02:00
|
|
|
(i, n) = (0, len(optqueue))
|
2012-08-23 18:22:54 +02:00
|
|
|
if len(argqueue) < n:
|
|
|
|
argqueue.append(None)
|
2012-08-23 07:20:49 +02:00
|
|
|
while i < n:
|
|
|
|
(opt, arg, i) = (optqueue[i], argqueue[i], i + 1)
|
|
|
|
opt = self.optmap[opt][0]
|
|
|
|
if (opt not in self.opts) or (self.opts[opt] is None):
|
2012-08-26 17:34:21 +02:00
|
|
|
self.opts[opt] = [arg]
|
|
|
|
else:
|
2012-08-26 18:13:29 +02:00
|
|
|
sys.stderr.write('%s: fatal: duplicate option %s\n' % (self.__program, arg))
|
2012-08-26 17:34:21 +02:00
|
|
|
exit(-1)
|
2013-05-21 15:36:35 +02:00
|
|
|
|
2012-08-23 07:20:49 +02:00
|
|
|
'''
|
|
|
|
Prints a colourful help message
|
|
|
|
'''
|
|
|
|
def help(self):
|
|
|
|
print('\033[1m%s\033[21m - %s\n' % (self.__program, self.__description))
|
|
|
|
if self.__longdescription is not None:
|
|
|
|
print(self.__longdescription)
|
|
|
|
print()
|
|
|
|
print('\n\033[1mUSAGE:\033[21m', end='')
|
|
|
|
first = True
|
|
|
|
for line in self.__usage.split('\n'):
|
|
|
|
if first: first = False
|
|
|
|
else: print(' or', end='')
|
|
|
|
print('\t%s' % (line))
|
|
|
|
print('\n\033[1mCONFIGURATIONS:\033[21m\n')
|
|
|
|
for opt in self.__arguments:
|
|
|
|
(opt_type, opt_alts, opt_arg, opt_help) = opt[0:4]
|
|
|
|
if opt_help is not None:
|
|
|
|
for opt_alt in opt_alts:
|
|
|
|
if opt_alt is opt_alts[-1]:
|
2013-06-01 08:30:04 +02:00
|
|
|
print('\t%s=\033[4m%s\033[24m' % (opt_alt, opt_arg) if opt_type == ARGUMENTED else '\t' + opt_alt)
|
2012-08-23 07:20:49 +02:00
|
|
|
else:
|
|
|
|
print('\t\033[2m' + opt_alt + '\033[22m')
|
|
|
|
first = True
|
|
|
|
for line in opt_help.split('\n'):
|
|
|
|
print(('\t\t\033[32;1m%s\033[21;39m' if first else '\t\t%s') % (line))
|
|
|
|
first = False
|
|
|
|
print()
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
Setup()
|