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>
  • Loading branch information
tiran committed Mar 2, 2017
1 parent 9e24918 commit 779b561
Show file tree
Hide file tree
Showing 18 changed files with 24 additions and 45 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
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 779b561

Please sign in to comment.