File: setup.py

package info (click to toggle)
libewf 20140608-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 18,424 kB
  • ctags: 8,253
  • sloc: ansic: 297,847; sh: 13,697; cpp: 4,381; makefile: 1,972; yacc: 1,094; lex: 390; python: 352; sed: 134
file content (152 lines) | stat: -rw-r--r-- 3,573 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python
import glob
import platform
import os
import shutil
import sys

from distutils import sysconfig
from distutils.command.bdist import bdist
from distutils.command.sdist import sdist
from distutils.core import setup, Extension


# Custom handler for the setup.py bdist_rpm command.
class custom_bdist_rpm(bdist):
	def run(self):
		print "'setup.py bdist_rpm' command not supported use 'rpmbuild' instead."
		sys.exit(1)


# Custom handler for the setup.py sdist command.
class custom_sdist(sdist):
	def run(self):
		print "'setup.py sdist' command not supported use 'make dist' instead."
		sys.exit(1)


LIBRARY_NAME = "libewf"
LIBRARY_VERSION = "20140608"
MODULE_NAME = "py%s" % (LIBRARY_NAME[3:])
# bdist_msi does not support the library version, neither a date as a version.
MODULE_VERSION = "20140608.1"
PROJECT_URL = "http://code.google.com/p/%s/" % (LIBRARY_NAME)

DIRECTORY_NAMES = [
	"common",
	"include",
	"libcstring",
	"libcerror",
	"libcdata",
	"libclocale",
	"libcsplit",
	"libuna",
	"libcfile",
	"libcpath",
	"libbfio",
]

INCLUDE_DIRS = []

for directory_name in DIRECTORY_NAMES:
	INCLUDE_DIRS.append(os.path.join("..", directory_name))

LIBRARY_NAMES = [
	"libcstring",
	"libcerror",
	"libcdata",
	"libclocale",
	"libcsplit",
	"libuna",
	"libcfile",
	"libcpath",
	"libbfio",
	"%s" % (LIBRARY_NAME),
]

LIBRARIES = []
LIBRARY_DIRS = []
LIBRARY_DATA_FILES = []

PYTHON_LIBRARY_DIRECTORY = sysconfig.get_python_lib(True)
_, _, PYTHON_LIBRARY_DIRECTORY = PYTHON_LIBRARY_DIRECTORY.rpartition(sysconfig.PREFIX)

if PYTHON_LIBRARY_DIRECTORY.startswith(os.sep):
	PYTHON_LIBRARY_DIRECTORY = PYTHON_LIBRARY_DIRECTORY[1:]

if platform.system() == "Windows":
	DEFINE_MACROS = [
		("HAVE_LOCAL_LIBCSTRING", ""),
		("HAVE_LOCAL_LIBCERROR", ""),
		("HAVE_LOCAL_LIBCDATA", ""),
		("HAVE_LOCAL_LIBCLOCALE", ""),
		("HAVE_LOCAL_LIBCSPLIT", ""),
		("HAVE_LOCAL_LIBUNA", ""),
		("HAVE_LOCAL_LIBCFILE", ""),
		("HAVE_LOCAL_LIBCPATH", ""),
		("HAVE_LOCAL_LIBBFIO", ""),
		("%s_DLL_IMPORT" % (LIBRARY_NAME.upper()), ""),
	]
	for library_name in LIBRARY_NAMES:
		LIBRARIES.append(library_name)

	library_directory = os.path.join("..", "msvscpp", "Release")

	LIBRARY_DIRS.append(library_directory)

	LIBRARY_DLL_FILES = [
		"%s.dll" % (LIBRARY_NAME),
		"zlib.dll",
	]
	for library_dll_filename in LIBRARY_DLL_FILES:
		library_dll_file = os.path.join(library_directory, library_dll_filename)

		if not os.path.exists(library_dll_file):
			print "No such file: %s" % (library_dll_file)
			sys.exit(1)

		LIBRARY_DATA_FILES.append(library_dll_file)

else:
	DEFINE_MACROS = [
		("HAVE_CONFIG_H", ""),
	]
	for library_name in LIBRARY_NAMES:
		library_directory = os.path.join("..", library_name)

		LIBRARY_DIRS.append(library_directory)

# Add the LICENSE file to the distribution.
copying_file = os.path.join("..", "COPYING")
license_file = "LICENSE.%s" % (LIBRARY_NAME)

shutil.copyfile(copying_file, license_file)

LIBRARY_DATA_FILES.append(license_file)

# TODO: what about description and platform in egg file

setup(
	name = MODULE_NAME,
	url = PROJECT_URL,
	version = MODULE_VERSION,
	description = "Python bindings module for %s" % (MODULE_NAME),
	author = "Joachim Metz",
	author_email = "joachim.metz@gmail.com",
	cmdclass = {
		"bdist_rpm": custom_bdist_rpm,
		"sdist": custom_sdist,
	},
	ext_modules = [
		Extension(
			MODULE_NAME,
			glob.glob("*.c"),
			define_macros = DEFINE_MACROS,
			include_dirs = INCLUDE_DIRS,
			libraries = LIBRARIES,
			library_dirs = LIBRARY_DIRS,
		),
	],
	data_files = [(PYTHON_LIBRARY_DIRECTORY, LIBRARY_DATA_FILES)],
)