Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move config system to config.py, where I keep looking for it.

  • Loading branch information...
commit ee3c366855f2b13b9ebe8553f52aab0ed03dcd20 1 parent 35d8707
Erik Rose erikrose authored
Showing with 184 additions and 183 deletions.
  1. +2 −1  dxr/build.py
  2. +180 −0 dxr/config.py
  3. +2 −1  dxr/dxr-worker.py
  4. +0 −181 dxr/utils.py
3  dxr/build.py
View
@@ -8,6 +8,7 @@
import subprocess
import sys
+from dxr.config import Config
from dxr.utils import load_template_env
import dxr.utils
import dxr.plugins
@@ -30,7 +31,7 @@ def build_instance(config_path, nb_jobs=None, tree=None):
overrides = {}
if nb_jobs:
overrides['nb_jobs'] = nb_jobs
- config = dxr.utils.Config(config_path, **overrides)
+ config = Config(config_path, **overrides)
# Find trees to make, fail if requested tree isn't available
if tree:
180 dxr/config.py
View
@@ -0,0 +1,180 @@
+import ConfigParser
+from datetime import datetime
+import os
+from os.path import isdir
+import sys
+
+import dxr
+
+
+# Please keep these config objects as simple as possible and in sync with
+# docs/configuration.mkd. I'm well aware that this is not the most compact way
+# of writing things, but it sure is doomed to fail when user forgets an important
+# key. It's also fairly easy to extract default values, and config keys from
+# this code, so enjoy.
+
+class Config(object):
+ """ Configuration for DXR """
+ def __init__(self, configfile, **override):
+ # Create parser with sane defaults
+ parser = ConfigParser.ConfigParser({
+ 'dxrroot': os.path.dirname(dxr.__file__),
+ 'plugin_folder': "%(dxrroot)s/plugins",
+ 'nb_jobs': "1",
+ 'temp_folder': "/tmp/dxr-temp",
+ 'log_folder': "%(temp_folder)s/logs",
+ 'template': "%(dxrroot)s/templates",
+ 'wwwroot': "/",
+ 'enabled_plugins': "*",
+ 'disabled_plugins': " ",
+ 'directory_index': ".dxr-directory-index.html",
+ 'generated_date': datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S +0000")
+ })
+ parser.read(configfile)
+
+ # Set config values
+ self.dxrroot = parser.get('DXR', 'dxrroot', False, override)
+ self.plugin_folder = parser.get('DXR', 'plugin_folder', False, override)
+ self.nb_jobs = parser.get('DXR', 'nb_jobs', False, override)
+ self.temp_folder = parser.get('DXR', 'temp_folder', False, override)
+ self.target_folder = parser.get('DXR', 'target_folder', False, override)
+ self.log_folder = parser.get('DXR', 'log_folder', False, override)
+ self.template_folder = parser.get('DXR', 'template', False, override)
+ self.wwwroot = parser.get('DXR', 'wwwroot', False, override)
+ self.enabled_plugins = parser.get('DXR', 'enabled_plugins', False, override)
+ self.disabled_plugins = parser.get('DXR', 'disabled_plugins', False, override)
+ self.directory_index = parser.get('DXR', 'directory_index', False, override)
+ self.generated_date = parser.get('DXR', 'generated_date', False, override)
+ # Set configfile
+ self.configfile = configfile
+ self.trees = []
+ # Set template parameters (using new parser to avoid defaults)
+ tmp_cfg = ConfigParser.ConfigParser()
+ tmp_cfg.read(configfile)
+ self.template_parameters = dict(tmp_cfg.items('Template'))
+
+ # Read all plugin_ keys
+ for key, value in tmp_cfg.items('DXR'):
+ if key.startswith('plugin_'):
+ setattr(self, key, value)
+
+ # Render all paths absolute
+ self.dxrroot = os.path.abspath(self.dxrroot)
+ self.plugin_folder = os.path.abspath(self.plugin_folder)
+ self.temp_folder = os.path.abspath(self.temp_folder)
+ self.log_folder = os.path.abspath(self.log_folder)
+ self.target_folder = os.path.abspath(self.target_folder)
+ self.template_folder = os.path.abspath(self.template_folder)
+
+ # Make sure wwwroot doesn't end in /
+ if self.wwwroot[-1] == '/':
+ self.wwwroot = self.wwwroot[:-1]
+
+ # Convert disabled plugins to a list
+ if self.disabled_plugins == "*":
+ self.disabled_plugins = os.listdir(self.plugin_folder)
+ else:
+ self.disabled_plugins = self.disabled_plugins.split()
+
+ # Convert enabled plugins to a list
+ if self.enabled_plugins == "*":
+ self.enabled_plugins = [
+ p for p in os.listdir(self.plugin_folder) if
+ isdir(os.path.join(self.plugin_folder, p)) and
+ p not in self.disabled_plugins]
+ else:
+ self.enabled_plugins = self.enabled_plugins.split()
+
+ # Test for conflicting plugins settings
+ if any((p in self.disabled_plugins for p in self.enabled_plugins)):
+ msg = "Plugin: '%s' is both enabled and disabled in '%s'"
+ print >> sys.stderr, msg % (p, name)
+ sys.exit(1)
+
+ # Load trees
+ def section_cmp(a, b):
+ if parser.has_option(a, "order") and parser.has_option(b, "order"):
+ return cmp(parser.getint(a, "order"), parser.getint(b, "order"))
+ if (not parser.has_option(a, "order")) and (not parser.has_option(b, "order")):
+ return cmp(a, b)
+ return -1 if parser.has_option(a, "order") else 1
+
+ for tree in sorted(parser.sections(), section_cmp):
+ if tree not in ('DXR', 'Template'):
+ self.trees.append(TreeConfig(self, self.configfile, tree))
+
+
+
+class TreeConfig(object):
+ """ Tree configuration for DXR """
+ def __init__(self, config, configfile, name):
+ # Create parser with sane defaults
+ parser = ConfigParser.ConfigParser({
+ 'enabled_plugins': "*",
+ 'disabled_plugins': "",
+ 'temp_folder': os.path.join(config.temp_folder, name),
+ 'log_folder': os.path.join(config.log_folder, name),
+ 'ignore_patterns': ".hg .git CVS .svn .bzr .deps .libs",
+ 'build_command': "make -j $jobs"
+ })
+ parser.read(configfile)
+
+ # Set config values
+ self.enabled_plugins = parser.get(name, 'enabled_plugins', False)
+ self.disabled_plugins = parser.get(name, 'disabled_plugins', False)
+ self.temp_folder = parser.get(name, 'temp_folder', False)
+ self.log_folder = parser.get(name, 'log_folder', False)
+ self.object_folder = parser.get(name, 'object_folder', False)
+ self.source_folder = parser.get(name, 'source_folder', False)
+ self.build_command = parser.get(name, 'build_command', False)
+ self.ignore_patterns = parser.get(name, 'ignore_patterns', False)
+
+ # You cannot redefine the target folder!
+ self.target_folder = os.path.join(config.target_folder, 'trees', name)
+ # Set config file and DXR config object reference
+ self.configfile = configfile
+ self.config = config
+ self.name = name
+
+ # Read all plugin_ keys
+ for key, value in parser.items(name):
+ if key.startswith('plugin_'):
+ setattr(self, key, value)
+
+ # Convert ignore patterns to list
+ self.ignore_patterns = self.ignore_patterns.split()
+ self.ignore_paths = filter(lambda p: p.startswith("/"), self.ignore_patterns)
+ self.ignore_patterns = filter(lambda p: not p.startswith("/"), self.ignore_patterns)
+
+ # Render all path absolute
+ self.temp_folder = os.path.abspath(self.temp_folder)
+ self.log_folder = os.path.abspath(self.log_folder)
+ self.object_folder = os.path.abspath(self.object_folder)
+ self.source_folder = os.path.abspath(self.source_folder)
+
+ # Convert disabled plugins to a list
+ if self.disabled_plugins == "*":
+ self.disabled_plugins = config.enabled_plugins
+ else:
+ self.disabled_plugins = self.disabled_plugins.split()
+ for p in config.disabled_plugins:
+ if p not in self.disabled_plugins:
+ self.disabled_plugins.append(p)
+
+ # Convert enabled plugins to a list
+ if self.enabled_plugins == "*":
+ self.enabled_plugins = [p for p in config.enabled_plugins
+ if p not in self.disabled_plugins]
+ else:
+ self.enabled_plugins = self.enabled_plugins.split()
+
+ # Test for conflicting plugins settings
+ if any(p in self.disabled_plugins for p in self.enabled_plugins):
+ msg = "Plugin: '%s' is both enabled and disabled in '%s'"
+ print >> sys.stderr, msg % (p, name)
+ sys.exit(1)
+
+ # Warn if $jobs isn't used...
+ if "$jobs" not in self.build_command:
+ msg = "Warning: $jobs is not used in build_command for '%s'"
+ print >> sys.stderr, msg % name
3  dxr/dxr-worker.py
View
@@ -7,6 +7,7 @@
# it's not to be imported.
import dxr
+from dxr.config import Config
import dxr.utils
import dxr.plugins
import os, sys
@@ -57,7 +58,7 @@ def main(argv):
end = int(opt)
# Load configuration file
- config = dxr.utils.Config(configfile)
+ config = Config(configfile)
# Find the tree
for t in config.trees:
181 dxr/utils.py
View
@@ -1,190 +1,9 @@
import sqlite3
import ctypes
-import ConfigParser
import os
-from os.path import isdir
import jinja2
import string
-import subprocess
-import sys
from urllib import quote, quote_plus
-from datetime import datetime
-
-import dxr
-
-
-# Please keep these config objects as simple as possible and in sync with
-# docs/configuration.mkd. I'm well aware that this is not the most compact way
-# of writing things, but it sure is doomed to fail when user forgets an important
-# key. It's also fairly easy to extract default values, and config keys from
-# this code, so enjoy.
-
-class Config(object):
- """ Configuration for DXR """
- def __init__(self, configfile, **override):
- # Create parser with sane defaults
- parser = ConfigParser.ConfigParser({
- 'dxrroot': os.path.dirname(dxr.__file__),
- 'plugin_folder': "%(dxrroot)s/plugins",
- 'nb_jobs': "1",
- 'temp_folder': "/tmp/dxr-temp",
- 'log_folder': "%(temp_folder)s/logs",
- 'template': "%(dxrroot)s/templates",
- 'wwwroot': "/",
- 'enabled_plugins': "*",
- 'disabled_plugins': " ",
- 'directory_index': ".dxr-directory-index.html",
- 'generated_date': datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S +0000")
- })
- parser.read(configfile)
-
- # Set config values
- self.dxrroot = parser.get('DXR', 'dxrroot', False, override)
- self.plugin_folder = parser.get('DXR', 'plugin_folder', False, override)
- self.nb_jobs = parser.get('DXR', 'nb_jobs', False, override)
- self.temp_folder = parser.get('DXR', 'temp_folder', False, override)
- self.target_folder = parser.get('DXR', 'target_folder', False, override)
- self.log_folder = parser.get('DXR', 'log_folder', False, override)
- self.template_folder = parser.get('DXR', 'template', False, override)
- self.wwwroot = parser.get('DXR', 'wwwroot', False, override)
- self.enabled_plugins = parser.get('DXR', 'enabled_plugins', False, override)
- self.disabled_plugins = parser.get('DXR', 'disabled_plugins', False, override)
- self.directory_index = parser.get('DXR', 'directory_index', False, override)
- self.generated_date = parser.get('DXR', 'generated_date', False, override)
- # Set configfile
- self.configfile = configfile
- self.trees = []
- # Set template parameters (using new parser to avoid defaults)
- tmp_cfg = ConfigParser.ConfigParser()
- tmp_cfg.read(configfile)
- self.template_parameters = dict(tmp_cfg.items('Template'))
-
- # Read all plugin_ keys
- for key, value in tmp_cfg.items('DXR'):
- if key.startswith('plugin_'):
- setattr(self, key, value)
-
- # Render all paths absolute
- self.dxrroot = os.path.abspath(self.dxrroot)
- self.plugin_folder = os.path.abspath(self.plugin_folder)
- self.temp_folder = os.path.abspath(self.temp_folder)
- self.log_folder = os.path.abspath(self.log_folder)
- self.target_folder = os.path.abspath(self.target_folder)
- self.template_folder = os.path.abspath(self.template_folder)
-
- # Make sure wwwroot doesn't end in /
- if self.wwwroot[-1] == '/':
- self.wwwroot = self.wwwroot[:-1]
-
- # Convert disabled plugins to a list
- if self.disabled_plugins == "*":
- self.disabled_plugins = os.listdir(self.plugin_folder)
- else:
- self.disabled_plugins = self.disabled_plugins.split()
-
- # Convert enabled plugins to a list
- if self.enabled_plugins == "*":
- self.enabled_plugins = [
- p for p in os.listdir(self.plugin_folder) if
- isdir(os.path.join(self.plugin_folder, p)) and
- p not in self.disabled_plugins]
- else:
- self.enabled_plugins = self.enabled_plugins.split()
-
- # Test for conflicting plugins settings
- if any((p in self.disabled_plugins for p in self.enabled_plugins)):
- msg = "Plugin: '%s' is both enabled and disabled in '%s'"
- print >> sys.stderr, msg % (p, name)
- sys.exit(1)
-
- # Load trees
- def section_cmp(a, b):
- if parser.has_option(a, "order") and parser.has_option(b, "order"):
- return cmp(parser.getint(a, "order"), parser.getint(b, "order"))
- if (not parser.has_option(a, "order")) and (not parser.has_option(b, "order")):
- return cmp(a, b)
- return -1 if parser.has_option(a, "order") else 1
-
- for tree in sorted(parser.sections(), section_cmp):
- if tree not in ('DXR', 'Template'):
- self.trees.append(TreeConfig(self, self.configfile, tree))
-
-
-
-class TreeConfig(object):
- """ Tree configuration for DXR """
- def __init__(self, config, configfile, name):
- # Create parser with sane defaults
- parser = ConfigParser.ConfigParser({
- 'enabled_plugins': "*",
- 'disabled_plugins': "",
- 'temp_folder': os.path.join(config.temp_folder, name),
- 'log_folder': os.path.join(config.log_folder, name),
- 'ignore_patterns': ".hg .git CVS .svn .bzr .deps .libs",
- 'build_command': "make -j $jobs"
- })
- parser.read(configfile)
-
- # Set config values
- self.enabled_plugins = parser.get(name, 'enabled_plugins', False)
- self.disabled_plugins = parser.get(name, 'disabled_plugins', False)
- self.temp_folder = parser.get(name, 'temp_folder', False)
- self.log_folder = parser.get(name, 'log_folder', False)
- self.object_folder = parser.get(name, 'object_folder', False)
- self.source_folder = parser.get(name, 'source_folder', False)
- self.build_command = parser.get(name, 'build_command', False)
- self.ignore_patterns = parser.get(name, 'ignore_patterns', False)
-
- # You cannot redefine the target folder!
- self.target_folder = os.path.join(config.target_folder, 'trees', name)
- # Set config file and DXR config object reference
- self.configfile = configfile
- self.config = config
- self.name = name
-
- # Read all plugin_ keys
- for key, value in parser.items(name):
- if key.startswith('plugin_'):
- setattr(self, key, value)
-
- # Convert ignore patterns to list
- self.ignore_patterns = self.ignore_patterns.split()
- self.ignore_paths = filter(lambda p: p.startswith("/"), self.ignore_patterns)
- self.ignore_patterns = filter(lambda p: not p.startswith("/"), self.ignore_patterns)
-
- # Render all path absolute
- self.temp_folder = os.path.abspath(self.temp_folder)
- self.log_folder = os.path.abspath(self.log_folder)
- self.object_folder = os.path.abspath(self.object_folder)
- self.source_folder = os.path.abspath(self.source_folder)
-
- # Convert disabled plugins to a list
- if self.disabled_plugins == "*":
- self.disabled_plugins = config.enabled_plugins
- else:
- self.disabled_plugins = self.disabled_plugins.split()
- for p in config.disabled_plugins:
- if p not in self.disabled_plugins:
- self.disabled_plugins.append(p)
-
- # Convert enabled plugins to a list
- if self.enabled_plugins == "*":
- self.enabled_plugins = [p for p in config.enabled_plugins
- if p not in self.disabled_plugins]
- else:
- self.enabled_plugins = self.enabled_plugins.split()
-
- # Test for conflicting plugins settings
- if any(p in self.disabled_plugins for p in self.enabled_plugins):
- msg = "Plugin: '%s' is both enabled and disabled in '%s'"
- print >> sys.stderr, msg % (p, name)
- sys.exit(1)
-
- # Warn if $jobs isn't used...
- if "$jobs" not in self.build_command:
- msg = "Warning: $jobs is not used in build_command for '%s'"
- print >> sys.stderr, msg % name
-
_trilite_loaded = False
Please sign in to comment.
Something went wrong with that request. Please try again.