Skip .git dir

This commit is contained in:
Tom Willemsen 2011-11-05 03:50:48 +01:00
parent 0e14ef7f7c
commit 528737be80

View file

@ -5,37 +5,40 @@ from django.core.management.base import BaseCommand, CommandError
from settings import MARKDOWN_PATH, DEPLOY_PATH from settings import MARKDOWN_PATH, DEPLOY_PATH
ignore_dir = '.git'
class Command(BaseCommand): class Command(BaseCommand):
help = 'Parse markdown files in %s' % MARKDOWN_PATH help = 'Parse markdown files in %s' % MARKDOWN_PATH
def handle(self, *args, **options): def handle(self, *args, **options):
for root, dirs, files in os.walk(MARKDOWN_PATH): for root, dirs, files in os.walk(MARKDOWN_PATH):
for file in files: if ignore_dir not in root:
subdir = root.replace(MARKDOWN_PATH, "") for file in files:
mdfile = '%s/%s' % (root, file) subdir = root.replace(MARKDOWN_PATH, "")
mdtuple = os.path.splitext(file) mdfile = '%s/%s' % (root, file)
mdname = '%s/%s' % (subdir, mdtuple[0]) mdtuple = os.path.splitext(file)
htmlpath = '%s/templates/html_pages/%s' % (DEPLOY_PATH, mdname) mdname = '%s/%s' % (subdir, mdtuple[0])
htmlfile = '%s/index.html' % htmlpath htmlpath = '%s/templates/html_pages/%s' % (DEPLOY_PATH, mdname)
htmlfile = '%s/index.html' % htmlpath
if options['verbosity'] == '3': if options['verbosity'] == '3':
print 'Subdir: ', subdir print 'Subdir: ', subdir
print 'Mdfile: ', mdfile print 'Mdfile: ', mdfile
print 'Mdtuple: ', mdtuple print 'Mdtuple: ', mdtuple
print 'Htmlpath: ', htmlpath print 'Htmlpath: ', htmlpath
print 'Htmlfile: ', htmlfile print 'Htmlfile: ', htmlfile
if mdtuple[1] == '.mdwn' and os.path.exists(mdfile) \ if mdtuple[1] == '.mdwn' and os.path.exists(mdfile) \
and (not os.path.exists(htmlfile) \ and (not os.path.exists(htmlfile) \
or os.path.getmtime(mdfile) > os.path.getmtime(htmlfile)): or os.path.getmtime(mdfile) > os.path.getmtime(htmlfile)):
if not os.path.exists(htmlpath): if not os.path.exists(htmlpath):
os.makedirs(htmlpath) os.makedirs(htmlpath)
md = markdown.Markdown() md = markdown.Markdown()
print 'Converting ', mdname, '-->', htmlfile, print 'Converting ', mdname, '-->', htmlfile,
wikiExtension = 'wikilinks(base_url=%s/)' % subdir wikiExtension = 'wikilinks(base_url=%s/)' % subdir
markdown.markdownFromFile(input=mdfile, output=htmlfile, encoding="utf-8", markdown.markdownFromFile(input=mdfile, output=htmlfile, encoding="utf-8",
extensions=[wikiExtension]) extensions=[wikiExtension])
print ' ... succeeded' print ' ... succeeded'