cwconfig.py
changeset 8537 e30d0a7f0087
parent 8484 4c1efb5bde0a
child 8544 3d049071957e
equal deleted inserted replaced
8535:268b6349baf3 8537:e30d0a7f0087
   669                 cls.warning("can't init cube %s: %s", cube, ex)
   669                 cls.warning("can't init cube %s: %s", cube, ex)
   670 
   670 
   671     cubicweb_appobject_path = set(['entities'])
   671     cubicweb_appobject_path = set(['entities'])
   672     cube_appobject_path = set(['entities'])
   672     cube_appobject_path = set(['entities'])
   673 
   673 
   674     @classmethod
       
   675     def build_vregistry_path(cls, templpath, evobjpath=None, tvobjpath=None):
       
   676         """given a list of directories, return a list of sub files and
       
   677         directories that should be loaded by the instance objects registry.
       
   678 
       
   679         :param evobjpath:
       
   680           optional list of sub-directories (or files without the .py ext) of
       
   681           the cubicweb library that should be tested and added to the output list
       
   682           if they exists. If not give, default to `cubicweb_appobject_path` class
       
   683           attribute.
       
   684         :param tvobjpath:
       
   685           optional list of sub-directories (or files without the .py ext) of
       
   686           directories given in `templpath` that should be tested and added to
       
   687           the output list if they exists. If not give, default to
       
   688           `cube_appobject_path` class attribute.
       
   689         """
       
   690         vregpath = cls.build_vregistry_cubicweb_path(evobjpath)
       
   691         vregpath += cls.build_vregistry_cube_path(templpath, tvobjpath)
       
   692         return vregpath
       
   693 
       
   694     @classmethod
       
   695     def build_vregistry_cubicweb_path(cls, evobjpath=None):
       
   696         vregpath = []
       
   697         if evobjpath is None:
       
   698             evobjpath = cls.cubicweb_appobject_path
       
   699         # NOTE: for the order, see http://www.cubicweb.org/ticket/2330799
       
   700         #       it is clearly a workaround
       
   701         for subdir in sorted(evobjpath, key=lambda x:x != 'entities'):
       
   702             path = join(CW_SOFTWARE_ROOT, subdir)
       
   703             if exists(path):
       
   704                 vregpath.append(path)
       
   705         return vregpath
       
   706 
       
   707     @classmethod
       
   708     def build_vregistry_cube_path(cls, templpath, tvobjpath=None):
       
   709         vregpath = []
       
   710         if tvobjpath is None:
       
   711             tvobjpath = cls.cube_appobject_path
       
   712         for directory in templpath:
       
   713             # NOTE: for the order, see http://www.cubicweb.org/ticket/2330799
       
   714             for subdir in sorted(tvobjpath, key=lambda x:x != 'entities'):
       
   715                 path = join(directory, subdir)
       
   716                 if exists(path):
       
   717                     vregpath.append(path)
       
   718                 elif exists(path + '.py'):
       
   719                     vregpath.append(path + '.py')
       
   720         return vregpath
       
   721 
       
   722     def __init__(self, debugmode=False):
   674     def __init__(self, debugmode=False):
   723         if debugmode:
   675         if debugmode:
   724             # in python 2.7, DeprecationWarning are not shown anymore by default
   676             # in python 2.7, DeprecationWarning are not shown anymore by default
   725             filterwarnings('default', category=DeprecationWarning)
   677             filterwarnings('default', category=DeprecationWarning)
   726         register_stored_procedures()
   678         register_stored_procedures()
   764         else:
   716         else:
   765             init_log(self.debugmode, syslog, logthreshold, logfile, self.log_format)
   717             init_log(self.debugmode, syslog, logthreshold, logfile, self.log_format)
   766         # configure simpleTal logger
   718         # configure simpleTal logger
   767         logging.getLogger('simpleTAL').setLevel(logging.ERROR)
   719         logging.getLogger('simpleTAL').setLevel(logging.ERROR)
   768 
   720 
   769     def vregistry_path(self):
   721     def appobjects_path(self):
   770         """return a list of files or directories where the registry will look
   722         """return a list of files or directories where the registry will look
   771         for application objects. By default return nothing in NoApp config.
   723         for application objects. By default return nothing in NoApp config.
   772         """
   724         """
   773         return []
   725         return []
       
   726 
       
   727     def build_appobjects_path(self, templpath, evobjpath=None, tvobjpath=None):
       
   728         """given a list of directories, return a list of sub files and
       
   729         directories that should be loaded by the instance objects registry.
       
   730 
       
   731         :param evobjpath:
       
   732           optional list of sub-directories (or files without the .py ext) of
       
   733           the cubicweb library that should be tested and added to the output list
       
   734           if they exists. If not give, default to `cubicweb_appobject_path` class
       
   735           attribute.
       
   736         :param tvobjpath:
       
   737           optional list of sub-directories (or files without the .py ext) of
       
   738           directories given in `templpath` that should be tested and added to
       
   739           the output list if they exists. If not give, default to
       
   740           `cube_appobject_path` class attribute.
       
   741         """
       
   742         vregpath = self.build_appobjects_cubicweb_path(evobjpath)
       
   743         vregpath += self.build_appobjects_cube_path(templpath, tvobjpath)
       
   744         return vregpath
       
   745 
       
   746     def build_appobjects_cubicweb_path(self, evobjpath=None):
       
   747         vregpath = []
       
   748         if evobjpath is None:
       
   749             evobjpath = self.cubicweb_appobject_path
       
   750         # NOTE: for the order, see http://www.cubicweb.org/ticket/2330799
       
   751         #       it is clearly a workaround
       
   752         for subdir in sorted(evobjpath, key=lambda x:x != 'entities'):
       
   753             path = join(CW_SOFTWARE_ROOT, subdir)
       
   754             if exists(path):
       
   755                 vregpath.append(path)
       
   756         return vregpath
       
   757 
       
   758     def build_appobjects_cube_path(self, templpath, tvobjpath=None):
       
   759         vregpath = []
       
   760         if tvobjpath is None:
       
   761             tvobjpath = self.cube_appobject_path
       
   762         for directory in templpath:
       
   763             # NOTE: for the order, see http://www.cubicweb.org/ticket/2330799
       
   764             for subdir in sorted(tvobjpath, key=lambda x:x != 'entities'):
       
   765                 path = join(directory, subdir)
       
   766                 if exists(path):
       
   767                     vregpath.append(path)
       
   768                 elif exists(path + '.py'):
       
   769                     vregpath.append(path + '.py')
       
   770         return vregpath
   774 
   771 
   775     apphome = None
   772     apphome = None
   776 
   773 
   777     def load_site_cubicweb(self, paths=None):
   774     def load_site_cubicweb(self, paths=None):
   778         """load instance's specific site_cubicweb file"""
   775         """load instance's specific site_cubicweb file"""
  1175                     # in test contexts, data/i18n does not exist, hence
  1172                     # in test contexts, data/i18n does not exist, hence
  1176                     # logging will only pollute the logs
  1173                     # logging will only pollute the logs
  1177                     self.exception('localisation support error for language %s',
  1174                     self.exception('localisation support error for language %s',
  1178                                    language)
  1175                                    language)
  1179 
  1176 
  1180     def vregistry_path(self):
  1177     def appobjects_path(self):
  1181         """return a list of files or directories where the registry will look
  1178         """return a list of files or directories where the registry will look
  1182         for application objects
  1179         for application objects
  1183         """
  1180         """
  1184         templpath = list(reversed(self.cubes_path()))
  1181         templpath = list(reversed(self.cubes_path()))
  1185         if self.apphome: # may be unset in tests
  1182         if self.apphome: # may be unset in tests
  1186             templpath.append(self.apphome)
  1183             templpath.append(self.apphome)
  1187         return self.build_vregistry_path(templpath)
  1184         return self.build_appobjects_path(templpath)
  1188 
  1185 
  1189     def set_sources_mode(self, sources):
  1186     def set_sources_mode(self, sources):
  1190         if not 'all' in sources:
  1187         if not 'all' in sources:
  1191             print 'warning: ignoring specified sources, requires a repository '\
  1188             print 'warning: ignoring specified sources, requires a repository '\
  1192                   'configuration'
  1189                   'configuration'