def blobstorage_stats(app): stats = {} for ob in app.objectValues(): if INySite.providedBy(ob): s_id = ob.getId() stats[s_id] = {'du': 0, 'objects': 0, 'versions': 0, 'extra': {}} catalog = ob.getCatalogTool() bfile_brains = catalog({'meta_type': ['Naaya Blob File', 'Naaya Localized Blob File']}) for brain in bfile_brains: try: bfile = brain.getObject() except Exception, e: continue # bad brain? else: stats[s_id]['objects'] += 1 if bfile.meta_type == 'Naaya Localized Blob File': sizes = 0 for lg in bfile._versions.values(): stats[s_id]['versions'] += len(lg) sizes = reduce(operator.add, [v.size or 0 for v in lg], sizes) else: stats[s_id]['versions'] += len(bfile._versions) sizes = [v.size or 0 for v in bfile._versions] stats[s_id]['du'] = reduce(operator.add, sizes, stats[s_id]['du'])
def blobstorage_stats(app): stats = {} for ob in app.objectValues(): if INySite.providedBy(ob): s_id = ob.getId() stats[s_id] = {'du': 0, 'objects': 0, 'versions': 0, 'extra': {}} catalog = ob.getCatalogTool() bfile_brains = catalog({ 'meta_type': ['Naaya Blob File', 'Naaya Localized Blob File'] }) for brain in bfile_brains: try: bfile = brain.getObject() except Exception, e: continue # bad brain? else: stats[s_id]['objects'] += 1 if bfile.meta_type == 'Naaya Localized Blob File': sizes = 0 for lg in bfile._versions.values(): stats[s_id]['versions'] += len(lg) sizes = reduce(operator.add, [v.size or 0 for v in lg], sizes) else: stats[s_id]['versions'] += len(bfile._versions) sizes = [v.size or 0 for v in bfile._versions] stats[s_id]['du'] = reduce(operator.add, sizes, stats[s_id]['du'])
def init_site_loggers(): """ Called once on App startup """ import Zope2 for ob in Zope2.app().objectValues(): if INySite.providedBy(ob): try: create_site_logger(ob) except Exception, e: log.exception("Exception creating site logger for %r", ob)
def init_site_loggers(): """ Called once on App startup """ import Zope2 for ob in Zope2.app().objectValues(): if INySite.providedBy(ob): try: create_site_logger(ob) except Exception: log.exception("Exception creating site logger for %r", ob)
def get_portals(container, context=None, meta_types=None): """ Given a `container` or a `context` recusivly search all portals with `meta_types`. """ if context is None: context = container.getPhysicalRoot() res = [] for ob in context.objectValues(): if not INySite.providedBy(ob): continue if meta_types is not None and ob.meta_type not in meta_types: continue res.append(ob) res.extend(get_portals(container, ob, meta_types)) return res
def _update(self, portal): """ Summary of update: * test for portal_i18n existance, if true, skip portal * get languages and default language * create portal_i18n, place it in portal * copy message translations * fix localized properties * delete Localizer and portal_translations """ #if Localizer is None: # self.log.error('Migration unavailable when edw-localizer' # ' not installed') # return False if isinstance(portal.getPortalI18n(), NaayaI18n): self.log.debug( "Portal already uses naaya.i18n, skipping i18n init") localizer = None else: self.log.debug( "Creating portal_i18n and copying message catalog data") localizer = portal._getOb('Localizer', None) portal_trans = portal._getOb('portal_translations') if localizer is None: self.log.error("Localizer not found") return False if portal_trans is None: self.log.error("Portal Translations not found") return False languages = [(x, localizer.get_language_name(x)) for x in localizer.get_languages()] def_lang = localizer.get_default_language() self.log.debug('Found languages: %r, default: %s', languages, def_lang) manage_addNaayaI18n(portal, languages) portal.getPortalI18n().manage_changeDefaultLang(def_lang) message_cat = portal.getPortalI18n().get_message_catalog() (msg_cnt, trans_cnt) = (0, 0) for (msgid, trans) in portal_trans._messages.items(): if isinstance(msgid, str): msgid = force_to_unicode(msgid) # one call to gettext, to add 'en' identical translation, if missing message_cat.gettext(msgid, def_lang) msg_cnt += 1 for lang in trans: found = message_cat.gettext(msgid, lang, '') if lang != 'note': trans_cnt += 1 if isinstance(trans[lang], unicode): translation = trans[lang] elif isinstance(trans[lang], str): translation = force_to_unicode(trans[lang]) else: self.log.error(("Unacceptable type '%s' found for " "translation") % type(trans[lang])) self.log.error("Migration cancelled") return False if translation != found: message_cat.edit_message(msgid, lang, translation) self.log.debug('%d iterated, a total of %d translation mappings.' % (msg_cnt, trans_cnt)) self.log.debug('Message Catalog now counts %d entries (msgid-s).' % len(message_cat._messages.keys())) # Clean up and delete localizer localizer.manage_beforeDelete(localizer, portal) portal._delObject('Localizer') portal._delObject('portal_translations') self.log.debug('Localizer and Portal translations removed') # Fix local properties: # * remove translations with None-index (instead of language code) # * add existent properties in _local_properties_metadata # * remove blank/emptystring translations # Clean up any LocalAttribute-s on instances, if attribute not # present in class and superclasses or present but is LocalAttribute # key: class, value: attrs on class that are not LocalAttribute # their overrides need to be kept lookup_cache = {} localprops_del_cnt = 0 localprops_keep_cnt = 0 total_cnt = 0 all_objects = itertools.chain([portal], ofs_walk(portal)) # this class is not used anymore: for obj in all_objects: # Part 0.0: remove unused contenttype classes on sites: if INySite.providedBy(obj): if '_contenttypes_tool__contenttype_dictionary' in obj.__dict__: del obj.__dict__[ '_contenttypes_tool__contenttype_dictionary'] obj._p_changed = 1 # Part 0.1: if broken, report it # if other localizer in NySite child, skip it if isinstance(obj, BrokenClass): self.log.error(("Object %r is broken! Unable to fix local" " properties, if any ") % obj) continue if isinstance(obj, Localizer) and obj != localizer: continue # Part 1: delete unnecessary LocalAttributes on instances if obj.__dict__.get('_languages') is not None: del obj._languages if obj.__dict__.get('_default_language') is not None: del obj._default_language for (key, value) in obj.__dict__.items(): if isinstance(value, LocalAttribute): if not requires_localproperty(obj, key): self.log.debug("Deleting LocalAttribute: %r.%s", obj, key) delattr(obj, key) localprops_del_cnt += 1 else: self.log.debug("Keeping LocalAttribute: %r.%s", obj, key) setattr(obj, key, NewLocalAttribute(key)) localprops_keep_cnt += 1 # Part 2: normalize representation of local properties _local_properties = getattr(obj, '_local_properties', None) if _local_properties is not None: for (property, trans) in _local_properties.items(): if property not in obj._local_properties_metadata: obj.set_localproperty(property, 'string') delete_keys = set() for (lang, translation) in trans.items(): if not translation[0]: delete_keys.add(lang) if len(delete_keys): for key in delete_keys: del trans[key] obj._p_changed = 1 self.log.debug("%d LocalAttribute-s deleted from OFS" % localprops_del_cnt) self.log.debug("%d LocalAttribute-s kept in OFS" % localprops_keep_cnt) self.log.debug('Migration is complete!') return True
""" Easily find and print all objects of a specified meta type """ from pprint import pprint as pp from Products.Naaya.interfaces import INySite HOST = 'http://forum.eionet.europa.eu' METATYPES = ['Naaya TalkBack Consultation', 'Naaya Event', 'Naaya Meeting', 'Naaya Mega Survey'] results = {} for ob in app.objectValues(): if INySite.providedBy(ob): catalog = ob.getCatalogTool() bfile_brains = catalog({'meta_type': METATYPES}) for brain in bfile_brains: results.setdefault(brain.meta_type, []).append("%s%s" % (HOST, brain.getPath())) pp(results)
""" Get all IG Administrators in the EEA """ from naaya.core.zope2util import users_in_role from Products.Naaya.interfaces import INySite for ob in app.objectValues(): if INySite.providedBy(ob): admins = users_in_role(ob, 'Administrator') for ad in admins: if ad.email.endswith('@eea.europa.eu'): print "\"%s\", %s, %s" % (ob.title_or_id(), ad.full_name, ad.email) group_roles = getattr(ob, '__ny_ldap_group_roles__', None) if group_roles: for gr, roles in group_roles.items(): if 'Administrator' in roles: print("\"%s\", %s, %[email protected]" % (ob.title_or_id(), gr, gr))
from Products.Naaya.interfaces import INySite for site in app.objectValues(): if INySite.providedBy(site): try: site.portal_schemas['NyMeeting']['allow_register-property'].sortorder = 147 site.portal_schemas['NyMeeting']['auto_register-property'].sortorder = 148 except KeyError: print "error in %s" % site else: 'Successful update in %s.' % site
from Products.Naaya.interfaces import INySite for site in app.objectValues(): if INySite.providedBy(site): try: site.portal_schemas['NyMeeting'][ 'allow_register-property'].sortorder = 147 site.portal_schemas['NyMeeting'][ 'auto_register-property'].sortorder = 148 except KeyError: print "error in %s" % site else: 'Successful update in %s.' % site
def _update(self, portal): """ Summary of update: * test for portal_i18n existance, if true, skip portal * get languages and default language * create portal_i18n, place it in portal * copy message translations * fix localized properties * delete Localizer and portal_translations """ #if Localizer is None: # self.log.error('Migration unavailable when edw-localizer' # ' not installed') # return False if isinstance(portal.getPortalI18n(), NaayaI18n): self.log.debug("Portal already uses naaya.i18n, skipping i18n init") localizer = None else: self.log.debug("Creating portal_i18n and copying message catalog data") localizer = portal._getOb('Localizer', None) portal_trans = portal._getOb('portal_translations') if localizer is None: self.log.error("Localizer not found") return False if portal_trans is None: self.log.error("Portal Translations not found") return False languages = [ (x, localizer.get_language_name(x)) for x in localizer.get_languages() ] def_lang = localizer.get_default_language() self.log.debug('Found languages: %r, default: %s', languages, def_lang) manage_addNaayaI18n(portal, languages) portal.getPortalI18n().manage_changeDefaultLang(def_lang) message_cat = portal.getPortalI18n().get_message_catalog() (msg_cnt, trans_cnt) = (0, 0) for (msgid, trans) in portal_trans._messages.items(): if isinstance(msgid, str): msgid = force_to_unicode(msgid) # one call to gettext, to add 'en' identical translation, if missing message_cat.gettext(msgid, def_lang) msg_cnt += 1 for lang in trans: found = message_cat.gettext(msgid, lang, '') if lang != 'note': trans_cnt += 1 if isinstance(trans[lang], unicode): translation = trans[lang] elif isinstance(trans[lang], str): translation = force_to_unicode(trans[lang]) else: self.log.error(("Unacceptable type '%s' found for " "translation") % type(trans[lang])) self.log.error("Migration cancelled") return False if translation != found: message_cat.edit_message(msgid, lang, translation) self.log.debug('%d iterated, a total of %d translation mappings.' % (msg_cnt, trans_cnt)) self.log.debug('Message Catalog now counts %d entries (msgid-s).' % len(message_cat._messages.keys())) # Clean up and delete localizer localizer.manage_beforeDelete(localizer, portal) portal._delObject('Localizer') portal._delObject('portal_translations') self.log.debug('Localizer and Portal translations removed') # Fix local properties: # * remove translations with None-index (instead of language code) # * add existent properties in _local_properties_metadata # * remove blank/emptystring translations # Clean up any LocalAttribute-s on instances, if attribute not # present in class and superclasses or present but is LocalAttribute # key: class, value: attrs on class that are not LocalAttribute # their overrides need to be kept lookup_cache = {} localprops_del_cnt = 0 localprops_keep_cnt = 0 total_cnt = 0 all_objects = itertools.chain([portal], ofs_walk(portal)) # this class is not used anymore: for obj in all_objects: # Part 0.0: remove unused contenttype classes on sites: if INySite.providedBy(obj): if '_contenttypes_tool__contenttype_dictionary' in obj.__dict__: del obj.__dict__['_contenttypes_tool__contenttype_dictionary'] obj._p_changed = 1 # Part 0.1: if broken, report it # if other localizer in NySite child, skip it if isinstance(obj, BrokenClass): self.log.error(("Object %r is broken! Unable to fix local" " properties, if any ") % obj) continue if isinstance(obj, Localizer) and obj != localizer: continue # Part 1: delete unnecessary LocalAttributes on instances if obj.__dict__.get('_languages') is not None: del obj._languages if obj.__dict__.get('_default_language') is not None: del obj._default_language for (key, value) in obj.__dict__.items(): if isinstance(value, LocalAttribute): if not requires_localproperty(obj, key): self.log.debug("Deleting LocalAttribute: %r.%s", obj, key) delattr(obj, key) localprops_del_cnt += 1 else: self.log.debug("Keeping LocalAttribute: %r.%s", obj, key) setattr(obj, key, NewLocalAttribute(key)) localprops_keep_cnt += 1 # Part 2: normalize representation of local properties _local_properties = getattr(obj, '_local_properties', None) if _local_properties is not None: for (property, trans) in _local_properties.items(): if property not in obj._local_properties_metadata: obj.set_localproperty(property, 'string') delete_keys = set() for (lang, translation) in trans.items(): if not translation[0]: delete_keys.add(lang) if len(delete_keys): for key in delete_keys: del trans[key] obj._p_changed = 1 self.log.debug("%d LocalAttribute-s deleted from OFS" % localprops_del_cnt) self.log.debug("%d LocalAttribute-s kept in OFS" % localprops_keep_cnt) self.log.debug('Migration is complete!') return True