def run(self, root, options): if options.keep < 1: fail("You need to keep at least one version") logger.info('Removing old versions ...') removed = 0 count = 0 for count, content in enumerate(walk_silva_tree(root)): if not IVersionedContent.providedBy(content): continue versions = content._previous_versions if not versions: continue if count and count % 500 == 0: # Commit now and when transaction.commit() removable_versions = versions[:-options.keep] content._previous_versions = versions[-options.keep:] contained_ids = content.objectIds() removable_version_ids = set([ str(version[0]) for version in removable_versions if version[0] in contained_ids]) removed += len(removable_version_ids) content.manage_delObjects(list(removable_version_ids)) if removed and removed % 500 == 0: logger.info('Removed %d versions, continuing ...' % removed) if removed: logger.info('Removed %d versions in total' % removed) transaction.commit() else: logger.info('Nothing removed')
def run(self, root, options): if options.list: logger.info('Listing silva sites') for content in root.objectValues(): if IRoot.providedBy(content): logger.info('%s (version %s)' % ( '/'.join(content.getPhysicalPath()), content.get_silva_content_version())) return if not options.identifier: fail(u"Please provide a site identifier") identifier = options.identifier if ':' in identifier: identifier, title = identifier.split(':', 1) else: title = identifier if options.delete: if identifier not in root.objectIds(): fail( u'There is no such Silva root "%s" to delete.', identifier) root.manage_delObjects([identifier]) return if options.add: if identifier in root.objectIds(): fail( u'There is already a Zope object identifier by "%s"', identifier) factory = root.manage_addProduct['Silva'] factory.manage_addRoot(identifier, title) transaction.commit() logger.info( u'Silva root "%s" added.', identifier) root = root._getOb(identifier) if options.documentation: factory = root.manage_addProduct['SilvaFind'] factory.manage_addSilvaFind('search', 'Search this site') install_documentation(root, TestRequest()) transaction.commit() logger.info( u'Silva documentation installed inside Silva root "%s".', identifier) if options.user: parts = options.user.split(':') if len(parts) < 2 or len(parts) > 3: fail('Impossible to interpret user definition') username = parts[0] password = parts[1] role = parts[2] if len(parts) == 3 else 'Manager' acl_users = root._getOb('acl_users') users = acl_users._getOb('users') roles = acl_users._getOb('roles') if not role in roles.listRoleIds(): fail(u'Role "%s" unknown.' % role) users.addUser(username, username, password) roles.assignRoleToPrincipal(role, username) transaction.commit() logger.info( u'User added to Silva root "%s".', identifier)
def run(self, db, options): if options.days < 0: fail(u'Cannot pack in the future.') db = db.databases.get(options.name) if db is None: fail(u'Unknown database "%s", cannot pack it.', options.name) logger.info( u'Packing "%s" database, keeping %d days ...', options.name, options.days) db.pack(time.time()-options.days*86400)