Permalink
Browse files

Don't install error_template.html into DEFAULT_INSTALL_PATH/etc

Use pkgutil.get_data() to get error_template.html
Part of addressing issue #42 and allowing virtualenv installs
  • Loading branch information...
1 parent eea4ab9 commit c8010fdb4b3b9d049c6c465dc818e692d6d3cbbe @von committed Aug 3, 2011
Showing with 22 additions and 6 deletions.
  1. +2 −0 MANIFEST.in
  2. 0 { → perproxy}/conf/error_template.html
  3. +18 −5 scripts/PerProxy
  4. +2 −1 setup.py
View
@@ -0,0 +1,2 @@
+include perproxy/conf/*
+
File renamed without changes.
View
@@ -7,6 +7,7 @@ import ConfigParser
import logging
import logging.config
import os.path
+import pkgutil
import sys
import threading
import time
@@ -45,7 +46,7 @@ def parse_args(argv):
defaults = {
"ca_cert_file" : os.path.expanduser(os.path.join(DEFAULT_USER_CONF_PATH, "ca-cert.crt")),
"ca_key_file" : os.path.expanduser(os.path.join(DEFAULT_USER_CONF_PATH,"ca-key.pem")),
- "error_template" : os.path.join(DEFAULT_INSTALL_PATH, "etc", "error_template.html"),
+ "error_template" : None,
"logging_config" : os.path.join(DEFAULT_INSTALL_PATH, "etc", "logging.config"),
"notaries_file" : os.path.join(DEFAULT_INSTALL_PATH, "etc", "http_notary_list.txt"),
"perspectives_quorum_duration" : 86400, # One day
@@ -129,6 +130,10 @@ def setup_logging(args):
root_logger.setLevel(logging.DEBUG)
root_logger.addHandler(root_handler)
+def get_resource(resource):
+ """Return contents of given resource from installed package"""
+ return pkgutil.get_data("perproxy", resource)
+
def main(argv=None):
# Do argv default this way, as doing it in the functional
# declaration sets it at compile time.
@@ -168,10 +173,18 @@ def main(argv=None):
wl = WhiteList.from_file(os.path.expanduser(args.whitelist_filename))
Handler.whitelist = wl
- output.debug("Loading error template from %s" % (args.error_template))
-
- with open(os.path.expanduser(args.error_template)) as f:
- Handler.HTML_ERROR_TEMPLATE = "".join(f.readlines())
+ if args.error_template is None:
+ output.debug("Loading error template from resources")
+ try:
+ template = get_resource("conf/error_template.html")
+ except IOError as e:
+ output.error("Error reading error_template resource: " + str(e))
+ sys.exit(1)
+ Handler.HTML_ERROR_TEMPLATE = get_resource("conf/error_template.html")
+ else:
+ output.debug("Loading error template from %s" % (args.error_template))
+ with open(os.path.expanduser(args.error_template)) as f:
+ Handler.HTML_ERROR_TEMPLATE = "".join(f.readlines())
# Per M2Crypto FAQ
output.debug("Initializing M2Crypto threading")
View
@@ -13,7 +13,6 @@
CONF_FILES = [
"conf/PerProxy-whitelist.txt",
"conf/PerProxy.conf",
- "conf/error_template.html",
"conf/http_notary_list.txt",
"conf/logging.config",
]
@@ -34,6 +33,8 @@
name = "PerProxy",
version = VERSION,
packages = [ "perproxy" ],
+ # Files in package_data must also appear in MANIFEST.in
+ package_data = { "perproxy" : [ "conf/error_template.html" ] },
data_files = [
(CONF_PATH, CONF_FILES),
(SCRIPT_PATH, SCRIPT_FILES),

0 comments on commit c8010fd

Please sign in to comment.