# ----------------------------------------------------------------
# This module defines metadata to be used by the batchSVN.py script.
#
# Copy this module as /class/csse/<courseName>/scripts/batchSVNData.py and 
# edit it to define the course metadata for <courseName>.  The sample data
# in the original file can be used by invoking the batchSVN.py script using
# "testing" as the course name argument, e.g.: ./batchSVN.py testing
#
# You can invoke your course-specific copy of batchSVNData.py to run
# some quick sanity tests on the data.
# ----------------------------------------------------------------

import os
import sys

# ----------------------------------------------------------------
# Hacks the system path so the import of batchSVNTypes works for testing 
# individual course meta-data on the the server.
serverPathToBatchSVN = "/class/csse/resources/Grading"
# Change the following line to point to your local checkout of the CSSE
# resources trunk if you want to test this file on your local machine:
localMachinePathToBatchSVN = "/Users/cclifton/Documents/Rose/Administrative/resources/Grading"
sys.path.append(serverPathToBatchSVN)
sys.path.append(localMachinePathToBatchSVN)
from batchSVNTypes import *
# ----------------------------------------------------------------

# ----------------------------------------------------------------
# Local variables
# ----------------------------------------------------------------
repoNamePrefix = 'csse403-201110-'
# replace the following with a description of the course, like 'CSSE 120'
courseDescription = 'CSSE 403 - Programming Language Paradigms'

# ----------------------------------------------------------------
# Defines repositories sets for this course.  Used by main script.
# ----------------------------------------------------------------
reposSets = []
# first set in the list is the default
reposSets.append(RepositorySet("Individuals", repoNamePrefix, [
    "anderswc",
    "bamberad",
    "covertcj",
    "ekltl",
    "frankmp",
    "gaot",
    "garvinml",
    "glowskst",
    "jabonsa",
    "jawaidss",
    "kehmbv",
    "kelleydj",
    "klaetsle",
    "kleinpa",
    "lesterwm",
    "lukemc",
    "lundgrpb",
    "manndj",
    "mendelnt",
    "mosttw",
    "orlowsap",
    "pientars",
    "reedec",
    "shermabj",
    "shevicna",
    "theisje",
    "vitalema",
    "watersdc",
    "wattsbn",
    "weirnc",
    "wellska1",
    "wentztj",
]))
reposSets.append(RepositorySet("Small Set for Testing", repoNamePrefix, [
    "clifton", "vargasd"
]))

# ----------------------------------------------------------------
# Defines project names and unit tests for this course. 
# Used by main script.
# ----------------------------------------------------------------
projects = []
projects.append(Project("PythonAnimation"))
projects.append(Project("PythonFunctions"))
projects.append(Project("PythonOOIntro"))
projects.append(Project("PythonObjects"))
projects.append(Project("PythonEtude"))
projects.append(Project("MS2"))
projects.append(Project("HaskellBasics"))
projects.append(Project("HaskellStyle"))
projects.append(Project("HaskellFunctions", "functions.hs"))
projects.append(Project("HaskellTrees", "basics.hs", "Trees.hs"))
projects.append(Project("HaskellFolding", "folders.hs"))
projects.append(Project("HaskellTypeClasses"))
projects.append(Project("HaskellWacky", "WackyMaps.hs"))
projects.append(Project("HaskellIO"))
projects.append(Project("HaskellBonus", "EddieEval.hs"))
projects.append(Project("GoTutorial"))
projects.append(Project("GoHaar"))
projects.append(Project("GoSudoku"))
projects.append(Project("GoSanta"))
# projects.append(Project("ErlangHomework"))
# projects.append(Project("ErlangInClass"))


# ----------------------------------------------------------------
# Defines any additional main menu commands for this course.
# Used by main script.
# ----------------------------------------------------------------
menuItems = []
# def zipForDownload(data):
#     if os.access(data.activeProject.name,os.F_OK):
#         os.system('zip -r %s.zip %s' % (data.activeProject.name,
#                                         data.activeProject.name))
#         if not os.access(data.activeProject.name + '.zip',os.F_OK):
#             print '\a\n*** Unable to create zip file ***\n'
#     return False
# menuItems.append(MenuItem('Zip local project subdirectory for download',
#                           zipForDownload))
# 
# ----------------------------------------------------------------
# A couple of extra menu items that are useful in a pinch, but aren't yet 
# sufficiently abstracted for general use.
# def copyInExtras(data):
#     forEachRepo("cp ${scriptDir}/*.java ${shortName}/src/btwp/", data)
#     return False
# menuItems.append(MenuItem('Copy in Exam2 test files',copyInExtras))
# 
# def runTestsExtraMem(data):
#     forEachRepo("cd ${shortName} && java -Xmx2000m -cp '${scriptDir}/junit-4.5.jar:bin' org.junit.runner.JUnitCore ${testClasses}", data)
#     return False
# menuItems.append(MenuItem('Run JUnit tests with extra memory',runTestsExtraMem))
# ----------------------------------------------------------------
def runTestsHaskell(data):
    # Need to execute runghc for each item in ${testClasses} INDIVIDUALLY
    # forEachRepo("cd ${shortName} && java -Xmx2000m -cp '${scriptDir}/junit-4.5.jar:bin' org.junit.runner.JUnitCore ${testClasses}", data)
    for testFile in data.activeProject.testClasses:
        print '-----------------------------------------------------------------------------'
        print '-----------------------------------------------------------------------------'
        print 'Testing:',testFile
        print '-----------------------------------------------------------------------------'
        print '-----------------------------------------------------------------------------'
        forEachRepo('cd ${shortName} && runghc ' + testFile, data)
    return False
menuItems.append(MenuItem('Test Haskell files using runghc',runTestsHaskell))

def runTestsGo(data):
    # Need to execute gotest once for each directory
    forEachRepo("cd ${shortName} && gotest", data)
    return False
menuItems.append(MenuItem('Test Go files using gotest',runTestsGo))


# ----------------------------------------------------------------
# Some test code, executed if this file is imported directly into
# a python shell.  Shouldn't need to change this when specifying
# course-specific data above.
# ----------------------------------------------------------------
if __name__ == '__main__':
    print "reposSets ==", reposSets
    print "Repositories from reposSets[0]:"
    for r in reposSets[0].repos():
        print "   ", r
    print "repository names: ", [r.name for r in reposSets]
    print
    print projects
    print "Test classes:"
    for p in projects:
        print "   %s: %s" % (p.name, p.testClasses)
    print "Additional Menu Items' Text:"
    for mi in menuItems:
        print "  ", mi.text