1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
#!/usr/bin/python
from distutils.command.build import build
from distutils.command.install import install
from distutils.core import Command, setup
import distutils.sysconfig
import os
import os.path
import re
import shutil
import subprocess
import sys
import tempfile
# Default prefix
prefix = ''
# Get the install prefix if one is specified from the command line
for i, arg in enumerate(sys.argv):
prefix_regex = re.compile('(?P<prefix>--prefix)?[\=\s]?(?P<path>/[\w\s/]*)')
if prefix_regex.match(arg):
if prefix_regex.match(arg).group('prefix') and not prefix_regex.match(arg).group('path'):
# We got --prefix with a space instead of an equal. The next arg will have our path.
prefix = os.path.expandvars(prefix_regex.match(sys.argv[i+1]).group('path'))
elif prefix_regex.match(arg).group('path'):
prefix = prefix_regex.match(arg).group('path')
elif (sys.argv[i-1] == '--prefix') and prefix_regex.match(arg).group('path'):
prefix = os.path.expandvars(prefix_regex.match(arg).group('path'))
data_files = [(os.path.join(prefix,'share/man/man1/'),
['doc/turnin.1', 'doc/turnincfg.1'])]
def check_executable_in_path(executable, message):
""" Checks that executable is installed in the system's PATH and returns
it's location.
"""
if os.environ.has_key('PATH'):
for directory in os.environ['PATH'].split(':'):
if os.path.exists(os.path.join(directory, executable)):
return os.path.join(directory, executable)
else:
for directory in ['/usr/bin', '/usr/local/bin']:
if os.path.exists(os.path.join(directory, executable)):
return os.path.join(directory, executable)
print message
return False
class build_htmldocs(Command):
description = 'Generate the HTML documentation.'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
""" Call texi2html on the Texinfo document. """
texi2html = check_executable_in_path('texi2html',
"Please install the texi2html executable to generate the HTML " +
"documentation")
if texi2html:
cargs = [texi2html, '--init-file=doc/turnin-ng.texi.init', 'doc/turnin-ng.texi']
retcode = subprocess.call(cargs)
if retcode < 0:
raise subprocess.CalledProcessError(retcode, ' '.join(cargs))
os.rename('turnin-ng.html', 'doc/turnin-ng.html')
data_files.append((os.path.join(prefix, 'share/doc/turnin-ng/'),
['doc/turnin-ng.html']))
build.sub_commands.append(('build_htmldocs', None))
class build_infopage(Command):
description = 'Generate the info document.'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
""" Call makeinfo on the Texinfo document. """
makeinfo = check_executable_in_path('makeinfo',
"Please install the makeinfo executable to generate the info document")
if makeinfo:
cargs = [makeinfo, '-o', 'doc/turnin-ng.info', 'doc/turnin-ng.texi']
retcode = subprocess.call(cargs)
if retcode < 0:
raise subprocess.CalledProcessError(retcode, ' '.join(cargs))
data_files.append((os.path.join(prefix, 'share/info/'),
['doc/turnin-ng.info']))
build.sub_commands.append(('build_infopage', None))
class build_pdf(Command):
description = 'Generate the pdf document.'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
""" Call texi2pdf on the Texinfo document. """
texi2pdf = check_executable_in_path('texi2pdf',
"Please install texi2pdf to generate the PDF documentation")
if texi2pdf:
tempdir = tempfile.mkdtemp()
shutil.copy(os.path.join('doc', 'turnin-ng.texi'), tempdir)
shutil.copy(os.path.join('doc', 'gpl-2.0.texi'), tempdir)
doc = os.path.join(os.getcwd(), 'doc')
os.chdir(tempdir)
success = True
cargs = [texi2pdf, 'turnin-ng.texi']
# We need to call texi2pdf twice.
for i in range(1):
retcode = subprocess.call(cargs)
if retcode < 0:
success = False
raise subprocess.CalledProcessError(retcode, ' '.join(cargs))
break
if success:
try:
shutil.copy('turnin-ng.pdf', doc)
shutil.rmtree(tempdir, ignore_errors=True)
# This is required so that the install command can find the
# build directory. Without it, it searches for it in the
# non-existent tempdir.
os.chdir(os.path.join(doc, os.pardir))
data_files.append((os.path.join(prefix, 'share/doc/turnin-ng/'),
['doc/turnin-ng.pdf']))
except:
print 'An error has occured, skipping PDF documentation.'
build.sub_commands.append(('build_pdf', None))
class build_legacy(Command):
description = 'Include the legacy files from renaming project to turnincfg'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
data_files.append((os.path.join(prefix, 'share/man/man1'),
['doc/project.1']))
build.sub_commands.append(('build_legacy', None))
class install_legacy(Command):
description = 'Install the legacy symlink of project to turnincfg'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
print os.path.join(prefix, 'bin/turnincfg')
os.symlink(os.path.join(prefix, 'bin/turnincfg'), os.path.join(prefix,
'bin/project'))
# We've manually taken care of this in the packaging (debian/turnin-ng.links),
# otherwise the build fails.
# install.sub_commands.append(('install_legacy', None))
setup(name='turnin-ng',
version='1.0.1',
description='Turn in your assignments with turnin',
author='Ryan Kavanagh',
author_email='ryanakca@kubuntu.org',
license='GNU General Public License version 2, or (at your option) ' +\
'any later version',
scripts=['src/bin/turnincfg', 'src/bin/turnin'],
packages=['turninng'],
package_dir={'turninng':'src/turninng'},
data_files=data_files,
cmdclass={'build_infopage': build_infopage, 'build_pdf':build_pdf,
'build_htmldocs': build_htmldocs, 'build_legacy': build_legacy#,
#'install_legacy': install_legacy} # Commented out for packaging link
}
)
|