source: enpraxis.staticsite/trunk/enpraxis/staticsite/utilities/staticsiteutility.py @ 265

Revision 265, 2.4 KB checked in by david, 4 years ago (diff)

Passing subdomain down to deployObject and updating code to work with deployment_path existing as a property

Line 
1import Globals
2import httplib
3import os
4
5from OFS.SimpleItem import SimpleItem
6from zope.interface import implements
7from interfaces import IStaticSiteUtility
8from zope.component import getUtility
9
10class StaticSiteUtility(SimpleItem):
11    """ Deploy a static site """
12
13    implements(IStaticSiteUtility)
14
15    def _getDeploymentPath(self, sp):
16        """ Get the default static path location. """
17        rpath = os.path.split(Globals.BobobaseName)[0]
18        return os.path.join(rpath, sp.getProperty('deployment_path'))
19       
20    def createDirectory(self, path):
21        """ Create a directory on the filesystem """     
22        if not os.path.lexists(path):
23            os.makedirs(path)
24           
25    def deploySite(self, context):
26        """ Deploy the site """
27
28        ssprops = context.portal_url.portal_properties.staticsite_properties
29        subdomain = ssprops.getProperty('subdomain')
30        rpath = self._getDeploymentPath(ssprops)
31        self.createDirectory(rpath)
32
33        allowed = context.portal_types.getTypeInfo('Plone Site').allowed_content_types
34        brains = context.portal_catalog.searchResults(
35            path={'query':'/'.join(context.getPhysicalPath()),
36                  'depth':1,},
37            portal_type=allowed,
38            review_state='Published')
39        for x in brains:
40            self.traverse(x, rpath, subdomain)
41
42    def traverse(self, brain, rpath, subdomain):
43        """ Traverse the site. """
44        brains = brain.portal_catalog.searchResults(
45            path={'query':brain.getPath(), 'depth':1},
46                  review_state='Published')
47        for x in brains:
48            url = x.getURL()
49            self.deployObject(url, x, rpath, subdomain)
50            if x.is_folderish:
51                self.traverse(x, rpath, subdomain)
52           
53    def deployObject(self, url, brain, rpath, subdomain):
54        """ Deploy an object """
55        portal_url = brain.portal_url()   
56        if brain.is_folderish:
57            #create dir before processing html
58            folder_path = url.replace(portal_url, rpath)
59            self.createDirectory(folder_path)
60        raw = self.httpget(url, portal_url, subdomain)       
61        data = self.runFilters(raw, None)
62        print url
63
64    def runFilters(self, data, filterchain):
65        """ Filter content """
66        return data
67   
68    def httpget(self, url, portal_url, subdomain):
69        url = url.replace(portal_url, subdomain)
70        return url
71
72
Note: See TracBrowser for help on using the repository browser.