TSM磁带离线操作时间表的生成脚本

用于生成OP日常的磁带离线操作时间表:

import datetime

def isSunday(_time):
    if _time.isocalendar()[2] == 7:
        return True
    else:
        return False
    
def isFirstSundayInMonth(_time):
    if _time.timetuple()[2] <= 7 and isSunday(_time):
        return True
    else:
        return False
    
def getWeekOffset(_time):
    ret = _time.timetuple()[2] / 7 + 1
    return ret
    
def isSundayInMonthButNotFirst(_time):
    if isSunday(_time) and not isFirstSundayInMonth(_time):
        return True
    else:
        return False
    
def generateDatetime(begindate,days):
    oneday = datetime.timedelta(days=1)
    for _ in range(0,days):
        begindate += oneday
        yield begindate
        
def formatTapes(tapes):
    output = ""
    for i, tape in enumerate(tapes):
        output += str(tape)
        if i != len(tapes) - 1:
            output += ','
    return output

def generateLibraryStatus(_from, _to, _tapes):
    output = ""
    output += "From "
    output += _from
    output += " to "
    output += _to
    output += " tape "
    output += formatTapes(_tapes)
    output += " are in library."
    return output

def generatePutInAction(_from, _to, _tape):
    output  = ""
    output += "OP put tape "
    output += _tape
    output += " into library during "
    output += _from
    output += " and "
    output += _to
    output += ","
    return output

def generateGetOutAction(_from, _to, _tape):
    output  = ""
    output += "OP get tape "
    output += _tape
    output += " out of library during "
    output += _from
    output += " and "
    output += _to
    output += ","
    return output

def generateGetOutAndPutInAction(_from, _to, _tapeout,_tapein):
    output  = ""
    output += "OP get tape "
    output += _tapeout
    output += " out of library and put tape "
    output += _tapein
    output += " into library during "
    output += _from
    output += " and "
    output += _to
    output += ","
    return output

begindate = datetime.date(2014,02,20)

DAILY_TAPES = ['T_LND01_D_01', 'T_LND01_D_02']
WEEKLY_TAPES = ['T_LND01_W_01', 'T_LND01_W_02', 'T_LND01_W_03', 'T_LND01_W_04']
MONTHLY_TAPES = ['T_LND01_M_01', 'T_LND01_M_02', 'T_LND01_M_03', 
                 'T_LND01_M_04', 'T_LND01_M_05', 'T_LND01_M_06', 'T_LND01_M_07', 
                 'T_LND01_M_08', 'T_LND01_M_09', 'T_LND01_M_10', 'T_LND01_M_11', 'T_LND01_M_12']
YEARLY_TAPES = ['T_LND01_Y_01', 'T_LND01_Y_02', 'T_LND01_Y_03']
  
for _ in generateDatetime(begindate,1500):
    if isSundayInMonthButNotFirst(_) and getWeekOffset(_) != 5:
        #print getWeekOffset(_),
        print _,',',
        output = ""
        output += generateGetOutAction("06:20","06:50", DAILY_TAPES[0])
        print output,','
        #print getWeekOffset(_),
        print _,',',
        output = ""
        output += generateGetOutAndPutInAction("07:10","07:40",DAILY_TAPES[1],WEEKLY_TAPES[getWeekOffset(_) - 1])
        print output,','
        #print getWeekOffset(_),
        print _,',',
        output = ""
        output += generateGetOutAndPutInAction("14:20","14:50",WEEKLY_TAPES[getWeekOffset(_) - 1],DAILY_TAPES[0])
        print output,','
        #print getWeekOffset(_),
        print _,',',
        output = ""
        output += generatePutInAction("15:10","15:40",DAILY_TAPES[1])
        print output,','
    elif isFirstSundayInMonth(_):
        #print getWeekOffset(_),
        print _,',',
        output = ""
        output += generateGetOutAction("06:20","06:50", DAILY_TAPES[0])
        print output,','
        #print getWeekOffset(_),
        print _,',',
        output = ""
        output += generateGetOutAndPutInAction("07:10","07:40",DAILY_TAPES[1],WEEKLY_TAPES[getWeekOffset(_) - 1])
        print output,','
        #print getWeekOffset(_),
        print _,',',
        output = ""
        output += generateGetOutAndPutInAction("14:20","14:50",WEEKLY_TAPES[getWeekOffset(_) - 1],MONTHLY_TAPES[_.timetuple()[1] - 1])
        print output,','
        #print getWeekOffset(_),
        print _,',',
        output = ""
        output += generateGetOutAndPutInAction("22:20","14:50",MONTHLY_TAPES[_.timetuple()[1] - 1],DAILY_TAPES[0])
        print output,','
        #print getWeekOffset(_),
        print _,',',
        output = ""
        output += generatePutInAction("23:10","23:40",DAILY_TAPES[1])
        print output,','
    elif not isSunday(_) or (getWeekOffset(_) == 5 and isSunday(_)):
        pass

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*