+
+ {% if homepage is not none %}
+
+ {% endif %}
+
+
\ No newline at end of file
diff --git a/setup.py b/setup.py
index aa26867e..da758be6 100644
--- a/setup.py
+++ b/setup.py
@@ -17,7 +17,7 @@ setup(
author='arcanis',
author_email='',
- url='',
+ url='https://github.com/arcan1s/ahriman',
license='GPL3',
@@ -39,7 +39,7 @@ setup(
include_package_data=True,
scripts=[
- 'package/bin/ahriman'
+ 'package/bin/ahriman',
],
data_files=[
('/etc', ['package/etc/ahriman.ini']),
@@ -47,10 +47,12 @@ setup(
('lib/systemd/system', [
'package/lib/systemd/system/ahriman.service',
'package/lib/systemd/system/ahriman.timer'
- ])
+ ]),
+ ('share/ahriman', ['package/share/ahriman/index.jinja2']),
],
extras_require={
+ 'html-templates': ['Jinja2'],
'test': ['coverage', 'pytest'],
},
)
diff --git a/src/ahriman/core/report/html.py b/src/ahriman/core/report/html.py
index 8171f6a4..8307f9b3 100644
--- a/src/ahriman/core/report/html.py
+++ b/src/ahriman/core/report/html.py
@@ -17,10 +17,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
+import jinja2
import os
+from typing import Dict
+
from ahriman.core.configuration import Configuration
from ahriman.core.report.report import Report
+from ahriman.core.util import package_like
+from ahriman.models.sign_settings import SignSettings
class HTML(Report):
@@ -29,25 +34,37 @@ class HTML(Report):
Report.__init__(self, architecture, config)
section = self.config.get_section_name('html', self.architecture)
self.report_path = config.get(section, 'path')
- self.css_path = config.get(section, 'css_path')
+
self.link_path = config.get(section, 'link_path')
- self.title = config.get('repository', 'name')
+ self.template_path = config.get(section, 'template_path')
+
+ # base template vars
+ if SignSettings.from_option(config.get('sign', 'enabled')) != SignSettings.Disabled:
+ self.pgp_key = config.get('sign', 'key')
+ else:
+ self.pgp_key = None
+ self.homepage = config.get(section, 'homepage', fallback=None)
+ self.repository = config.get('repository', 'name')
def generate(self, path: str) -> None:
- # lets not use libraries here
- html = f'''{self.title}'''
- if self.css_path:
- html += f''''''
- html += ''''''
+ # idea comes from https://stackoverflow.com/a/38642558
+ templates_dir, template_name = os.path.split(self.template_path)
+ loader = jinja2.FileSystemLoader(searchpath=templates_dir)
+ environment = jinja2.Environment(loader=loader)
+ template = environment.get_template(template_name)
- html += '''
'''
- for package in sorted(os.listdir(path)):
- if '.pkg.' not in package:
+ packages: Dict[str, str] = {}
+ for fn in sorted(os.listdir(path)):
+ if not package_like(fn):
continue
- html += f'''
'''
+ packages[fn] = f'{self.link_path}/{fn}'
- html += ''''''
+ html = template.render(
+ homepage=self.homepage,
+ link_path=self.link_path,
+ packages=packages,
+ pgp_key=self.pgp_key,
+ repository=self.repository)
with open(self.report_path, 'w') as out:
out.write(html)
diff --git a/src/ahriman/core/repository.py b/src/ahriman/core/repository.py
index 1ad04a5f..980cb7a6 100644
--- a/src/ahriman/core/repository.py
+++ b/src/ahriman/core/repository.py
@@ -29,6 +29,7 @@ from ahriman.core.repo.repo_wrapper import RepoWrapper
from ahriman.core.report.report import Report
from ahriman.core.sign.gpg_wrapper import GPGWrapper
from ahriman.core.upload.uploader import Uploader
+from ahriman.core.util import package_like
from ahriman.models.package import Package
from ahriman.models.repository_paths import RepositoryPaths
@@ -64,7 +65,7 @@ class Repository:
def packages(self) -> List[Package]:
result: Dict[str, Package] = {}
for fn in os.listdir(self.paths.repository):
- if '.pkg.' not in fn:
+ if not package_like(fn):
continue
full_path = os.path.join(self.paths.repository, fn)
try:
@@ -101,7 +102,7 @@ class Repository:
def process_remove(self, packages: List[str]) -> str:
for fn in os.listdir(self.paths.repository):
- if '.pkg.' not in fn:
+ if not package_like(fn):
continue
full_path = os.path.join(self.paths.repository, fn)
@@ -146,7 +147,7 @@ class Repository:
self.config.get_section_name('build', self.architecture), 'ignore_packages')
for fn in os.listdir(self.paths.repository):
- if '.pkg.' not in fn:
+ if not package_like(fn):
continue
try:
diff --git a/src/ahriman/core/util.py b/src/ahriman/core/util.py
index c85e593d..093e5608 100644
--- a/src/ahriman/core/util.py
+++ b/src/ahriman/core/util.py
@@ -37,3 +37,7 @@ def check_output(*args: str, exception: Optional[Exception],
logger.debug(line)
raise exception or e
return result
+
+
+def package_like(filename: str) -> bool:
+ return '.pkg.' in filename and not filename.endswith('.sig')