Ejemplo n.º 1
0
 def assignTime(self, text):
     for i in range(len(text)):
         if text[i] == 'Start:' or text[i] == 'Start':
             self.startTime = timeformat.format(text[i + 1])
         elif text[i] == 'Break:' or text[i] == 'Break':
             self.startTimeFinish = timeformat.format(text[i + 1])
         elif (text[-1] != 'End:'
               and text[-1] != 'End') and (text[i] == 'End:'
                                           or text[i] == 'End'):
             self.endTime = timeformat.format(text[i + 1])
Ejemplo n.º 2
0
    def value(self, currentPath=None):
        # Default to local timezone and RFC822 format
        utcTime = 0
        strFrmt = self.defaultFormat
        if (currentPath is not None):
            index, paths = currentPath
            currentPath = '/'.join(paths[index:])
            match = PATHREGEX.match(currentPath)
            if (match is not None):
                type = match.group(1)
                if (type == 'local'):
                    utcTime = 0
                else:
                    utcTime = 1
                strFrmt = match.group(2)
                if (strFrmt == ""):
                    strFrmt = self.defaultFormat

        if (self.ourValue is None):
            # Default to the current time!
            timeValue = time.localtime()
        else:
            timeValue = self.ourValue

        if (utcTime):
            # Convert to UTC (GMT)
            timeValue = time.gmtime(time.mktime(timeValue))
        value = timeformat.format(strFrmt, timeValue, utctime=utcTime)
        raise simpleTALES.ContextVariable(value)
Ejemplo n.º 3
0
	def value (self, currentPath=None):
		# Default to local timezone and RFC822 format
		utcTime = 0
		strFrmt = self.defaultFormat
		if (currentPath is not None):
			index, paths = currentPath
			currentPath = '/'.join (paths[index:])
			match = PATHREGEX.match (currentPath)
			if (match is not None):
				type = match.group(1)
				if (type == 'local'):
					utcTime = 0
				else:
					utcTime = 1
				strFrmt = match.group(2)
				if (strFrmt == ""):
					strFrmt = self.defaultFormat
			
		if (self.ourValue is None):
			# Default to the current time!
			timeValue = time.localtime()
		else:
			timeValue = self.ourValue
			
		if (utcTime):
			# Convert to UTC (GMT)
			timeValue = time.gmtime (time.mktime (timeValue))
		value = timeformat.format (strFrmt, timeValue, utctime=utcTime)
		raise simpleTALES.ContextVariable (value)
Ejemplo n.º 4
0
    def getPageContext(self, page, template):
        """ Returns the default context which will apply to most pages of
			content.  Template is the template that this context will 
			eventually be used in, and is used to extract the type
			of output (HTML, XHTML, WML, etc) and the destination
			file extension.
		"""
        copyrightYear = timeformat.format("%Y")

        destExtension = "." + template.getTemplateExtension()
        relativeDestPath = os.path.splitext(page.getRelativePath())[0] + destExtension
        destPath = os.path.join(self.destDir, relativeDestPath)
        destFilename = os.path.basename(destPath)

        pageContext = {
            "lastModifiedDate": DateContext.Date(
                time.localtime(page.getModificationTime()), "%a[SHORT], %d %b[SHORT] %Y %H:%M:%S %Z"
            ),
            "copyrightYear": DateContext.Date(time.localtime(), "%Y"),
            "sourcePath": page.getRelativePath(),
            "absoluteSourcePath": page.getSource(),
            "destinationPath": relativeDestPath,
            "absoluteDestinationPath": destPath,
            "destinationFilename": destFilename,
            "depth": page.getDepthString(),
            "headers": page.getHeaders(),
        }

        siteURLPrefix = page.getOption("url-prefix")
        if siteURLPrefix is not None:
            pageContext["absoluteDestinationURL"] = "%s/%s" % (siteURLPrefix, relativeDestPath)

        return pageContext
Ejemplo n.º 5
0
	def publish (self, page):
		indexTemplate = self.templateConfig.getTemplate (page.getOption ('catalogue-index-template', 'template.html'))
		itemTemplate = self.templateConfig.getTemplate (page.getOption ('catalogue-item-template', 'template.html'))
		
		maxCols = int (page.getOption ('catalogue-max-columns', '5'))
		buildIndexPage = 0
		buildItemPages = 0
		catalogueBuildPages = page.getOption ('catalogue-build-pages', 'index,item')
		for option in catalogueBuildPages.split (','):
			if (option == "index"):
				if (indexTemplate is not None):
					buildIndexPage = 1
				else:
					msg = "Unable to build the index page for catalogue %s because no catalogue-index-template has been specified." % page.getSource()
					self.log.warn (msg)
					self.ui.warn (msg)
			elif (option == "item"):
				if (itemTemplate is not None):
					buildItemPages = 1
				else:
					msg = "Unable to build the item pages for catalogue %s because no catalogue-item-template has been specified." % page.getSource()
					self.log.warn (msg)
					self.ui.warn (msg)
		
		if (not buildIndexPage | buildItemPages):
			msg = "Neither index or item pages are being built for catalogue %s" % page.getSource()
			self.log.warn (msg)
			self.ui.warn (msg)
			return
			
		itemContentType = page.getOption ('catalogue-item-content-type', None)
		if (itemContentType is None or itemContentType.lower() == 'none'):
			# We wish to turn off item content publishing
			itemContentPublisher = None
		else:
			itemContentPublisher = self.pagePublisher.getContentPublisher (itemContentType)
			if (itemContentPublisher is None):
				msg = "Unable to find a publisher for catalogue item content type %s." % itemContentType
				self.log.error (msg)
				raise SitePublisher.PublisherException (msg)
		# Build the context pieces we are going to need
		pageCharSet = page.getOption ('character-set', None)
		if (pageCharSet is not None):
			# This page has it's own character set
			pageCodec = codecs.lookup (self.pageCharSet)
		else:
			# This page uses the default character set.
			pageCodec = self.characterSetCodec
			
		catalogue = CatalogueContent.CatalogueContent (page.getSource(), pageCodec)
		items = []
		rows = []
		col = []
		lastModDate = timeformat.format ('%a[SHORT], %d %b[SHORT] %Y %H:%M:%S %Z', time.localtime (page.getModificationTime()))
		copyrightYear = timeformat.format ('%Y')
		# Source paths
		relativeSourcePath = page.getRelativePath()
		contentDir = self.contentDir
		absSourcePath = page.getSource()
		localDestinationDir = os.path.dirname (page.getRelativePath())
		depth = page.getDepthString()
		
		self.log.debug ("Building the context for each item in the catalogue.")
		for itemHeaders in catalogue.getItems():
			# Destination paths
			filename = itemHeaders.get ('filename', None)
			if (filename is None and buildItemPages):
				msg = "Unable to publish catalogue %s.  Missing filename header in catalogue but item publishing is enabled." % page.getSource()
				self.log.error (msg)
				raise SitePublisher.PublisherException (msg)

			actualHeaders = {}
			actualHeaders.update (page.getHeaders())
			actualHeaders.update (itemHeaders)
			
			if (filename is not None):
				# Used to determine the file to write to, kept in case the pageContext doesn't contain them.
				relativeDestPath = os.path.join (localDestinationDir, os.path.splitext (filename)[0] + '.html')
				destPath = os.path.join (self.destDir, relativeDestPath)
				
				if (itemContentPublisher is not None):
					self.log.debug ("Retrieving page context for this catalogue entry.")
					
					# We need a page for this entry so that we can get it's content.
					itemPageList = self.contentConfig.getPages (os.path.join (contentDir, filename), {})
					
					if (len (itemPageList) > 1):
						self.ui.warn ("Catalogue contains content type that returns more than one page!  Only building first page.")
					itemPage = itemPageList [0]
					
					pageContext = itemContentPublisher.getPageContext (itemPage, itemTemplate)
					actualHeaders.update (pageContext.get ('headers', {}))
					pageContext ['headers'] = actualHeaders
					if (not pageContext.has_key ('destinationPath')):
						pageContext ['destinationPath'] = relativeDestPath
					if (not pageContext.has_key ('absoluteDestinationPath')):
						pageContext ['absoluteDestinationPath'] = destPath
				else:
					self.log.debug ("No content type for this catalogue entry - just publish what we have.")
					
					# Get the generic page information for this file
					relativeDestPath = os.path.join (localDestinationDir, os.path.splitext (filename)[0] + '.' + itemTemplate.getTemplateExtension())
					destPath = os.path.join (self.destDir, relativeDestPath)
					destFilename = os.path.basename (destPath)
					actualHeaders = {}
					actualHeaders.update (page.getHeaders())
					actualHeaders.update (itemHeaders)
					
					pageContext = {'lastModifiedDate': lastModDate
								,'copyrightYear': copyrightYear
								,'sourcePath': relativeSourcePath
								,'absoluteSourcePath': absSourcePath
								,'destinationPath': relativeDestPath
								,'absoluteDestinationPath': destPath
								,'destinationFilename': destFilename
								,'depth': depth
								,'headers': actualHeaders
								}
			else:
				# No filename specified for this entry
				pageContext = {'headers': actualHeaders}
			items.append (pageContext)
			if (len (col) == maxCols):
				rows.append (col)
				col = []
			col.append (pageContext)
		if (len (col) > 0):
			rows.append (col)
			col = []
		
		# Build the Catalogue context
		catalogueMap = {'entries': items, 'rows': rows, 'headers': catalogue.getCatalogueHeaders()}
		# Do the individual items now
		if (buildItemPages):
			itemCount = 0
			itemLength = len (items)
			for item in items:
				relativeDestPath = item['destinationPath']
				context = simpleTALES.Context(allowPythonPath=1)
				context.addGlobal ('page', item)
				if (itemCount > 0):
					catalogueMap ['previous'] = items[itemCount - 1]
				elif (catalogueMap.has_key ('previous')):
					del catalogueMap ['previous']
				if (itemCount < itemLength - 1):
					catalogueMap ['next'] = items[itemCount + 1]
				elif (catalogueMap.has_key ('next')):
					del catalogueMap ['next']
					
				context.addGlobal ('catalogue', catalogueMap)
				
				macros = page.getMacros()
				self.pagePublisher.expandTemplate (itemTemplate, context, relativeDestPath, macros)
				itemCount += 1
				
		if (buildIndexPage):
			# Cleanup the catalogueMap from the items pages.
			if (catalogueMap.has_key ('previous')):
				del catalogueMap ['previous']
			if (catalogueMap.has_key ('next')):
				del catalogueMap ['next']
			
			indexMap = self.getPageContext (page, indexTemplate, catalogue)			
			relativeDestPath = indexMap ['destinationPath']
			
			context = simpleTALES.Context(allowPythonPath=1)
			context.addGlobal ('page', indexMap)			
			context.addGlobal ('catalogue', catalogueMap)
			
			macros = page.getMacros()
			self.pagePublisher.expandTemplate (indexTemplate, context, relativeDestPath, macros)