forked from KasperskyLab/RAM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistrib.py
More file actions
217 lines (172 loc) · 6.97 KB
/
distrib.py
File metadata and controls
217 lines (172 loc) · 6.97 KB
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
from setuptools import setup, find_packages
from setuptools import Distribution, Command
import os
class build_ram(Command):
def initialize_options(self):
self.build_base = None
self.executable = None
self.compile = None
self.optimize = None
def finalize_options(self):
self.set_undefined_options('build',
('build_base', 'build_base'),
)
self.set_undefined_options('build_scripts',
('executable', 'executable'),
)
self.set_undefined_options('build_py',
('compile', 'compile'),
('optimize', 'optimize'),
)
for (_dst, _src), _dist in self.distribution.ram_dists.items():
_build = _dist.reinitialize_command('build', reinit_subcommands=True)
_build.build_base = os.path.join(self.build_base, 'ram', _src, '__pybuild__')
_build_scripts = _dist.reinitialize_command('build_scripts')
_build_scripts.executable = self.executable
_build_py = _dist.reinitialize_command('build_py')
_build_py.compile = self.compile
_build_py.optimize = self.optimize
def run(self):
for (_dst, _src), _dist in self.distribution.ram_dists.items():
_dist.run_command('build')
class install_ram(Command):
def initialize_options(self):
self.root = None
self.compile = None
self.optimize = None
self.skip_build = None
self.build_base = None
def finalize_options(self):
self.set_undefined_options('install',
('root', 'root'),
('skip_build', 'skip_build'),
)
self.set_undefined_options('install_lib',
('compile', 'compile'),
('optimize', 'optimize'),
)
self.set_undefined_options('build_ram',
('build_base', 'build_base'),
)
for (_dst, _src), _dist in self.distribution.ram_dists.items():
_install = _dist.reinitialize_command('install', reinit_subcommands=True)
_install_build_base = os.path.join(self.build_base, 'ram', _src, '__pybuild__')
_install.skip_build = self.skip_build
_install.root = self.root
_install.install_scripts = os.path.join('$platbase', _dst)
_install.install_lib = os.path.join('$platbase', _dst)
_install_scripts = _dist.reinitialize_command('install_scripts')
_install_lib = _dist.reinitialize_command('install_lib')
_install_lib.compile = self.compile
_install_lib.optimize = self.optimize
def get_outputs(self):
return sum(
(_dist.get_command_obj('install', create=0).get_outputs()
for _, _dist in self.distribution.ram_dists.items()
), []
)
def run(self):
for (_dst, _src), _dist in self.distribution.ram_dists.items():
_dist.run_command('install')
class DummyCommand(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
pass
def get_outputs(self): return []
class RamDistribution(Distribution):
def __init__(self, attrs=None):
self.ram_units = None
Distribution.__init__(self, attrs)
self.cmdclass.setdefault('build_ram', build_ram)
self.cmdclass.setdefault('install_ram', install_ram)
self.ram_dists = {}
for ram_dst, ram_src in self.ram_units or list():
for srcpath, dirs, files in os.walk(ram_src):
dstpath = os.path.normpath(
os.path.join(ram_dst, os.path.relpath(srcpath, ram_src))
)
scripts = []
modules = []
various = []
for _ in files:
_name, _ext = os.path.splitext(_)
_path = os.path.join(srcpath, _)
if os.path.isfile(_path) and os.access(_path, os.X_OK):
scripts.append(_path)
elif _ext == '.py':
modules.append(_name)
else:
various.append(_)
self.ram_dists[dstpath, srcpath] = Distribution(dict(
scripts=scripts,
package_dir={'': srcpath},
packages=[''],
package_data={'': various},
options=dict(
install_scripts={
'no_ep': True,
},
),
cmdclass={
'egg_info': DummyCommand,
'install_egg_info': DummyCommand,
},
script_name=self.script_name,
script_args=self.script_args,
))
def get_command_class(self, command):
klass = Distribution.get_command_class(self, command)
if command in ['build', 'install']:
class klass(klass):
sub_commands = klass.sub_commands + [
('%s_ram' % command, lambda self: True),
]
klass.__name__ = command
return klass
if __name__ == '__main__':
os.chdir(os.path.dirname(__file__) or '.')
__project__ = 'ram-framework'
__version__ = open('./src/ram/VERSION').read().strip()
setup(
name=__project__,
version=__version__,
description='Framework to manage product state and configuration',
long_description=open('./README.md').read(),
long_description_content_type='text/markdown',
author='Roman Valov',
author_email='roman.valov@gmail.com',
url='https://ram-framework.readthedocs.io/en/latest/',
license='MIT',
package_dir={'': 'src'},
packages=find_packages(where='src', exclude=['tests', 'tests.*']),
package_data={'': ['VERSION']},
ram_units=[
('lib/ram', 'lib/ram'),
],
data_files=[
('/etc/ram', ['etc/ram.conf.example']),
('share/ram', ['share/ram/srv.functions', 'share/ram/ram.functions']),
],
distclass=RamDistribution,
scripts=['bin/ram', 'bin/ram-symbols'],
classifiers=(
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Environment :: Console :: Newt',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: MIT License',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Application Frameworks',
'Topic :: System :: Installation/Setup',
'Topic :: System :: Systems Administration',
'Topic :: Utilities',
),
)