PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/website/setup.py

http://github.com/aichallenge/aichallenge
Python | 47 lines | 36 code | 10 blank | 1 comment | 11 complexity | ca625b484b22b6feac470791745f413b MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
  1. #!/usr/bin/env python
  2. import glob
  3. import re
  4. import os
  5. def replaceMarkdown():
  6. competition="Ants"
  7. seewikiregex=re.compile(r'(<!--<MarkdownReplacement with="([^\n>]*.md)">-->.*?<!--</MarkdownReplacement>-->)',re.DOTALL)
  8. markdownlocation = "aichallenge.wiki/"
  9. for page in glob.iglob("*.php"):
  10. try:
  11. pagecontent=open(page,"r").read()
  12. matches=(match.groups() for match in seewikiregex.finditer(pagecontent))
  13. for toreplace, markdownfilename in matches:
  14. realmarkdownfilename=markdownfilename.replace("competition",competition)
  15. print "Inserting `%s` into `%s`, where `%s...` was." % (realmarkdownfilename,page,toreplace[:90])
  16. compiledmarkdown=os.popen("python md.py %s" % markdownlocation+realmarkdownfilename).read()
  17. compiledmarkdown='<!--<MarkdownReplacement with="%s">-->%s<!--</MarkdownReplacement>-->' % (markdownfilename,compiledmarkdown)
  18. pagecontent=pagecontent.replace(toreplace,compiledmarkdown)
  19. open(page,"w").write(pagecontent)
  20. except IOError:
  21. print "Ignoring `%s` because of errors" % (page)
  22. def concatCSS():
  23. css_order = ['font.css', 'reset.css', 'layout.css'] # these files go first
  24. with open('aichallenge.css', 'w') as f:
  25. css_files = css_order + list(set(os.listdir('css')) - set(css_order))
  26. for filename in css_files:
  27. print "Concatenating `%s` to the main css." % (filename)
  28. if filename.endswith('.css'):
  29. with open(os.path.join('css', filename), 'r') as fin:
  30. f.write('\n/* begin %s %s */\n' % (filename, '='*(70-len(filename))))
  31. f.write(fin.read())
  32. f.write('\n/* end %s %s */\n' % (filename, '='*(72-len(filename))))
  33. def setup():
  34. concatCSS()
  35. replaceMarkdown()
  36. if __name__=="__main__":
  37. setup()