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
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Installation and deployment script."""
from __future__ import print_function
import os
import sys
import run_tests
try:
from setuptools import find_packages, setup, Command
except ImportError:
from distutils.core import find_packages, setup, Command
try:
from setuptools.commands.bdist_rpm import bdist_rpm
except ImportError:
from distutils.command.bdist_rpm import bdist_rpm
if sys.version < '2.7':
print('Unsupported Python version: {0:s}.'.format(sys.version))
print('Supported Python versions are 2.7 or a later 2.x version.')
sys.exit(1)
# Change PYTHONPATH to include dfdatetime so that we can get the version.
sys.path.insert(0, '.')
import dfdatetime
class BdistRPMCommand(bdist_rpm):
"""Custom handler for the bdist_rpm command."""
def _make_spec_file(self):
"""Generates the text of an RPM spec file.
Returns:
A list of strings containing the lines of text.
"""
# Note that bdist_rpm can be an old style class.
if issubclass(BdistRPMCommand, object):
spec_file = super(BdistRPMCommand, self)._make_spec_file()
else:
spec_file = bdist_rpm._make_spec_file(self)
if sys.version_info[0] < 3:
python_package = 'python'
else:
python_package = 'python3'
description = []
summary = ''
in_description = False
python_spec_file = []
for index, line in enumerate(spec_file):
if line.startswith('Summary: '):
summary = line
elif line.startswith('BuildRequires: '):
line = 'BuildRequires: {0:s}-setuptools'.format(python_package)
elif line.startswith('Requires: '):
if python_package == 'python3':
line = line.replace('python', 'python3')
elif line.startswith('%description'):
in_description = True
elif line.startswith('%files'):
line = '%files -f INSTALLED_FILES -n {0:s}-%{{name}}'.format(
python_package)
elif line.startswith('%prep'):
in_description = False
python_spec_file.append(
'%package -n {0:s}-%{{name}}'.format(python_package))
python_spec_file.append('{0:s}'.format(summary))
python_spec_file.append('')
python_spec_file.append(
'%description -n {0:s}-%{{name}}'.format(python_package))
python_spec_file.extend(description)
elif in_description:
# Ignore leading white lines in the description.
if not description and not line:
continue
description.append(line)
python_spec_file.append(line)
return python_spec_file
class TestCommand(Command):
"""Run tests, implementing an interface."""
user_options = []
def initialize_options(self):
self._dir = os.getcwd()
def finalize_options(self):
pass
def run(self):
test_results = run_tests.RunTests(os.path.join('.', 'dfdatetime'))
dfdatetime_version = dfdatetime.__version__
# Command bdist_msi does not support the library version, neither a date
# as a version but if we suffix it with .1 everything is fine.
if 'bdist_msi' in sys.argv:
dfdatetime_version += '.1'
dfdatetime_description = (
'Digital Forensics Date and Time (dfDateTime).')
dfdatetime_long_description = (
'dfDateTime, or Digital Forensics date and time, provides date and time '
'objects to preserve accuracy and precision.')
setup(
name='dfdatetime',
version=dfdatetime_version,
description=dfdatetime_description,
long_description=dfdatetime_long_description,
license='Apache License, Version 2.0',
url='https://github.com/log2timeline/dfdatetime',
maintainer='dfDateTime development team',
maintainer_email='log2timeline-dev@googlegroups.com',
cmdclass={
'bdist_rpm': BdistRPMCommand,
'test': TestCommand},
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Operating System :: OS Independent',
'Programming Language :: Python',
],
packages=find_packages('.', exclude=[
'examples', 'tests', 'tests.*', 'utils']),
package_dir={
'dfdatetime': 'dfdatetime'
},
data_files=[
('share/doc/dfdatetime', [
'AUTHORS', 'ACKNOWLEDGEMENTS', 'LICENSE', 'README']),
],
)
|