Attachment 'multiconfig.patch'

Download

   1 --- orig/MoinMoin/multiconfig.py
   2 +++ mod/MoinMoin/multiconfig.py
   3 @@ -10,101 +10,64 @@
   4  
   5  import re, os, sys
   6  from MoinMoin import error
   7 -
   8 +    
   9  
  10  _url_re = None
  11  def url_re():
  12      """ Return url matching regular expression
  13  
  14 -    Using this regular expression, we find the config_module for each
  15 +    Using this regular expression, we find the wiki package for each
  16      url.
  17      
  18 -    Import wikis from 'farmconfig' on the first time, compile and cache url_re
  19 +    Import wikis from farm onfig on the first time, compile and cache url_re
  20      regular expression, and return it.
  21  
  22 -    Note: You must restart a long running process when you edit
  23 -    farmconfig.py config file.
  24 -
  25      @rtype: compiled re object
  26      @return: url to wiki config  matching re
  27      """
  28      global _url_re
  29      if not _url_re:
  30          try:
  31 -            farmconfig = __import__('farmconfig', globals(), {})
  32 +            from farm.config import wikis
  33              pattern = '|'.join([r'(?P<%s>%s)' % (name, regex)
  34 -                                for name, regex in farmconfig.wikis])
  35 +                                for name, regex in wikis])
  36              _url_re = re.compile(pattern)
  37 -        except (ImportError, AttributeError):
  38 -            # It is not there, so we maybe have only one config. Fall back to
  39 -            # old config file name and use it for all urls we get.
  40 -            # Or we have a farmconfig file, but it does not contain a wikis
  41 -            # attribute (because of typo or everything commented out as in
  42 -            # sample config).
  43 -            _url_re = re.compile(r'(?P<wikiconfig>.)')
  44 +        except ImportError:
  45 +            # Either there is no farm config or it is bad. Use the
  46 +            # default wiki name for all requests.
  47 +            _url_re = re.compile(r'(?P<wiki>.+)')
  48      return _url_re
  49  
  50  
  51  def getConfig(url):
  52 -    """ Make and return config object, or raise an error
  53 -
  54 -    If the config file is not found or broken, either because of a typo
  55 -    in farmconfig or deleted file or some other error, we raise a
  56 -    ConfigurationError which is handled by our client.
  57 -    
  58 -    @param url: the url from request, possibly matching specific wiki
  59 -    @rtype: DefaultConfig subclass instance
  60 -    @return: config object for specific wiki
  61 -    """
  62 +    """ Return a config object matching url """
  63      match = url_re().match(url)
  64 -    if match and match.groups():
  65 -        # Get config module name from match
  66 +    if match:
  67          for name, value in match.groupdict().items():
  68              if value: break
  69 -
  70 -        # FIXME: we should cache config objects by wiki url and return
  71 -        # here a ready to use config, instead of creating new instance
  72 -        # for each request.
  73 -        
  74 +        # Try to import a Config class from name config
  75 +        wikiConfig = 'farm.%s.config' % name
  76          try:
  77 -            module =  __import__(name, globals(), {})
  78 -            Config = getattr(module, 'Config', None)
  79 -            if Config:
  80 -                # Config found, return config instance using name as
  81 -                # site identifier (name must be unique of our url_re).
  82 -                cfg = Config(name)
  83 -                return cfg
  84 -            else:
  85 -                # Broken config file, probably old config from 1.2
  86 -                msg = '''
  87 -Could not find required "Config" class in "%(name)s.py". This might
  88 -happen if you are trying to use a pre 1.3 configuration file, or made a
  89 -syntax or spelling error.
  90 -
  91 -Please check your configuration file. As an example for correct syntax,
  92 -use the wikiconfig.py file from the distribution.
  93 -''' % {'name': name}
  94 -
  95 -        # We don't handle fatal errors here
  96 -        except error.FatalError, err:
  97 -            raise err
  98 -
  99 -        # These errors will not be big surprise:       
 100 +            module =  __import__(wikiConfig, globals(), {}, ['Config'])
 101 +            Config = getattr(module, 'Config')
 102 +            return Config(name)
 103          except ImportError, err:
 104              msg = '''
 105  Import of configuration file "%(name)s.py" failed because of
 106  ImportError: %(err)s.
 107  
 108 -Check that the file is in the same directory as the server script. If
 109 -it is not, you must add the path of the directory where the file is located
 110 -to the python path in the server script. See the comments at the top of
 111 -the server script.
 112 -
 113 -Check that the configuration file name is either "wikiconfig.py" or the
 114 -module name specified in the wikis list in farmconfig.py. Note that the module
 115 -name does not include the ".py" suffix.
 116 -''' % {'name': name, 'err': str(err)}
 117 +Check the path to the farm in the server script. Check that the
 118 +configuration file name is "config.py".
 119 +''' % {'name': wikiConfig, 'err': str(err)}
 120 +        except AttributeError:
 121 +            msg = '''
 122 +Could not find required "Config" class in "%(name)s.py". This might
 123 +happen if you are trying to use a pre 1.3 configuration file, or made a
 124 +syntax or spelling error.
 125  
 126 +Please check your configuration file. As an example for correct syntax,
 127 +use the config.py file from the distribution.
 128 +''' % {'name': wikiConfig}
 129          except IndentationError, err:
 130              msg = '''
 131  Import of configuration file "%(name)s.py" failed because of
 132 @@ -113,10 +76,7 @@
 133  The configuration files are python modules. Therefore, whitespace is
 134  important. Make sure that you use only spaces, no tabs are allowed here!
 135  You have to use four spaces at the beginning of the line mostly.
 136 -''' % {'name': name, 'err': str(err)}
 137 -
 138 -        # But people can have many other errors. We hope that the python
 139 -        # error message will help them.
 140 +''' % {'name': wikiConfig, 'err': str(err)}
 141          except:
 142              err = sys.exc_info()[1]
 143              msg = '''
 144 @@ -126,10 +86,8 @@
 145  We hope this error message make sense. If not, you are welcome to ask on
 146  the page http://moinmoin.wikiwikiweb.de/MoinMoinQuestions/ConfigFiles
 147  or the #moin channel on irc.freenode.net or on the mailing list.
 148 -''' % {'name': name, 'class': err.__class__.__name__, 'err': str(err)}
 149 -
 150 +''' % {'name': wikiConfig, 'class': err.__class__.__name__, 'err': str(err)}
 151      else:
 152 -        # URL did not match anything, probably error in farmconfig.wikis 
 153          msg = '''
 154  Could not find a match for url: "%(url)s".
 155  
 156 @@ -174,8 +132,11 @@
 157      chart_options = None
 158      config_check_enabled = 0
 159      cookie_lifetime = 12 # 12 hours from now
 160 -    data_dir = './data/'
 161 -    data_underlay_dir = './underlay/'
 162 +
 163 +    # Lazy initialized
 164 +    data_dir = None
 165 +    data_underlay_dir = None
 166 +
 167      date_fmt = '%Y-%m-%d'
 168      datetime_fmt = '%Y-%m-%d %H:%M:%S'
 169      default_lang = 'en'
 170 @@ -270,9 +231,10 @@
 171      
 172      SecurityPolicy = None
 173  
 174 -    def __init__(self, siteid):
 175 +    def __init__(self, siteid='wiki'):
 176          """ Init Config instance """
 177          self.siteid = siteid
 178 +        self._initializeDirectories()
 179          if self.config_check_enabled:
 180              self._config_check()
 181              
 182 @@ -281,9 +243,6 @@
 183  
 184          # Make sure directories are accessible
 185          self._check_directories()
 186 -
 187 -        # Load plugin module
 188 -        self._loadPluginModule()
 189          
 190          # Normalize values
 191          self.default_lang = self.default_lang.lower()
 192 @@ -401,6 +360,15 @@
 193                                  raise error.ConfigurationError(message %
 194                                                                 {'name': name})
 195  
 196 +    def _initializeDirectories(self):
 197 +        """ Use default directories paths unless overridden """
 198 +        import farm
 199 +        farmPath = os.path.abspath(os.path.dirname(farm.__file__))
 200 +        if self.data_underlay_dir is None:
 201 +            self.data_underlay_dir = os.path.join(farmPath, 'underlay')
 202 +        if self.data_dir is None:
 203 +            self.data_dir = os.path.join(farmPath, self.siteid, 'data')
 204 +
 205      def _check_directories(self):
 206          """ Make sure directories are accessible
 207  
 208 @@ -408,15 +376,13 @@
 209          execute.
 210          """
 211          mode = os.F_OK | os.R_OK | os.W_OK | os.X_OK
 212 -        for attr in ('data_dir', 'data_underlay_dir'):
 213 +        for attr, required in (('data_dir', 1), ('data_underlay_dir', 0)):
 214              path = getattr(self, attr)
 215 -            
 216 -            # allow an empty underlay path or None
 217 -            if attr == 'data_underlay_dir' and not path:
 218 +            if path == '' and not required:
 219                  continue
 220 -
 221 -            path_pages = os.path.join(path, "pages")
 222 -            if not (os.path.isdir(path_pages) and os.access(path_pages, mode)):
 223 +            pages = os.path.join(path, "pages")
 224 +            # TODO: access should not be used here!
 225 +            if not (os.path.isdir(pages) and os.access(pages, mode)):
 226                  msg = '''
 227  "%(attr)s" does not exists at "%(path)s", or has incorrect ownership and
 228  permissions.

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2007-07-04 15:29:57, 7.7 KB) [[attachment:Slideshow.py]]
  • [get | view] (2004-10-20 05:28:16, 72.8 KB) [[attachment:alum.jpg]]
  • [get | view] (2005-04-14 19:56:30, 68.2 KB) [[attachment:farm.tbz]]
  • [get | view] (2005-05-28 17:05:11, 31.2 KB) [[attachment:me-with-naomi.jpg]]
  • [get | view] (2005-04-14 19:55:22, 8.6 KB) [[attachment:multiconfig.patch]]
  • [get | view] (2005-01-16 05:36:39, 41.4 KB) [[attachment:page-state.patch]]
  • [get | view] (2004-12-28 02:41:46, 36.7 KB) [[attachment:plugin.patch]]
  • [get | view] (2004-10-21 18:49:52, 22.1 KB) [[attachment:text_html.py]]
  • [get | view] (2005-04-18 07:20:14, 1.4 KB) [[attachment:wiki_icons.png]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.