Skip to content

Commit 2f93979

Browse files
author
Sebastian Wagner
committed
PKG: separate building process from setup.py
move the building process from setup.py to a separate file, make it an executable ship the apache configuration file if possible adapt the debian build rules
1 parent 46c5564 commit 2f93979

9 files changed

Lines changed: 109 additions & 47 deletions

File tree

MANIFEST.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
include CHANGELOG.md CONTRIBUTING.md CONTRIBUTORS.md
55
include NEWS.md README.md SECURITY.md
66
include LICENSES/*
7-
recursive-include docs *
7+
recursive-include contrib *
8+
graft intelmq_manager/templates/
9+
graft intelmq_manager/static/

debian/changelog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
intelmq-manager (3.1.0~apha1-1) UNRELEASED; urgency=medium
1+
intelmq-manager (3.1.0~alpha2-1) UNRELEASED; urgency=medium
22

33
* Update to 3.1.0.
44

debian/rules

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
%:
33
dh $@ --with python3 --buildsystem=pybuild
44

5+
override_dh_install:
6+
dh_install
7+
# build the files. call build.py directly, not the produced executable as that would require an installed instance of intelmq-manager already
8+
PYTHONPATH=. python3 ./intelmq_manager/build.py --output-dir debian/intelmq-manager/usr/share/intelmq_manager/html/
9+
# remove the generated intelmq-manager-build executable, as it should not be called in deb-installations
10+
rm debian/intelmq-manager/usr/bin/intelmq-manager-build
11+
512

613
override_dh_auto_clean:
714
dh_auto_clean

intelmq_manager/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
66
"""
77
import pathlib
8+
from .version import __version__, __version_info__ # noqa
89

910
path = pathlib.Path(__file__).parent

intelmq_manager/build.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""
2+
Build statically rendered files.
3+
4+
SPDX-FileCopyrightText: 2021 Birger Schacht <schacht@cert.at>, Mikk Margus Möll <mikk@cert.ee>, Sebastian Wagner <wagner@cert.at>
5+
SPDX-License-Identifier: AGPL-3.0-or-later
6+
"""
7+
import argparse
8+
import pathlib
9+
import shutil
10+
from mako.lookup import TemplateLookup
11+
12+
13+
def render_page(pagename: str, **template_args) -> str:
14+
template_dir = pathlib.Path(__file__).parent / 'templates'
15+
template_lookup = TemplateLookup(directories=[template_dir], default_filters=["h"], input_encoding='utf8')
16+
template = template_lookup.get_template(f'{pagename}.mako')
17+
18+
return template.render(pagename=pagename, **template_args)
19+
20+
21+
def buildhtml(outputdir: pathlib.Path = pathlib.Path('html')):
22+
outputdir.mkdir(parents=True, exist_ok=True)
23+
24+
htmlfiles = ["configs", "management", "monitor", "check", "about", "index"]
25+
for filename in htmlfiles:
26+
print(f"Rendering {filename}.html")
27+
html = render_page(filename)
28+
outputdir.joinpath(f"{filename}.html").write_text(html)
29+
30+
staticfiles = ["css", "images", "js", "plugins", "less"]
31+
for filename in staticfiles:
32+
print(f"Copying {filename} recursively")
33+
src = pathlib.Path(__file__).parent / 'static' / filename
34+
dst = outputdir / filename
35+
if dst.exists():
36+
shutil.rmtree(dst)
37+
shutil.copytree(src, dst)
38+
39+
print('rendering dynvar.js')
40+
rendered = render_page('dynvar', allowed_path='/opt/intelmq/var/lib/bots/', controller_cmd='intelmq')
41+
outputdir.joinpath('js/dynvar.js').write_text(rendered)
42+
43+
44+
def main():
45+
parser = argparse.ArgumentParser(
46+
prog='intelmq-manager-build',
47+
description='Build statically rendered files for intelmq-manager.',
48+
epilog='This command renders and saves all files required for IntelMQ Manager at the given directory, which can be served by Webservers statically',
49+
formatter_class=argparse.RawDescriptionHelpFormatter,
50+
)
51+
52+
parser.add_argument('--output-dir', '-o', default='html',
53+
type=pathlib.Path,
54+
help='The destination directory, will be created if needed.')
55+
args = parser.parse_args()
56+
buildhtml(outputdir=args.output_dir)
57+
58+
59+
if __name__ == '__main__':
60+
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../contrib/manager-apache.conf

intelmq_manager/static/js/about.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function get_versions() {
1212
.done(function (data) {
1313
intelmq_version_element.innerHTML = data.intelmq;
1414
intelmq_api_version_element.innerHTML = data['intelmq-api'];
15-
intelmq_manager_version_element.innerHTML = '3.1.0alpha1';
15+
intelmq_manager_version_element.innerHTML = '3.1.0.alpha2';
1616
})
1717
.fail(function (jqxhr, textStatus, error) {
1818
let err = `${textStatus}, ${error}`;

intelmq_manager/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
SPDX-FileCopyrightText: 2020-2021 Intelmq Team <intelmq-team@cert.at>
44
SPDX-License-Identifier: AGPL-3.0-or-later
55
"""
6-
__version_info__ = (3, 1, 0, 'alpha1')
6+
__version_info__ = (3, 1, 0, 'alpha2')
77
__version__ = '.'.join(map(str, __version_info__))

setup.py

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,56 @@
1-
""" Setup file for intelmq-manager
1+
"""
2+
Setup file for intelmq-manager
23
34
SPDX-FileCopyrightText: 2020 IntelMQ Team <intelmq-team@cert.at>
45
SPDX-License-Identifier: AGPL-3.0-or-later
56
"""
6-
from setuptools import find_packages, setup
77

8-
import pathlib
9-
import shutil
10-
from mako.lookup import TemplateLookup
8+
from setuptools import find_packages, setup
119

1210
from intelmq_manager.version import __version__
1311

14-
def render_page(pagename:str, **template_args) -> str:
15-
template_dir = pathlib.Path('intelmq_manager/templates')
16-
template_lookup = TemplateLookup(directories=[template_dir], default_filters=["h"], input_encoding='utf8')
17-
template = template_lookup.get_template(f'{pagename}.mako')
18-
19-
return template.render(pagename=pagename, **template_args)
20-
21-
def buildhtml():
22-
outputdir = pathlib.Path('html')
23-
outputdir.mkdir(parents=True, exist_ok=True)
24-
25-
htmlfiles = ["configs", "management", "monitor", "check", "about", "index"]
26-
for filename in htmlfiles:
27-
print(f"Rendering {filename}.html")
28-
html = render_page(filename)
29-
outputdir.joinpath(f"{filename}.html").write_text(html)
30-
31-
staticfiles = ["css", "images", "js", "plugins", "less"]
32-
for filename in staticfiles:
33-
print(f"Copying {filename} recursively")
34-
src = pathlib.Path('intelmq_manager/static') / filename
35-
dst = outputdir / filename
36-
if dst.exists():
37-
shutil.rmtree(dst)
38-
shutil.copytree(src, dst)
39-
40-
print('rendering dynvar.js')
41-
rendered = render_page('dynvar', allowed_path='/opt/intelmq/var/lib/bots/', controller_cmd='intelmq')
42-
outputdir.joinpath('js/dynvar.js').write_text(rendered)
43-
44-
# Before running setup, we build the html files in any case
45-
buildhtml()
46-
47-
htmlsubdirs = [directory for directory in pathlib.Path('html').glob('**') if directory.is_dir()]
48-
data_files = [(f'/usr/share/intelmq_manager/{directory}', [str(x) for x in directory.glob('*') if x.is_file()]) for directory in htmlsubdirs]
49-
data_files = data_files + [('/usr/share/intelmq_manager/html', [str(x) for x in pathlib.Path('html').iterdir() if x.is_file()])]
50-
data_files = data_files + [('/etc/intelmq', ['contrib/manager-apache.conf'])]
5112

5213
setup(
5314
name="intelmq-manager",
15+
maintainer='IntelMQ Team',
16+
maintainer_email='intelmq-team@cert.at',
5417
version=__version__,
5518
python_requires='>=3.5',
5619
packages=find_packages(),
5720
install_requires=[
5821
"intelmq-api",
22+
"mako",
5923
],
6024
include_package_data=True,
6125
url='https://github.com/certtools/intelmq-manager/',
6226
description=("IntelMQ Manager is a graphical interface to manage"
6327
" configurations for the IntelMQ framework."),
64-
data_files=data_files
28+
data_files=[('/etc/intelmq', ['contrib/manager-apache.conf'])], # required for deb packaging
29+
package_data={'': ('manager-apache.conf', # works for the wheel package
30+
'templates/*',
31+
'static/css/*',
32+
'static/images/*',
33+
'static/js/*',
34+
'static/less/*',
35+
'static/plugins/*',
36+
'static/plugins/bootstrap/*',
37+
'static/plugins/dataTables/*',
38+
'static/plugins/font-awesome-4.1.0/*',
39+
'static/plugins/font-awesome-4.1.0/css/*',
40+
'static/plugins/font-awesome-4.1.0/fonts/*',
41+
'static/plugins/font-awesome-4.1.0/less/*',
42+
'static/plugins/font-awesome-4.1.0/scss/*',
43+
'static/plugins/fonts/*',
44+
'static/plugins/metisMenu/*',
45+
'static/plugins/vis.js/*',
46+
'static/plugins/vis.js/img/*',
47+
'static/plugins/vis.js/img/graph/*',
48+
'static/plugins/vis.js/img/network/*',
49+
'static/plugins/vis.js/img/timeline/*',
50+
)},
51+
entry_points={
52+
'console_scripts': [
53+
'intelmq-manager-build = intelmq_manager.build:main',
54+
],
55+
},
6556
)

0 commit comments

Comments
 (0)