Skip to content

Commit

Permalink
improving static website generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fiers committed Sep 8, 2012
1 parent 1bee14d commit 958a661
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 33 deletions.
44 changes: 39 additions & 5 deletions lib/python/moa/plugin/system/doc/pelican_util.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,59 @@
"""
Functions to support pelican
"""

import datetime
import os

import moa.logger
from Yaco import Yaco

import jinja2


jenv = jinja2.Environment(loader=jinja2.PackageLoader('moa.plugin.system.doc'))

import moa.logger
l = moa.logger.getLogger(__name__)

from Yaco import Yaco


def _getpagename(name):
"""
Create a filename for a pelican page with this name
:param name: Name of the page
:type name: String
"""
pagedir = os.path.join('doc', 'pages')
if not os.path.exists(pagedir):
os.makedirs(pagedir)

return os.path.join(pagedir, name)


def _getpostname(category):
"""
Return a file name for a (blog) "post" -
:param category: post category
:type category: string
"""

pagedir = os.path.join('doc', category)
if not os.path.exists(pagedir):
os.makedirs(pagedir)

now = datetime.datetime.now()
filename = os.path.join(pagedir, '%s_%d%d%d_%d%d%d.md' % (
category, now.year, now.month, now.day,
now.hour, now.minute, now.second))
return filename


def generate_redirect(job):
"""
Create a redirect page
:param job: job for the HTML redirect
:type job: moa.job.Job object
"""
jtemplate = jenv.select_template(['redirect.jinja2'])
pagename = _getpagename('template.md')
Expand All @@ -36,10 +67,13 @@ def generate_redirect(job):
def generate_template_page(job):
"""
create a page with template parameters
:type job: moa.job.Job object
"""
jtemplate = jenv.select_template(['template.page.jinja2'])
pagename = _getpagename('template.md')
pagename = _getpostname('template')

l.warning("generate template page")
with open(pagename, 'w') as F:
F.write(jtemplate.render({
't': job.template}))
Expand Down
4 changes: 3 additions & 1 deletion lib/python/moa/plugin/system/doc/templates/file.page.jinja2
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Title: filesets
Title: Filesets
Category: Filesets


Set | Name | Typ | Cat | File
-----|--------------|-----|---------|----------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# -*- coding: utf-8 -*-

SITEURL = './doc/test/test/pelican/'
SITEURL = './doc/pelican/'
SITENAME = "Moa"
DEFAULT_LANG = 'en'
SERVER = u'{{ doc.server }}'
WD= u'{{ job.wd }}'
RELATIVE_URLS = True
DISPLAY_PAGES_ON_MENU = True
DEFAULT_PAGINATION = 5
DEFAULT_PAGINATION = 15
OUTPUT_PATH = './doc/pelican/'
#PATH = 'doc'
REVERSE_ARCHIVE_ORDER = True
CONTENT_STATIC_LOC = '../../'
MD_EXTENSIONS = ['tables']
SUMMARY_MAX_LENGTH = 550
SUMMARY_MAX_LENGTH = 50

LINKS = (('Moa docs', 'http://mfiers.github.com/Moa/'),
LINKS = (('Moa docs', 'http://mfiers.github.com/Moa/'),
('Moa source', 'https://github.com/mfiers/Moa'),
)

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Title: template "{{ t.moa_id }}"
Category: template

{{ t.description }}

Expand Down Expand Up @@ -39,4 +40,4 @@ Name | O | type | help

* Author: {{ t.author }}
* Backend: {{ t.backend }}
*
*
54 changes: 32 additions & 22 deletions lib/python/moa/plugin/system/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,21 @@ def hook_pelican():
'vinfo': vinfo}))


@moa.args.needsJob
@moa.args.command
def log(job, args):
def _getLog(job, noLines=10):
"""
Show activity log
Retrieve the last noLines of the log file
Shows a log of moa commands executed. Only commands with an impact
on the pipeline are logged, such as `moa run` & `moa set`.
:param noLines: no of lines to retrieve
:type noLines: int
"""

noLines = 10
logFile = os.path.join(job.confDir, 'log')

moa.utils.moaDirOrExit(job)
if not os.path.exists(logFile):
moa.ui.exit("No logs found")

rv = []
with open(logFile) as F:
#read the last 2k - prevent reading the whole file
try:
Expand All @@ -228,18 +226,30 @@ def _isInteger(_s):

continue

status, command, logLevel, start, stop, delta, command = \
line.split("\t")

logLevel = int(logLevel)
if status == 'ok':
lc = '{{bold}}{{green}}Success {{reset}}'
elif status == 'error':
lc = "{{bold}}{{red}}Error {{reset}}"
else:
lc = "{{blue}}%-8s{{reset}}" % status[:7].capitalize()

lc += "%s " % start.rsplit(':', 1)[0]
lc += "%10s " % niceRunTime(delta)
lc += command
moa.ui.fprint(lc, f='jinja')
rv.append(line.split("\t"))
return rv

@moa.args.needsJob
@moa.args.command
def log(job, args):
"""
Show activity log
Shows a log of moa commands executed. Only commands with an impact
on the pipeline are logged, such as `moa run` & `moa set`.
"""
for logRec in _getLog(job, 10):
status, command, logLevel, start, stop, delta, command = logRec

logLevel = int(logLevel)
if status == 'ok':
lc = '{{bold}}{{green}}Success {{reset}}'
elif status == 'error':
lc = "{{bold}}{{red}}Error {{reset}}"
else:
lc = "{{blue}}%-8s{{reset}}" % status[:7].capitalize()

lc += "%s " % start.rsplit(':', 1)[0]
lc += "%10s " % niceRunTime(delta)
lc += command
moa.ui.fprint(lc, f='jinja')

0 comments on commit 958a661

Please sign in to comment.