《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 regels
1.1 KiB

  1. #!/usr/bin/env python
  2. import os, sys
  3. import re
  4. if len(sys.argv) < 5:
  5. print 'Usage: formatter.py <section name> <result-dir> <repo> <tid>'
  6. sys.exit()
  7. tid_regex = re.compile('([a-z0-9]+)-.*')
  8. lab_title = re.compile('=* (lab[0-9]) =*')
  9. test_entry_title = re.compile('^([\w][\w -]+)(:.*)')
  10. section = sys.argv[1]
  11. result_dir = sys.argv[2]
  12. repo = sys.argv[3]
  13. tid = sys.argv[4]
  14. m = tid_regex.match(tid)
  15. if not m:
  16. print 'Invalid tid'
  17. sys.exit()
  18. commit = m.group(1)
  19. lab = ''
  20. while True:
  21. l = sys.stdin.readline()
  22. if not l:
  23. break
  24. line = l.rstrip('\n')
  25. output = line
  26. m = test_entry_title.match(line)
  27. if m and lab:
  28. test_entry = m.group(1).lower().replace(' ', '_')
  29. test_log = os.path.join(result_dir, repo, commit, lab, test_entry + ".error")
  30. if os.path.exists(test_log):
  31. rest = m.group(2)
  32. output = '<a href="/repo/' + '/'.join([repo, commit, lab, test_entry]) + '">' + m.group(1) + '</a>' + rest
  33. m = lab_title.match(line)
  34. if m:
  35. lab = m.group(1)
  36. sys.stdout.write(output + '<br>')
  37. sys.stdout.flush()