Changeset 173:197a41520ad1


Ignore:
Timestamp:
Sep 3, 2013, 2:07:56 PM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Message:

Tweak resources.get_file to allow creating non-existant files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/resources.py

    r161 r173  
    1818        self.language = language.split('_', 1)[0] if language else None
    1919        self._cache = {}
     20
     21    def create_resource_path(self, *path_fragments):
     22        return resource_filename(self.resource_module,
     23                                 os.path.join(*path_fragments))
    2024
    2125    def get_resource_path(self, *path_fragments):
     
    4246    def get_file(self, *path_fragments, **kw):
    4347        mode = kw.get('mode', "rU")
    44         path = self.get_resource_path(*path_fragments)
     48        try:
     49            path = self.get_resource_path(*path_fragments)
     50        except ResourceNotFound:
     51            if 'w' in mode:
     52                path = self.create_resource_path(*path_fragments)
     53            else:
     54                raise
    4555        return file(path, mode)
    4656
Note: See TracChangeset for help on using the changeset viewer.