def exportTypesTool(context): """ Export types tool content types as a set of XML files. """ site = context.getSite() ttool = getToolByName(site, 'portal_types') if ttool is None: return 'Types tool: Nothing to export.' ttc = TypesToolExportConfigurator(site).__of__(site) tool_xml = ttc.generateXML() context.writeDataFile(_FILENAME, tool_xml, 'text/xml') for ti_id in ttool.listContentTypes(): type_filename = '%s.xml' % ti_id.replace( ' ', '_' ) ti = getattr(ttool, ti_id) exporter = INodeExporter(ti) if exporter is None: continue doc = PrettyDocument() doc.appendChild(exporter.exportNode(doc)) context.writeDataFile(type_filename, doc.toprettyxml(' '), 'text/xml', 'types') # XXX: YAGNI? # exportScriptsFromContainer(ttool, ('typestool_scripts',)) return 'Types tool exported'
def exportTypesTool(context): """ Export types tool content types as a set of XML files. """ site = context.getSite() ttool = getToolByName(site, 'portal_types') if ttool is None: return 'Types tool: Nothing to export.' ttc = TypesToolExportConfigurator(site).__of__(site) tool_xml = ttc.generateXML() context.writeDataFile(_FILENAME, tool_xml, 'text/xml') for ti_id in ttool.listContentTypes(): type_filename = '%s.xml' % ti_id.replace(' ', '_') ti = getattr(ttool, ti_id) exporter = INodeExporter(ti) if exporter is None: continue doc = PrettyDocument() doc.appendChild(exporter.exportNode(doc)) context.writeDataFile(type_filename, doc.toprettyxml(' '), 'text/xml', 'types') # XXX: YAGNI? # exportScriptsFromContainer(ttool, ('typestool_scripts',)) return 'Types tool exported'
def test_attr_quoting(self): original = 'baz <bar>&"\'' expected = ('<?xml version="1.0"?>\n' '<doc foo="baz &nbsp;<bar>&"\'"/>\n') doc = PrettyDocument() node = doc.createElement('doc') node.setAttribute('foo', original) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), expected) # Reparse e = parseString(expected).documentElement self.assertEqual(e.getAttribute('foo'), original)
def test_attr_quoting(self): from Products.GenericSetup.utils import PrettyDocument original = "baz <bar>&\"'" expected = '<?xml version="1.0"?>\n' '<doc bar="" foo="baz ' "&nbsp;<bar>&"'\"/>\n" doc = PrettyDocument() node = doc.createElement("doc") node.setAttribute("foo", original) node.setAttribute("bar", None) doc.appendChild(node) self.assertEqual(doc.toprettyxml(" "), expected) # Reparse e = _getDocumentElement(expected) self.assertEqual(e.getAttribute("foo"), original)
def test_attr_quoting(self): from Products.GenericSetup.utils import PrettyDocument original = 'baz <bar>&"\'' expected = ('<?xml version="1.0"?>\n' '<doc bar="" foo="baz &nbsp;<bar>&"\'"/>\n') doc = PrettyDocument() node = doc.createElement('doc') node.setAttribute('foo', original) node.setAttribute('bar', None) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), expected) # Reparse e = _getDocumentElement(expected) self.assertEqual(e.getAttribute('foo'), original)
def test__extractProperties_empty(self): doc = self.helpers._doc = PrettyDocument() node = doc.createElement('dummy') node.appendChild(self.helpers._extractProperties()) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), _EMPTY_PROPERTY_EXPORT)
def exportMailHost(context): """ Export mailhost settings as an XML file. """ site = context.getSite() mailhost = getToolByName(site, 'MailHost', None) if mailhost is None: return 'Mailhost: Nothing to export.' exporter = INodeExporter(mailhost) if exporter is None: return 'Mailhost: Export adapter misssing.' doc = PrettyDocument() doc.appendChild(exporter.exportNode(doc)) context.writeDataFile(_FILENAME, doc.toprettyxml(' '), 'text/xml') return 'Mailhost settings exported.'
def exportCookieCrumbler(context): """ Export cookie crumbler settings as an XML file. """ site = context.getSite() cctool = getToolByName(site, 'cookie_authentication', None) if cctool is None: return 'Cookie crumbler: Nothing to export.' exporter = INodeExporter(cctool) if exporter is None: return 'Cookie crumbler: Export adapter misssing.' doc = PrettyDocument() doc.appendChild(exporter.exportNode(doc)) context.writeDataFile(_FILENAME, doc.toprettyxml(' '), 'text/xml') return 'Cookie crumbler settings exported.'
def exportCatalogTool(context): """ Export catalog tool. """ site = context.getSite() ctool = getToolByName(site, 'portal_catalog', None) if ctool is None: return 'Catalog tool: Nothing to export.' exporter = INodeExporter(ctool) if exporter is None: return 'Catalog tool: Export adapter misssing.' doc = PrettyDocument() doc.appendChild(exporter.exportNode(doc)) context.writeDataFile(_FILENAME, doc.toprettyxml(' '), 'text/xml') return 'Catalog tool exported.'
def exportActionProviders(context): """ Export actions tool. """ site = context.getSite() atool = getToolByName(site, 'portal_actions', None) if atool is None: return 'Actions tool: Nothing to export.' exporter = INodeExporter(atool) if exporter is None: return 'Actions tool: Export adapter misssing.' doc = PrettyDocument() doc.appendChild(exporter.exportNode(doc)) context.writeDataFile(_FILENAME, doc.toprettyxml(' '), 'text/xml') return 'Actions tool exported.'
def test__extractMarkers(self): self._populate(self.helpers.context) doc = self.helpers._doc = PrettyDocument() node = doc.createElement('dummy') node.appendChild(self.helpers._extractMarkers()) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), _NORMAL_MARKER_EXPORT)
def test__extractProperties_normal(self): self._populate(self.helpers.context) doc = self.helpers._doc = PrettyDocument() node = doc.createElement('dummy') node.appendChild(self.helpers._extractProperties()) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), _NORMAL_PROPERTY_EXPORT)
def test__extractProperties_empty(self): from Products.GenericSetup.utils import PrettyDocument helpers = self._makeOne() doc = helpers._doc = PrettyDocument() node = doc.createElement('dummy') node.appendChild(helpers._extractProperties()) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), _EMPTY_PROPERTY_EXPORT)
def __init__(self, object): self.object = object self.site = getSite() import logging self._logger = logging.getLogger('wildcard.migrator') self._doc = PrettyDocument() self.sitepath = '/'.join(getSite().getPhysicalPath()) self.objectpath = '/'.join( object.getPhysicalPath())[len(self.sitepath):]
def test__extractMarkers(self): from Products.GenericSetup.utils import PrettyDocument helpers = self._makeOne() self._populate(helpers.context) doc = helpers._doc = PrettyDocument() node = doc.createElement('dummy') node.appendChild(helpers._extractMarkers()) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), _NORMAL_MARKER_EXPORT)
def test__initProperties_fixed(self): node = parseString(_FIXED_PROPERTY_EXPORT).documentElement self.helpers._initProperties(node, PURGE) doc = self.helpers._doc = PrettyDocument() node = doc.createElement('dummy') node.appendChild(self.helpers._extractProperties()) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), _NORMAL_PROPERTY_EXPORT)
def test__initProperties_special(self): node = parseString(_SPECIAL_IMPORT).documentElement self.helpers._initProperties(node) doc = self.helpers._doc = PrettyDocument() node = doc.createElement('dummy') node.appendChild(self.helpers._extractProperties()) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), _EMPTY_PROPERTY_EXPORT)
def test__initMarkers(self): node = parseString(_NORMAL_MARKER_EXPORT).documentElement self.helpers._initMarkers(node) self.failUnless(IDummyMarker.providedBy(self.helpers.context)) doc = self.helpers._doc = PrettyDocument() node = doc.createElement('dummy') node.appendChild(self.helpers._extractMarkers()) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), _NORMAL_MARKER_EXPORT)
def test__extractProperties_normal(self): from Products.GenericSetup.utils import PrettyDocument helpers = self._makeOne() obj = self._getReal(helpers.context) self._populate(obj) doc = helpers._doc = PrettyDocument() node = doc.createElement('dummy') node.appendChild(helpers._extractProperties()) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), _NORMAL_PROPERTY_EXPORT)
def test__initProperties_fixed(self): from Products.GenericSetup.utils import PrettyDocument helpers = self._makeOne() node = _getDocumentElement(_FIXED_PROPERTY_EXPORT) helpers._initProperties(node) doc = helpers._doc = PrettyDocument() node = doc.createElement('dummy') node.appendChild(helpers._extractProperties()) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), _NORMAL_PROPERTY_EXPORT)
def test__initProperties_normal(self): node = parseString(_NORMAL_PROPERTY_EXPORT).documentElement self.helpers._initProperties(node) self.assertEqual(type(self.helpers.context.foo_int), int) self.assertEqual(type(self.helpers.context.foo_string), str) self.assertEqual(type(self.helpers.context.foo_tokens), tuple) self.assertEqual(type(self.helpers.context.foo_tokens[0]), str) doc = self.helpers._doc = PrettyDocument() node = doc.createElement('dummy') node.appendChild(self.helpers._extractProperties()) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), _NORMAL_PROPERTY_EXPORT)
def test__extractProperties_normal(self): self._populate(self.helpers.context) doc = self.helpers._doc = PrettyDocument() node = doc.createElement('dummy') # The extraction process wants to decode text properties # to unicode using the default ZPublisher encoding, which # defaults to iso-8859-15. We force UTF-8 here because we # forced our properties to be UTF-8 encoded. self.helpers._encoding = 'utf-8' node.appendChild(self.helpers._extractProperties()) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), _NORMAL_PROPERTY_EXPORT)
def test__initMarkers(self): from Products.GenericSetup.utils import PrettyDocument from Products.GenericSetup.testing import IDummyMarker helpers = self._makeOne() node = _getDocumentElement(_NORMAL_MARKER_EXPORT) helpers._initMarkers(node) self.failUnless(IDummyMarker.providedBy(helpers.context)) doc = helpers._doc = PrettyDocument() node = doc.createElement('dummy') node.appendChild(helpers._extractMarkers()) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), _NORMAL_MARKER_EXPORT)
def get_portlet_blacklist_xml(context, prefix): return_value = False doc = PrettyDocument() node = doc.createElement('portlets') key = '/'.join(context.getPhysicalPath()) if key.startswith(prefix): key = key[len(prefix):] key = key or '/' for manager_name, manager in getUtilitiesFor(IPortletManager): assignable = queryMultiAdapter((context, manager), ILocalPortletAssignmentManager) if assignable is None: continue for category in (USER_CATEGORY, GROUP_CATEGORY, CONTENT_TYPE_CATEGORY, CONTEXT_CATEGORY): # noqa child = doc.createElement('blacklist') child.setAttribute('manager', manager_name) child.setAttribute('category', category) child.setAttribute('location', key) status = assignable.getBlacklistStatus(category) if status: child.setAttribute('status', u'block') return_value = True elif not status: child.setAttribute('status', u'show') return_value = True else: child.setAttribute('status', u'acquire') node.appendChild(child) doc.appendChild(node) xml = doc.toprettyxml(' ') doc.unlink() if return_value: yield xml
def test_text_quoting(self): original = 'goo <hmm>&"\'' expected = ('<?xml version="1.0"?>\n' '<doc>goo &nbsp;<hmm>&"\'</doc>\n') doc = PrettyDocument() node = doc.createElement('doc') child = doc.createTextNode(original) node.appendChild(child) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), expected) # Reparse e = parseString(expected).documentElement self.assertEqual(e.childNodes[0].nodeValue, original)
def test__initProperties_normal(self): from Products.GenericSetup.utils import PrettyDocument helpers = self._makeOne() obj = self._getReal(helpers.context) node = _getDocumentElement(_NORMAL_PROPERTY_EXPORT) helpers._initProperties(node) self.assertEqual(type(obj.foo_int), int) self.assertEqual(type(obj.foo_string), str) self.assertEqual(type(obj.foo_tokens), tuple) self.assertEqual(type(obj.foo_tokens[0]), str) doc = helpers._doc = PrettyDocument() node = doc.createElement('dummy') node.appendChild(helpers._extractProperties()) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), _NORMAL_PROPERTY_EXPORT)
def test_text_quoting(self): from Products.GenericSetup.utils import PrettyDocument original = "goo <hmm>&\"'" expected = '<?xml version="1.0"?>\n' "<doc>goo &nbsp;<hmm>&\"'</doc>\n" doc = PrettyDocument() node = doc.createElement("doc") child = doc.createTextNode(original) node.appendChild(child) doc.appendChild(node) self.assertEqual(doc.toprettyxml(" "), expected) # Reparse e = _getDocumentElement(expected) self.assertEqual(e.childNodes[0].nodeValue, original)
def test_attr_quoting(self): from Products.GenericSetup.utils import PrettyDocument original = 'baz <bar>&"\'' expected = ('<?xml version="1.0"?>\n' '<doc bar="" foo="baz ' '&nbsp;<bar>&"\'"/>\n') doc = PrettyDocument() node = doc.createElement('doc') node.setAttribute('foo', original) node.setAttribute('bar', None) doc.appendChild(node) self.assertEqual(doc.toprettyxml(' '), expected) # Reparse e = _getDocumentElement(expected) self.assertEqual(e.getAttribute('foo'), original)
def get_portlet_assignment_xml(context, prefix): doc = PrettyDocument() node = doc.createElement('portlets') for manager_name, manager in getUtilitiesFor(IPortletManager): mapping = queryMultiAdapter((context, manager), IPortletAssignmentMapping) if mapping is None: continue mapping = mapping.__of__(context) key = '/'.join(context.getPhysicalPath()) if key.startswith(prefix): key = key[len(prefix):] key = key or '/' extract_mapping(doc, node, manager_name, CONTEXT_CATEGORY, key, mapping) doc.appendChild(node) xml = patch_portlets_xml(doc.toprettyxml(' '), prefix) doc.unlink() return xml
def extract_mapping(manager_name, category, key, mapping): portlets_schemata = dict([ (iface, name) for name, iface in getUtilitiesFor(IPortletTypeInterface) ]) for name, assignment in mapping.items(): type_ = None schema = None for schema in providedBy(assignment).flattened(): type_ = portlets_schemata.get(schema, None) if type_ is not None: break if type_ is not None: child = PrettyDocument().createElement('assignment') child.setAttribute('manager', manager_name) child.setAttribute('category', category) child.setAttribute('key', key) child.setAttribute('type', type_) child.setAttribute('name', name) assignment = assignment.__of__(mapping) settings = IPortletAssignmentSettings(assignment) visible = settings.get('visible', True) child.setAttribute('visible', repr(visible)) handler = IPortletAssignmentExportImportHandler(assignment) handler.export_assignment(schema, PrettyDocument(), child) yield child
def test_exportNode_special(self): self._populate_special(self._obj) node = INodeExporter(self._obj).exportNode(PrettyDocument()) self.assertEqual(node.toprettyxml(' '), _CATALOG_XML % (_VOCABULARY_XML, _TEXT_XML))