Author: jmorliaguet Date: Sun Apr 9 14:49:37 2006 New Revision: 2796 Added: cpsskins/branches/jmo-perspectives/setup/snapshot.py (contents, props changed) cpsskins/branches/jmo-perspectives/setup/storage.py (contents, props changed) Modified: cpsskins/branches/jmo-perspectives/setup/configure.zcml cpsskins/branches/jmo-perspectives/thememanager.py cpsskins/branches/jmo-perspectives/ui/panels/io_section.pt cpsskins/branches/jmo-perspectives/ui/screens/sitemanager/configure.zcml cpsskins/branches/jmo-perspectives/ui/screens/sitemanager/views.py Log:
- added snapshot storage and a view to create site snapshots Modified: cpsskins/branches/jmo-perspectives/setup/configure.zcml ============================================================================== --- cpsskins/branches/jmo-perspectives/setup/configure.zcml (original) +++ cpsskins/branches/jmo-perspectives/setup/configure.zcml Sun Apr 9 14:49:37 2006 @@ -34,4 +34,29 @@ zcml:condition="have devmode" /> + + <!-- snapshot storage --> + <cpsskins:storage + id="snapshots" + title="Snapshot storage" + description="A snapshot storage contains site snapshots" + class="cpsskins.setup.storage.SnapshotStorage" + interface="cpsskins.setup.storage.ISnapshotStorage" + /> + + + <class class="cpsskins.setup.snapshot.Snapshot"> + + <require + permission="zope.View" + interface="cpsskins.setup.snapshot.ISnapshot" + /> + + <require + permission="zope.ManageContent" + set_schema="cpsskins.setup.snapshot.ISnapshot" + /> + + </class> + </configure> Added: cpsskins/branches/jmo-perspectives/setup/snapshot.py ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/setup/snapshot.py Sun Apr 9 14:49:37 2006 @@ -0,0 +1,41 @@ +############################################################################## +# +# Copyright (c) 2005-2006 Nuxeo and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## +""" + +$Id$ +""" +__docformat__ = "reStructuredText" + +import time + +from zope.app.container.contained import Contained +from zope.interface import implements +from zope.app.file import File +from zope.app.file.interfaces import IFile + +class ISnapshot(IFile): + """A site snapshot""" + +class Snapshot(File, Contained): + """A site snapshot""" + + implements(ISnapshot) + + def __init__(self, data): + self.data = data + self.contentType = 'application/tgz' + + self.filename = 'site-%4d-%02d-%02d-%02d:%02d:%02d.tgz' % \ + time.gmtime()[:6] + Added: cpsskins/branches/jmo-perspectives/setup/storage.py ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/setup/storage.py Sun Apr 9 14:49:37 2006 @@ -0,0 +1,36 @@ +############################################################################## +# +# Copyright (c) 2005-2006 Nuxeo and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## +""" + +$Id$ +""" +__docformat__ = "reStructuredText" + +from zope.app.container.constraints import contains +from zope.interface import implements + +from cpsskins.setup.snapshot import ISnapshot +from cpsskins.storage import Storage +from cpsskins.storage.interfaces import IStorage + +class ISnapshotStorage(IStorage): + """ """ + contains(ISnapshot) + +class SnapshotStorage(Storage): + """A BTree-based snapshot container""" + implements(ISnapshotStorage) + + + Modified: cpsskins/branches/jmo-perspectives/thememanager.py ============================================================================== --- cpsskins/branches/jmo-perspectives/thememanager.py (original) +++ cpsskins/branches/jmo-perspectives/thememanager.py Sun Apr 9 14:49:37 2006 @@ -45,6 +45,7 @@ from cpsskins.relations.storage import RelationStorage from cpsskins.setup.interfaces import IResourceManager, ISettings from cpsskins.setup.settings import Settings +from cpsskins.setup.storage import ISnapshotStorage, SnapshotStorage logger = logging.getLogger("cpsskins") @@ -138,7 +139,7 @@ super(ThemeManagementFolder, self).__init__() # negotiation strategy self.negotiation = negotiation - # registries, storages + # registries, storages, etc. self[u'uids'] = IntIds() self[u'imagecache'] = ImageCache() self[u'settings'] = Settings() @@ -146,6 +147,8 @@ self[u'portlets'] = PortletStorage() self[u'displays'] = DisplayStorage() self[u'formats'] = FormatStorage() + # snapshots + self[u'snapshots'] = SnapshotStorage() ################################################################### # Local utilities @@ -153,6 +156,7 @@ def registerUtilities(self): self.registerUtility(IIntIds, self[u'uids']) + self.registerUtility(ISnapshotStorage, self[u'snapshots']) self.registerUtility(IImageCache, self[u'imagecache']) self.registerUtility(ISettings, self[u'settings']) self.registerUtility(IRelationStorage, self[u'relations']) @@ -174,6 +178,9 @@ def getRelationStorage(self): return getUtility(IRelationStorage, context=self) + def getSnapshotStorage(self): + return getUtility(ISnapshotStorage, context=self) + ################################################################### # Unique id registry ################################################################### Modified: cpsskins/branches/jmo-perspectives/ui/panels/io_section.pt ============================================================================== --- cpsskins/branches/jmo-perspectives/ui/panels/io_section.pt (original) +++ cpsskins/branches/jmo-perspectives/ui/panels/io_section.pt Sun Apr 9 14:49:37 2006 @@ -17,7 +17,7 @@ <div tal:condition="python: section == 'snapshots'"> <h3>Snapshots</h3> - Make a snapshot + <a href="@@createSnapshot">Make a snapshot</a> </div> </div> Modified: cpsskins/branches/jmo-perspectives/ui/screens/sitemanager/configure.zcml ============================================================================== --- cpsskins/branches/jmo-perspectives/ui/screens/sitemanager/configure.zcml (original) +++ cpsskins/branches/jmo-perspectives/ui/screens/sitemanager/configure.zcml Sun Apr 9 14:49:37 2006 @@ -58,21 +58,6 @@ /> <page - name="exportSettings" - attribute="exportSettings" - /> - - <page - name="exportStorage" - attribute="exportStorage" - /> - - <page - name="exportThemes" - attribute="exportThemes" - /> - - <page name="exportSite" attribute="exportSite" /> @@ -82,6 +67,11 @@ attribute="importSite" /> + <page + name="createSnapshot" + attribute="createSnapshot" + /> + </pages> </configure> Modified: cpsskins/branches/jmo-perspectives/ui/screens/sitemanager/views.py ============================================================================== --- cpsskins/branches/jmo-perspectives/ui/screens/sitemanager/views.py (original) +++ cpsskins/branches/jmo-perspectives/ui/screens/sitemanager/views.py Sun Apr 9 14:49:37 2006 @@ -18,6 +18,7 @@ __docformat__ = "reStructuredText" from zope.app.interface import queryType +from zope.app.file import File from zope.app.publisher.browser import BrowserView from zope.component import getUtilitiesFor, getUtility, getMultiAdapter from zope.component import queryUtility, getAllUtilitiesRegisteredFor @@ -29,6 +30,7 @@ from cpsskins.setup.interfaces import IResourceType, IResourceManager, IResource from cpsskins.setup.registration import reloadSetting, refreshSettings from cpsskins.setup.utils import TarArchive +from cpsskins.setup.snapshot import Snapshot from cpsskins.utils import getThemeManager themes_xml = """<?xml version="1.0"?> @@ -119,15 +121,16 @@ # Site ################################################################### - def exportSite(self): + def exportSite(self, interactive=True): """Export the entire site an XML file. """ filename = 'site.tgz' - response = self.request.response - response.setHeader('content-type', 'application/gz') - response.setHeader('Content-disposition', - 'attachment; filename=%s' % filename) + if interactive: + response = self.request.response + response.setHeader('content-type', 'application/tgz') + response.setHeader('Content-disposition', + 'attachment; filename=%s' % filename) archive = TarArchive(filename='site.tgz', mode='w') @@ -154,6 +157,16 @@ # TODO + def createSnapshot(self): + mgr = getThemeManager() + + data = self.exportSite(False) + + snapshots = mgr.getSnapshotStorage() + + snapshot = Snapshot(data=data) + snapshots.add(snapshot, snapshot.filename) + ################################################################### # Storage ################################################################### -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins