Skip to content

Commit

Permalink
Move csrgen templates into ipaclient package
Browse files Browse the repository at this point in the history
csrgen broke packaging of ipaclient for PyPI. All csrgen related
resources are now package data of ipaclient package. Package data is
accessed with Jinja's PackageLoader() or through pkg_resources.

https://pagure.io/freeipa/issue/6714

Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Ben Lipton <blipton@redhat.com>
Reviewed-By: Martin Basti <mbasti@redhat.com>
  • Loading branch information
tiran authored and David Kupka committed Mar 8, 2017
1 parent f8d7e37 commit 80be181
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 52 deletions.
1 change: 0 additions & 1 deletion configure.ac
Expand Up @@ -463,7 +463,6 @@ AC_CONFIG_FILES([
install/share/Makefile
install/share/advise/Makefile
install/share/advise/legacy/Makefile
install/share/csrgen/Makefile
install/share/profiles/Makefile
install/share/schema.d/Makefile
install/ui/Makefile
Expand Down
13 changes: 6 additions & 7 deletions freeipa.spec.in
Expand Up @@ -1231,13 +1231,6 @@ fi
%{_usr}/share/ipa/advise/legacy/*.template
%dir %{_usr}/share/ipa/profiles
%{_usr}/share/ipa/profiles/*.cfg
%dir %{_usr}/share/ipa/csrgen
%dir %{_usr}/share/ipa/csrgen/templates
%{_usr}/share/ipa/csrgen/templates/*.tmpl
%dir %{_usr}/share/ipa/csrgen/profiles
%{_usr}/share/ipa/csrgen/profiles/*.json
%dir %{_usr}/share/ipa/csrgen/rules
%{_usr}/share/ipa/csrgen/rules/*.json
%dir %{_usr}/share/ipa/html
%{_usr}/share/ipa/html/ffconfig.js
%{_usr}/share/ipa/html/ffconfig_page.js
Expand Down Expand Up @@ -1364,6 +1357,9 @@ fi
%{python_sitelib}/ipaclient/plugins/*.py*
%{python_sitelib}/ipaclient/remote_plugins/*.py*
%{python_sitelib}/ipaclient/remote_plugins/2_*/*.py*
%{python_sitelib}/ipaclient/csrgen/profiles/*.json
%{python_sitelib}/ipaclient/csrgen/rules/*.json
%{python_sitelib}/ipaclient/csrgen/templates/*.tmpl
%{python_sitelib}/ipaclient-*.egg-info


Expand All @@ -1384,6 +1380,9 @@ fi
%{python3_sitelib}/ipaclient/remote_plugins/__pycache__/*.py*
%{python3_sitelib}/ipaclient/remote_plugins/2_*/*.py
%{python3_sitelib}/ipaclient/remote_plugins/2_*/__pycache__/*.py*
%{python3_sitelib}/ipaclient/csrgen/profiles/*.json
%{python3_sitelib}/ipaclient/csrgen/rules/*.json
%{python3_sitelib}/ipaclient/csrgen/templates/*.tmpl
%{python3_sitelib}/ipaclient-*.egg-info

%endif # with_python3
Expand Down
1 change: 0 additions & 1 deletion install/share/Makefile.am
Expand Up @@ -2,7 +2,6 @@ NULL =

SUBDIRS = \
advise \
csrgen \
profiles \
schema.d \
$(NULL)
Expand Down
35 changes: 0 additions & 35 deletions install/share/csrgen/Makefile.am

This file was deleted.

21 changes: 15 additions & 6 deletions ipaclient/csrgen.py
Expand Up @@ -8,14 +8,15 @@
import pipes
import traceback

import pkg_resources

import jinja2
import jinja2.ext
import jinja2.sandbox
import six

from ipalib import errors
from ipalib.text import _
from ipaplatform.paths import paths
from ipapython.ipa_log_manager import log_mgr

if six.PY3:
Expand Down Expand Up @@ -72,10 +73,14 @@ class Formatter(object):
"""
base_template_name = None

def __init__(self, csr_data_dir=paths.CSR_DATA_DIR):
def __init__(self, csr_data_dir=None):
if csr_data_dir is not None:
loader = jinja2.FileSystemLoader(
os.path.join(csr_data_dir, 'templates'))
else:
loader = jinja2.PackageLoader('ipaclient', 'csrgen/templates')
self.jinja2 = jinja2.sandbox.SandboxedEnvironment(
loader=jinja2.FileSystemLoader(
os.path.join(csr_data_dir, 'templates')),
loader=loader,
extensions=[jinja2.ext.ExprStmtExtension, IPAExtension],
keep_trailing_newline=True, undefined=IndexableUndefined)

Expand Down Expand Up @@ -277,9 +282,13 @@ def rules_for_profile(self, profile_id, helper):


class FileRuleProvider(RuleProvider):
def __init__(self, csr_data_dir=paths.CSR_DATA_DIR):
def __init__(self, csr_data_dir=None):
self.rules = {}
self.csr_data_dir = csr_data_dir
if csr_data_dir is None:
self.csr_data_dir = pkg_resources.resource_filename(
'ipaclient', 'csrgen')
else:
self.csr_data_dir = csr_data_dir

def _rule(self, rule_name, helper):
if (rule_name, helper) not in self.rules:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 9 additions & 1 deletion ipaclient/setup.py
Expand Up @@ -43,6 +43,13 @@
"ipaclient.remote_plugins.2_156",
"ipaclient.remote_plugins.2_164",
],
package_data={
'ipaclient': [
'csrgen/profiles/*.json',
'csrgen/rules/*.json',
'csrgen/templates/*.tmpl',
],
},
install_requires=[
"cryptography",
"ipalib",
Expand All @@ -56,5 +63,6 @@
extras_require={
"install": ["ipaplatform"],
"otptoken_yubikey": ["yubico", "usb"]
}
},
zip_safe=False,
)
1 change: 0 additions & 1 deletion ipaplatform/base/paths.py
Expand Up @@ -238,7 +238,6 @@ class BasePathNamespace(object):
SCHEMA_COMPAT_ULDIF = "/usr/share/ipa/schema_compat.uldif"
IPA_JS_PLUGINS_DIR = "/usr/share/ipa/ui/js/plugins"
UPDATES_DIR = "/usr/share/ipa/updates/"
CSR_DATA_DIR = "/usr/share/ipa/csrgen"
DICT_WORDS = "/usr/share/dict/words"
CACHE_IPA_SESSIONS = "/var/cache/ipa/sessions"
VAR_KERBEROS_KRB5KDC_DIR = "/var/kerberos/krb5kdc/"
Expand Down

0 comments on commit 80be181

Please sign in to comment.