Skip to content

Instantly share code, notes, and snippets.

@z4yx
Created Mar 21, 2014
Embed
What would you like to do?
OOP course homework checking helper
#!/usr/bin/env python
#
# -*- coding: utf-8; -*-
import sys
import chardet
# file_handle = file(sys.argv[1])
# content = file_handle.read()
# file_handle.close()
content = sys.stdin.read()
result = chardet.detect(content)
# print(repr(result))
encoding = result['encoding']
if encoding != None and encoding != 'ascii' and encoding != 'utf-8':
print content.decode(result['encoding']).encode('utf-8')
else:
print content
#!/bin/bash
echo "Confirm?"
read
declare -a users
for u in *;do
if [ ! -d "$u" ];then
continue
fi
echo -e "\033[0;33;1mUser $u\033[0m"
users=("${users[@]}" "$u")
pushd . &>/dev/null
cd "$u"
comp_info="$PWD/__comp_info__"
>$comp_info
find . | while read i;do
if [ -d "$i" ]; then
# echo "---- $i"
if [ -f "$i/makefile" ]; then
# echo "==== make -C '$i'"
make -C "$i" >>$comp_info 2>&1
else
pushd . &>/dev/null
cd "$i"
for j in *.cpp; do
[ -e "$j" ] || continue
# echo "==== make '${j%.cpp}'"
make "${j%.cpp}" >>$comp_info 2>&1
done
popd &>/dev/null
fi
fi
done
popd &>/dev/null
cat <$comp_info
done
echo ${users[@]}
HTML="$PWD/generate.html"
cat >$HTML <<EndOfFile
<!DOCTYPE html>
<html lang="cn">
<head>
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
Generated Output
</title>
<!-- Bootstrap core CSS -->
<link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.css" rel="stylesheet">
<link href="http://cdnjs.cloudflare.com/ajax/libs/prettify/r224/prettify.css" rel="stylesheet">
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/prettify/r224/prettify.js" type="text/javascript"></script>
</head>
<body onload="prettyPrint()">
<div class="container">
<h1>偷懒的小教员--作业批改辅助工具</h1>
<div class="row">
<div class="col-md-12" role="main">
<ul class="nav nav-tabs">
EndOfFile
for u in ${users[@]};do
echo "<li><a href=\"#u_$u\" data-toggle=\"tab\">$u</a></li>" >>$HTML
done
cat >>$HTML <<EndOfFile
</ul>
<div class="tab-content">
EndOfFile
for u in ${users[@]};do
echo "<div class=\"tab-pane\" id=\"u_$u\">" >>$HTML
pushd . &>/dev/null
cd "$u"
comp_info="$PWD/__comp_info__"
declare -a files=()
while read i;do
# i=`echo "$i" | sed 's/ *$//'`
[[ "$i" == *.cpp || "$i" == *.h || "$i" == *.c || "$i" == *.txt || "$i" == *makefile* || "$i" == *Makefile* ]] || continue
files=("${files[@]}" "$i")
# echo ${files[@]}
done < <(find . )
echo ${files[@]}
echo '<hr/><ul class="nav nav-tabs">' >>$HTML
for ((j = 0; j < ${#files[@]}; j++))
do
i="${files[$j]}"
if [[ $j == 0 ]];then
active="active"
else
active=""
fi
echo "<li class=\"$active\"><a href=\"#f_${u}_$j\" data-toggle=\"tab\">$i</a></li>" >>$HTML
done
echo "<li><a href=\"#f_${u}_comp\" data-toggle=\"tab\">Compiler Info</a></li>" >>$HTML
echo '</ul>' >>$HTML
echo '<div class="tab-content">' >>$HTML
for ((j = 0; j < ${#files[@]}; j++))
do
if [[ $j == 0 ]];then
active="active"
else
active=""
fi
i="${files[$j]}"
echo "<div class=\"tab-pane $active\" id=\"f_${u}_$j\">" >>$HTML
echo ' <pre class="prettyprint linenums">' >>$HTML
conv_utf8.py <"$i"|sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g' >>$HTML
if [[ $? != 0 ]];then
exit 1
fi
echo ' </pre>' >>$HTML
echo '</div>' >>$HTML
done
echo "<div class=\"tab-pane\" id=\"f_${u}_comp\"><pre>" >>$HTML
conv_utf8.py <$comp_info|sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g' >>$HTML
echo '</pre></div>' >>$HTML
echo '</div>' >>$HTML
popd &>/dev/null
echo "</div>" >>$HTML
done
cat >>$HTML <<EndOfFile
</div>
</div>
</div>
</div>
</body>
</html>
EndOfFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment