765 vregpath.append(path + '.py') |
765 vregpath.append(path + '.py') |
766 return vregpath |
766 return vregpath |
767 |
767 |
768 apphome = None |
768 apphome = None |
769 |
769 |
770 def load_site_cubicweb(self, paths=None): |
770 def load_site_cubicweb(self, cubes=()): |
771 """load instance's specific site_cubicweb file""" |
771 """load site_cubicweb file for `cubes`""" |
772 if paths is None: |
772 for cube in reversed(cubes or self.cubes()): |
773 paths = self.cubes_path() |
773 if cube in self._site_loaded: |
774 if self.apphome is not None: |
774 continue |
775 paths = [self.apphome] + paths |
775 try: |
776 for path in reversed(paths): |
776 self._load_site_cubicweb(cube) |
777 sitefile = join(path, 'site_cubicweb.py') |
777 self._site_loaded.add(cube) |
778 if exists(sitefile) and not sitefile in self._site_loaded: |
778 except ImportError: |
779 self._load_site_cubicweb(sitefile) |
779 continue |
780 self._site_loaded.add(sitefile) |
780 if self.apphome is not None: |
781 |
781 # Would occur, e.g., upon `cubicweb-ctl i18ncube <cube>`. |
782 def _load_site_cubicweb(self, sitefile): |
782 self._load_app_site_cubicweb() |
783 # XXX extrapath argument to load_module_from_file only in lgc > 0.50.2 |
783 |
784 from logilab.common.modutils import load_module_from_modpath, modpath_from_file |
784 def _load_site_cubicweb(self, cube): |
785 module = load_module_from_modpath(modpath_from_file(sitefile, self.extrapath)) |
785 """Load site_cubicweb.py from `cube`.""" |
786 self.debug('%s loaded', sitefile) |
786 modname = 'cubes.%s.site_cubicweb' % cube |
787 return module |
787 __import__(modname) |
|
788 return sys.modules[modname].__dict__ |
|
789 |
|
790 def _load_app_site_cubicweb(self): |
|
791 """Load site_cubicweb.py in `apphome`.""" |
|
792 assert self.apphome is not None |
|
793 site_globals = {} |
|
794 apphome_site = join(self.apphome, 'site_cubicweb.py') |
|
795 if exists(apphome_site): |
|
796 with open(apphome_site, 'rb') as f: |
|
797 code = compile(f.read(), apphome_site, 'exec') |
|
798 exec(code, site_globals) |
|
799 return site_globals |
788 |
800 |
789 def cwproperty_definitions(self): |
801 def cwproperty_definitions(self): |
790 cfg = self.persistent_options_configuration() |
802 cfg = self.persistent_options_configuration() |
791 for section, options in cfg.options_by_section(): |
803 for section, options in cfg.options_by_section(): |
792 section = section.lower() |
804 section = section.lower() |
1076 def add_cubes(self, cubes): |
1088 def add_cubes(self, cubes): |
1077 """add given cubes to the list of used cubes""" |
1089 """add given cubes to the list of used cubes""" |
1078 if not isinstance(cubes, list): |
1090 if not isinstance(cubes, list): |
1079 cubes = list(cubes) |
1091 cubes = list(cubes) |
1080 self._cubes = self.reorder_cubes(list(self._cubes) + cubes) |
1092 self._cubes = self.reorder_cubes(list(self._cubes) + cubes) |
1081 self.load_site_cubicweb([self.cube_dir(cube) for cube in cubes]) |
1093 self.load_site_cubicweb(cubes) |
1082 |
1094 |
1083 def main_config_file(self): |
1095 def main_config_file(self): |
1084 """return instance's control configuration file""" |
1096 """return instance's control configuration file""" |
1085 return join(self.apphome, '%s.conf' % self.name) |
1097 return join(self.apphome, '%s.conf' % self.name) |
1086 |
1098 |
1145 super(CubicWebConfiguration, self).load_configuration(**kw) |
1157 super(CubicWebConfiguration, self).load_configuration(**kw) |
1146 if self.apphome and not self.creating: |
1158 if self.apphome and not self.creating: |
1147 # init gettext |
1159 # init gettext |
1148 self._gettext_init() |
1160 self._gettext_init() |
1149 |
1161 |
1150 def _load_site_cubicweb(self, sitefile): |
1162 def _load_site_cubicweb(self, cube): |
1151 # overridden to register cube specific options |
1163 # overridden to register cube specific options |
1152 mod = super(CubicWebConfiguration, self)._load_site_cubicweb(sitefile) |
1164 mod = super(CubicWebConfiguration, self)._load_site_cubicweb(cube) |
1153 if getattr(mod, 'options', None): |
1165 if 'options' in mod: |
1154 self.register_options(mod.options) |
1166 self.register_options(mod['options']) |
1155 self.load_defaults() |
1167 self.load_defaults() |
1156 |
1168 |
1157 def init_log(self, logthreshold=None, force=False): |
1169 def init_log(self, logthreshold=None, force=False): |
1158 """init the log service""" |
1170 """init the log service""" |
1159 if not force and hasattr(self, '_logging_initialized'): |
1171 if not force and hasattr(self, '_logging_initialized'): |