forked from tema-tut/tema-tg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
159 lines (135 loc) · 5.82 KB
/
setup.py
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
#!/usr/bin/env python
# -*- coding: utf-8
# Copyright (c) 2006-2010 Tampere University of Technology
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from distutils.core import setup
from distutils.command.build_scripts import build_scripts,first_line_re
from distutils.command.bdist_wininst import bdist_wininst
from distutils.dist import Distribution
from shutil import copyfile,rmtree
from tempfile import mkdtemp
import os
import glob
class Distribution_extended(Distribution):
def __init__ (self, attrs=None):
self.add_prefix = False
self.remove_prefix = False
Distribution.__init__(self,attrs)
class bdist_wininst_extended(bdist_wininst):
def run(self):
self.distribution.add_prefix = True
bdist_wininst.run(self)
class build_scripts_add_extension(build_scripts):
def _transform_script_name(self,script_name):
script_base = os.path.basename(script_name)
filu = open(script_name,'r')
firstline = filu.readline()
filu.close()
if firstline:
match = first_line_re.match(firstline)
else:
match = None
file_name = script_base
if match:
if self.distribution.add_prefix and not script_base.endswith(".py"):
file_name = "%s.py" % script_base
if self.distribution.remove_prefix and script_base.endswith(".py"):
file_name = script_base[:-3]
if not file_name.startswith("tema."):
file_name = "tema.%s" % file_name
return file_name
def run(self):
# Not in posix system. Add prefix .py just to be sure
if os.name != "posix":
self.distribution.add_prefix = True
# Remove .py prefix in posix.
elif os.name == "posix" and not self.distribution.add_prefix:
self.distribution.remove_prefix = True
try:
tempdir = mkdtemp()
new_names = []
for script in self.scripts:
new_name = os.path.join(tempdir,self._transform_script_name(script))
new_names.append(new_name)
copyfile(script,new_name)
self.scripts = new_names
build_scripts.run(self)
finally:
if os.path.isdir(tempdir):
rmtree(tempdir)
try:
input_h = open("LICENCE",'r')
LICENCE=input_h.read()
finally:
input_h.close()
VERSION='3.2'
def get_scripts():
scripts = glob.glob("Validation/simulation/*.py")
log_tools = glob.glob("Validation/loghandling/*.py")
if "Validation/loghandling/avgofdats.py" in log_tools:
log_tools.remove("Validation/loghandling/avgofdats.py")
scripts.extend(log_tools)
scripts.append("Validation/viewer/model2dot.py")
scripts.append("ModelUtils/runmodelpackage.py")
scripts.append("ModelUtils/actionlist.py")
# scripts.append("TemaLib/MockSUT/mocksut.py")
scripts.extend(glob.glob("Validation/analysis/*.py"))
modelutils = glob.glob("TemaLib/tema/modelutils/*.py")
modelutils.remove("TemaLib/tema/modelutils/__init__.py")
scripts.extend(modelutils)
scripts.append("TemaLib/tema/model/model2lsts.py")
scripts.append("TemaLib/tema/eini/mdm2svg.py")
scripts.append("TemaLib/tema/packagereader/packagereader.py")
scripts.append("TemaLib/tema/ats4appmodel/ats4appmodel2lsts.py")
scripts.append("TemaLib/tema/filter/filterexpand.py")
scripts.append("TemaLib/tema/variablemodels/variablemodelcreator.py")
scripts.append("TemaLib/tema/testengine/testengine.py")
return scripts
def get_packages(start_path):
for root,dirs,files in os.walk(start_path):
for filename in files:
if filename == "__init__.py":
yield root.split(start_path + os.sep,1)[1].replace("/",".")
def get_manpages():
man_pages = glob.glob("Docs/man/man1/*.1")
return man_pages
packages_list = list(get_packages("TemaLib"))
if "ToolProxy" in packages_list:
packages_list.remove("ToolProxy")
scripts_list = get_scripts()
manpages_list = get_manpages()
setup(name='tema-tg',
provides=['tema',],
license=LICENCE,
version=VERSION,
description='TEMA Test engine',
author="Tampere University of Technology, Department of Software Systems",
author_email='[email protected]',
url='http://tema.cs.tut.fi',
package_dir = {"" : "TemaLib" },
data_files=[('share/man/man1', manpages_list),
('lib/tema-tg/gui_interface',['gui_interface/tema.start_engine','gui_interface/tema.list_sessions','gui_interface/tema.kill_engine'])],
packages=packages_list,
package_data={"tema.modelutils" : ["pcrules/Generic*","makefiles/GNUmakefile*"]},
scripts=scripts_list,
cmdclass={"build_scripts" : build_scripts_add_extension, "bdist_wininst" : bdist_wininst_extended },
distclass=Distribution_extended,
)