471 """return the information module for the given cube""" |
471 """return the information module for the given cube""" |
472 cube = CW_MIGRATION_MAP.get(cube, cube) |
472 cube = CW_MIGRATION_MAP.get(cube, cube) |
473 try: |
473 try: |
474 parent = __import__('cubes.%s.__pkginfo__' % cube) |
474 parent = __import__('cubes.%s.__pkginfo__' % cube) |
475 return getattr(parent, cube).__pkginfo__ |
475 return getattr(parent, cube).__pkginfo__ |
476 except Exception, ex: |
476 except Exception as ex: |
477 raise ConfigurationError( |
477 raise ConfigurationError( |
478 'unable to find packaging information for cube %s (%s: %s)' |
478 'unable to find packaging information for cube %s (%s: %s)' |
479 % (cube, ex.__class__.__name__, ex)) |
479 % (cube, ex.__class__.__name__, ex)) |
480 |
480 |
481 @classmethod |
481 @classmethod |
578 if dep in cubes) |
578 if dep in cubes) |
579 graph[cube] |= set(dep for dep in cls.cube_recommends(cube) |
579 graph[cube] |= set(dep for dep in cls.cube_recommends(cube) |
580 if dep in cubes) |
580 if dep in cubes) |
581 try: |
581 try: |
582 return ordered_nodes(graph) |
582 return ordered_nodes(graph) |
583 except UnorderableGraph, ex: |
583 except UnorderableGraph as ex: |
584 raise ConfigurationError('cycles in cubes dependencies: %s' |
584 raise ConfigurationError('cycles in cubes dependencies: %s' |
585 % ex.cycles) |
585 % ex.cycles) |
586 |
586 |
587 @classmethod |
587 @classmethod |
588 def cls_adjust_sys_path(cls): |
588 def cls_adjust_sys_path(cls): |
612 'server/serverctl.py', |
612 'server/serverctl.py', |
613 'devtools/devctl.py', 'goa/goactl.py'): |
613 'devtools/devctl.py', 'goa/goactl.py'): |
614 if exists(join(CW_SOFTWARE_ROOT, ctlfile)): |
614 if exists(join(CW_SOFTWARE_ROOT, ctlfile)): |
615 try: |
615 try: |
616 load_module_from_file(join(CW_SOFTWARE_ROOT, ctlfile)) |
616 load_module_from_file(join(CW_SOFTWARE_ROOT, ctlfile)) |
617 except ImportError, err: |
617 except ImportError as err: |
618 cls.error('could not import the command provider %s: %s', |
618 cls.error('could not import the command provider %s: %s', |
619 ctlfile, err) |
619 ctlfile, err) |
620 cls.info('loaded cubicweb-ctl plugin %s', ctlfile) |
620 cls.info('loaded cubicweb-ctl plugin %s', ctlfile) |
621 for cube in cls.available_cubes(): |
621 for cube in cls.available_cubes(): |
622 pluginfile = join(cls.cube_dir(cube), 'ccplugin.py') |
622 pluginfile = join(cls.cube_dir(cube), 'ccplugin.py') |
641 __init__ file, so they should be loaded early in the startup process |
641 __init__ file, so they should be loaded early in the startup process |
642 """ |
642 """ |
643 for cube in cls.available_cubes(): |
643 for cube in cls.available_cubes(): |
644 try: |
644 try: |
645 __import__('cubes.%s' % cube) |
645 __import__('cubes.%s' % cube) |
646 except Exception, ex: |
646 except Exception as ex: |
647 cls.warning("can't init cube %s: %s", cube, ex) |
647 cls.warning("can't init cube %s: %s", cube, ex) |
648 |
648 |
649 cubicweb_appobject_path = set(['entities']) |
649 cubicweb_appobject_path = set(['entities']) |
650 cube_appobject_path = set(['entities']) |
650 cube_appobject_path = set(['entities']) |
651 |
651 |
1053 """ |
1053 """ |
1054 if not exists(path): |
1054 if not exists(path): |
1055 self.info('creating %s directory', path) |
1055 self.info('creating %s directory', path) |
1056 try: |
1056 try: |
1057 os.makedirs(path) |
1057 os.makedirs(path) |
1058 except OSError, ex: |
1058 except OSError as ex: |
1059 self.warning('error while creating %s directory: %s', path, ex) |
1059 self.warning('error while creating %s directory: %s', path, ex) |
1060 return |
1060 return |
1061 if self['uid']: |
1061 if self['uid']: |
1062 try: |
1062 try: |
1063 uid = int(self['uid']) |
1063 uid = int(self['uid']) |
1072 fstat = os.stat(path) |
1072 fstat = os.stat(path) |
1073 if fstat.st_uid != uid: |
1073 if fstat.st_uid != uid: |
1074 self.info('giving ownership of %s directory to %s', path, self['uid']) |
1074 self.info('giving ownership of %s directory to %s', path, self['uid']) |
1075 try: |
1075 try: |
1076 os.chown(path, uid, os.getgid()) |
1076 os.chown(path, uid, os.getgid()) |
1077 except OSError, ex: |
1077 except OSError as ex: |
1078 self.warning('error while giving ownership of %s directory to %s: %s', |
1078 self.warning('error while giving ownership of %s directory to %s: %s', |
1079 path, self['uid'], ex) |
1079 path, self['uid'], ex) |
1080 if not (fstat.st_mode & stat.S_IWUSR): |
1080 if not (fstat.st_mode & stat.S_IWUSR): |
1081 self.info('forcing write permission on directory %s', path) |
1081 self.info('forcing write permission on directory %s', path) |
1082 try: |
1082 try: |
1083 os.chmod(path, fstat.st_mode | stat.S_IWUSR) |
1083 os.chmod(path, fstat.st_mode | stat.S_IWUSR) |
1084 except OSError, ex: |
1084 except OSError as ex: |
1085 self.warning('error while forcing write permission on directory %s: %s', |
1085 self.warning('error while forcing write permission on directory %s: %s', |
1086 path, ex) |
1086 path, ex) |
1087 return |
1087 return |
1088 |
1088 |
1089 @cached |
1089 @cached |
1189 server, port = self['smtp-host'], self['smtp-port'] |
1189 server, port = self['smtp-host'], self['smtp-port'] |
1190 SMTP_LOCK.acquire() |
1190 SMTP_LOCK.acquire() |
1191 try: |
1191 try: |
1192 try: |
1192 try: |
1193 smtp = SMTP(server, port) |
1193 smtp = SMTP(server, port) |
1194 except Exception, ex: |
1194 except Exception as ex: |
1195 self.exception("can't connect to smtp server %s:%s (%s)", |
1195 self.exception("can't connect to smtp server %s:%s (%s)", |
1196 server, port, ex) |
1196 server, port, ex) |
1197 return False |
1197 return False |
1198 heloaddr = '%s <%s>' % (self['sender-name'], self['sender-addr']) |
1198 heloaddr = '%s <%s>' % (self['sender-name'], self['sender-addr']) |
1199 for msg, recipients in msgs: |
1199 for msg, recipients in msgs: |
1200 try: |
1200 try: |
1201 smtp.sendmail(heloaddr, recipients, msg.as_string()) |
1201 smtp.sendmail(heloaddr, recipients, msg.as_string()) |
1202 except Exception, ex: |
1202 except Exception as ex: |
1203 self.exception("error sending mail to %s (%s)", |
1203 self.exception("error sending mail to %s (%s)", |
1204 recipients, ex) |
1204 recipients, ex) |
1205 smtp.close() |
1205 smtp.close() |
1206 finally: |
1206 finally: |
1207 SMTP_LOCK.release() |
1207 SMTP_LOCK.release() |
1312 |
1312 |
1313 def source_execute(self, source, session, value): |
1313 def source_execute(self, source, session, value): |
1314 fpath = source.binary_to_str(value) |
1314 fpath = source.binary_to_str(value) |
1315 try: |
1315 try: |
1316 return Binary(fpath) |
1316 return Binary(fpath) |
1317 except OSError, ex: |
1317 except OSError as ex: |
1318 source.critical("can't open %s: %s", fpath, ex) |
1318 source.critical("can't open %s: %s", fpath, ex) |
1319 return None |
1319 return None |
1320 |
1320 |
1321 register_function(FSPATH) |
1321 register_function(FSPATH) |