StudyNote--VI Python II
#<Copyright by sksc.me>
#<No one can copy and paste these codes without permission by sksc.me before 1st June 2010>
import sys
import enrol
import os
def stats(argv):
"""
This function reads command-line and display statistics about current enrolments If run with on arguments,stats will display a list of subjects,
and the total number of students and classes for each subjects.If run with –student and a student ID, it should print a list of all the classes
the specified student is enrolled in, including subject code and name, location and time .
"""
e=0
if os.getenv('ENROLDIR'):
Path=os.getenv('ENROLDIR')
TempX=len(Path)
while Path[:TempX].lower().rfind('data')!= -1 :
#This while loop is case of path with data directory nesting.For instance: C://Pathon//data//XXX//Data//
TempX=Path[:TempX].lower().rfind('data')
if os.path.isfile(Path[:TempX]+'data//SUBJECTS'):
if os.path.isfile(Path[:TempX]+'data//CLASSES'):
if os.path.isfile(Path[:TempX]+'data//VENUES'):
e=enrol.Enrol(Path[:TempX]+'data')
break
if os.path.isfile(os.getcwd()+'//data//SUBJECTS')and e==0:
# If no useful path in ENROLDIR, search current directory
e=enrol.Enrol(os.getcwd()+'//data')
elif e==0:
#If both fail,exit
print 'No Data Files Can be Found Status'
sys.exit(0)
if len(argv)==1:
#This is for command-line with no arguments
SubjectID=e.subjects()
for itemX in SubjectID :
SubjectName=e.subjectName(itemX)
ClassAmount=e.classes(itemX)
StudentAmount=0
for itemY in ClassAmount:
StudentInfo=e.classInfo(itemY)
StudentAmount=len(StudentInfo[4])+StudentAmount
print itemX, SubjectName, ' classes: '+str(len(ClassAmount)),' students:'+str(StudentAmount)
elif argv[1]=='--student' and len(argv)==3:
#This is for command-line with 2 arguments
ClassID=e.checkStudent(argv[2])
for itemX in ClassID:
ClassInfo=e.classInfo(itemX)
SubjectName=e.subjectName(ClassInfo[0])
print itemX,'('+SubjectName+')',ClassInfo[1],'in '+ClassInfo[2]
else:
print "WRONG INPUT"
stats(sys.argv)

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home