本文整理汇总了Python中shinken.util.get_day函数的典型用法代码示例。如果您正苦于以下问题:Python get_day函数的具体用法?Python get_day怎么用?Python get_day使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_day函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_next_valid_day
def get_next_valid_day(self, t):
if self.get_next_future_timerange_valid(t) is None:
# this day is finish, we check for next period
(start_time, end_time) = self.get_start_and_end_time(get_day(t)+86400)
else:
(start_time, end_time) = self.get_start_and_end_time(t)
if t <= start_time:
return get_day(start_time)
if self.is_time_day_valid(t):
return get_day(t)
return None
示例2: get_next_valid_time_from_t
def get_next_valid_time_from_t(self, t):
#print "\tDR Get next valid from:", time.asctime(time.localtime(t))
#print "DR Get next valid from:", t
if self.is_time_valid(t):
return t
#print "DR Get next valid from:", time.asctime(time.localtime(t))
# First we search fot the day of t
t_day = self.get_next_valid_day(t)
#print "DR: T next valid day", time.asctime(time.localtime(t_day))
# We search for the min of all tr.start > sec_from_morning
# if it's the next day, use a start of the day search for timerange
if t < t_day:
sec_from_morning = self.get_next_future_timerange_valid(t_day)
else: # t is in this day, so look from t (can be in the evening or so)
sec_from_morning = self.get_next_future_timerange_valid(t)
#print "DR: sec from morning", sec_from_morning
if sec_from_morning is not None:
if t_day is not None and sec_from_morning is not None:
return t_day + sec_from_morning
# Then we search for the next day of t
# The sec will be the min of the day
t = get_day(t) + 86400
t_day2 = self.get_next_valid_day(t)
sec_from_morning = self.get_next_future_timerange_valid(t_day2)
if t_day2 is not None and sec_from_morning is not None:
return t_day2 + sec_from_morning
else:
# I'm not find any valid time
return None
示例3: check_and_do_archive
def check_and_do_archive(self, first_pass = False):
now = int(time.time())
#first check if the file last mod (or creation) was
#not our day
try :
t_last_mod = int(float(str(os.path.getmtime(self.path))))
except OSError: #there should be no path from now, so no move :)
return False
#print "Ctime %d" % os.path.getctime(self.path)
t_last_mod_day = get_day(t_last_mod)
today = get_day(now)
# Will be saved with the date of yesterday because all elemetns arefrom yesterday
yesterday = get_day(now-3600)
#print "Dates: t_last_mod : %d, t_last_mod_day: %d, today : %d" % (t_last_mod, t_last_mod_day, today)
if t_last_mod_day != today:
logger.log("We are archiving the old log file")
#For the first pass, it's not already open
if not first_pass:
self.file.close()
#Now we move it
#Get a new name like MM
#f_name is like nagios.log
f_name = os.path.basename(self.path)
#remove the ext -> (nagios,.log)
(f_base_name, ext) = os.path.splitext(f_name)
#make the good looking day for archive name
#like -05-09-2010-00
d = datetime.datetime.fromtimestamp(yesterday)
s_day = d.strftime("-%m-%d-%Y-00")
archive_name = f_base_name+s_day+ext
file_archive_path = os.path.join(self.archive_path, archive_name)
logger.log("Moving the old log file from %s to %s" % (self.path, file_archive_path))
shutil.move(self.path, file_archive_path)
#and we overwrite it
print "I open the log file %s" % self.path
self.file = open(self.path,'a')
return True
return False
示例4: get_next_invalid_day
def get_next_invalid_day(self, t):
# print "Look in", self.__dict__
# print 'DR: get_next_invalid_day for', time.asctime(time.localtime(t))
if self.is_time_day_invalid(t):
# print "EARLY RETURN"
return t
next_future_timerange_invalid = self.get_next_future_timerange_invalid(t)
# print "next_future_timerange_invalid:", next_future_timerange_invalid
# If today there is no more unavailable timerange, search the next day
if next_future_timerange_invalid is None:
# print 'DR: get_next_future_timerange_invalid is None'
# this day is finish, we check for next period
(start_time, end_time) = self.get_start_and_end_time(get_day(t))
else:
# print 'DR: get_next_future_timerange_invalid is',
# print time.asctime(time.localtime(next_future_timerange_invalid))
(start_time, end_time) = self.get_start_and_end_time(t)
# (start_time, end_time) = self.get_start_and_end_time(t)
# print "START", time.asctime(time.localtime(start_time)),
# print "END", time.asctime(time.localtime(end_time))
# The next invalid day can be t day if there a possible
# invalid time range (timerange is not 00->24
if next_future_timerange_invalid is not None:
if start_time <= t <= end_time:
# print "Early Return next invalid day:", time.asctime(time.localtime(get_day(t)))
return get_day(t)
if start_time >= t:
# print "start_time >= t:", time.asctime(time.localtime(get_day(start_time)))
return get_day(start_time)
else:
# Else, there is no possibility than in our start_time<->end_time we got
# any invalid time (full period out). So it's end_time+1 sec (tomorrow of end_time)
return get_day(end_time + 1)
return None
示例5: get_next_invalid_day
def get_next_invalid_day(self, t):
#print 'DR: get_next_invalid_day for', time.asctime(time.localtime(t))
if self.is_time_day_invalid(t):
return t
next_future_timerange_invalid = self.get_next_future_timerange_invalid(t)
#print "next_future_timerange_invalid:", next_future_timerange_invalid
#If today there is no more unavalable timerange, search the next day
if next_future_timerange_invalid is None:
#print 'DR: get_next_future_timerange_invalid is None'
#this day is finish, we check for next period
(start_time, end_time) = self.get_start_and_end_time(get_day(t)+86400)
else:
#print 'DR: get_next_future_timerange_invalid is', time.asctime(time.localtime(next_future_timerange_invalid))
(start_time, end_time) = self.get_start_and_end_time(t)
#res = get_day(t) + next_future_timerange_invalid
#print "Early return"
#return res
#print 'DR:Start:', time.asctime(time.localtime(start_time))
#print 'DR:End:', time.asctime(time.localtime(end_time))
#The next invalid day can be t day if there a possible
#invalid time range (timerange is not 00->24
if next_future_timerange_invalid is not None:
if start_time <= t <= end_time:
#print "Early Return next invalid day:", time.asctime(time.localtime(get_day(t)))
return get_day(t)
if start_time >= t :
return get_day(start_time)
else:#Else, there is no possibility than in our start_time<->end_time we got
#any invalid time (full period out). So it's end_time+1 sec (tomorow of end_time)
#print "Full period out, got end_time", time.asctime(time.localtime(get_day(end_time +1)))
return get_day(end_time +1)
return None
示例6: get_next_invalid_time_from_t
def get_next_invalid_time_from_t(self, t):
#print 'DR:get_next_invalid_time_from_t', time.asctime(time.localtime(t))
if not self.is_time_valid(t):
#print "DR: cool, t is invalid", time.asctime(time.localtime(t))
return t
#else:
# print "DR: Arg, t is valid", time.asctime(time.localtime(t))
#First we search fot the day of t
t_day = self.get_next_invalid_day(t)
#print "Get next invalid day:", time.asctime(time.localtime(t_day))
#print "Is valid day?", self.is_time_valid(t_day)
#We search for the min of all tr.start > sec_from_morning
#starts = []
#for tr in self.timeranges:
# tr_start = tr.hstart * 3600 + tr.mstart * 3600
# if tr_start >= sec_from_morning:
# starts.append(tr_start)
#tr can't be valid, or it will be return at the begining
sec_from_morning = self.get_next_future_timerange_invalid(t)
#print "TOTO sec_from_morning:", sec_from_morning
#Ok we've got a next invalid day and a invalid possibility in
#timerange, so the next invalid is this day+sec_from_morning
#print "T_day", t_day, "Sec from morning", sec_from_morning
if t_day is not None and sec_from_morning is not None:
return t_day + sec_from_morning + 1
#We've got a day but no sec_from_morning : the timerange is full (0->24h)
#so the next invalid is this day at the day_start
if t_day is not None and sec_from_morning is None:
return t_day
#Then we search for the next day of t
#The sec will be the min of the day
t = get_day(t)+86400
t_day2 = self.get_next_invalid_day(t)
sec_from_morning = self.get_next_future_timerange_invalid(t_day2)
if t_day2 is not None and sec_from_morning is not None:
return t_day2 + sec_from_morning + 1
if t_day2 is not None and sec_from_morning is None:
return t_day2
else:
#I'm not find any valid time
return None
示例7: get_next_invalid_time_from_t
def get_next_invalid_time_from_t(self, t):
if not self.is_time_valid(t):
return t
# First we search fot the day of t
t_day = self.get_next_invalid_day(t)
#print "FUCK NEXT DAY", time.asctime(time.localtime(t_day))
# We search for the min of all tr.start > sec_from_morning
# if it's the next day, use a start of the day search for timerange
if t < t_day:
sec_from_morning = self.get_next_future_timerange_invalid(t_day)
else: # t is in this day, so look from t (can be in the evening or so)
sec_from_morning = self.get_next_future_timerange_invalid(t)
#print "DR: sec from morning", sec_from_morning
# tr can't be valid, or it will be return at the beginning
#sec_from_morning = self.get_next_future_timerange_invalid(t)
# Ok we've got a next invalid day and a invalid possibility in
# timerange, so the next invalid is this day+sec_from_morning
#print "T_day", t_day, "Sec from morning", sec_from_morning
if t_day is not None and sec_from_morning is not None:
return t_day + sec_from_morning + 1
# We've got a day but no sec_from_morning: the timerange is full (0->24h)
# so the next invalid is this day at the day_start
if t_day is not None and sec_from_morning is None:
return t_day
# Then we search for the next day of t
# The sec will be the min of the day
t = get_day(t) + 86400
t_day2 = self.get_next_invalid_day(t)
sec_from_morning = self.get_next_future_timerange_invalid(t_day2)
if t_day2 is not None and sec_from_morning is not None:
return t_day2 + sec_from_morning + 1
if t_day2 is not None and sec_from_morning is None:
return t_day2
else:
# I'm not find any valid time
return None
示例8: get_next_valid_time_from_t
def get_next_valid_time_from_t(self, t):
#print "DR Get next valid from:", time.asctime(time.localtime(t))
#print "DR Get next valid from:", t
if self.is_time_valid(t):
return t
#print "DR Get next valid from:", time.asctime(time.localtime(t))
#First we search fot the day of t
t_day = self.get_next_valid_day(t)
sec_from_morning = self.get_min_sec_from_morning()
#print "Search for t", time.asctime(time.localtime(t))
#print "DR: next day", time.asctime(time.localtime(t_day))
#print "DR: sec from morning", time.asctime(time.localtime(sec_from_morning))
#We search for the min of all tr.start > sec_from_morning
starts = []
for tr in self.timeranges:
tr_start = tr.hstart * 3600 + tr.mstart * 3600
if tr_start >= sec_from_morning:
starts.append(tr_start)
#tr can't be valid, or it will be return at the begining
sec_from_morning = self.get_next_future_timerange_valid(t)
#print "DR: sec from morning", time.asctime(time.localtime(sec_from_morning))
#print "Sec from morning", t_day
if sec_from_morning is not None:
if t_day is not None and sec_from_morning is not None:
return t_day + sec_from_morning
#Then we search for the next day of t
#The sec will be the min of the day
t = get_day(t)+86400
t_day2 = self.get_next_valid_day(t)
sec_from_morning = self.get_next_future_timerange_valid(t_day2)
if t_day2 is not None and sec_from_morning is not None:
return t_day2 + sec_from_morning
else:
#I'm not find any valid time
return None
示例9: get_min_from_t
def get_min_from_t(self, t):
if self.is_time_valid(t):
return t
t_day_epoch = get_day(t)
tr_mins = self.get_min_sec_from_morning()
return t_day_epoch + tr_mins