def run(self): while self.par.work_available() and self.keep_working: job = self.par.__get_work__() userTree = BTree() # itemCount = 0 uuid = job["_id"] # day_count = job["day_count"] days = job["daily_sessions"] day_index = 0 for day in days: day_index += 1 #print "adding sessions for {0} for day {1}/{2}".format(uuid, day_index, day_count) sessions = day day_items = [] for session in sessions: host = session["Domain"] duration = parse_timespan( session["Duration"]).total_seconds() day_items.append({'time': duration, 'label': host}) userTree.build(day_items) #print "added daily sessions for {0}".format(uuid) self.par.push_result(userTree, uuid) print("Worker stopping because no work is available") self.is_working = False
def check(self, arg): """ Assumes the argument is a time span. @param arg: the timespan @type arg: string @returns: the number of seconds in the timespan @rtype: int @raise ParserException: if the timespan is invalid """ try: time = utils.parse_timespan(arg) return time except: raise ParserException, "Invalid timespan specified %s" % (arg,)
def check(self, arg): """ Assumes the argument is a time span. @param arg: the timespan @type arg: string @returns: the number of seconds in the timespan @rtype: int @raise ParserException: if the timespan is invalid """ try: time = utils.parse_timespan(arg) return time except: raise ParserException, "Invalid timespan specified %s" % (arg, )
text = "This is some text \33[1;37mwith some\33[0m ansi formatting in it to see if we can handle wrapping with it \33[1;37mtoo.\33[0m" _pass_fail("wrap_text 8 (with ansi)", wrap_text(text), """This is some text \33[1;37mwith some\33[0m ansi formatting in it to see if we can handle wrapping with it \33[1;37mtoo.\33[0m""") _pass_fail("wrap_text 9 (with ansi)", wrap_text(text, indent=5), """This is some text \33[1;37mwith some\33[0m ansi formatting in it to see if we can handle wrapping with it \33[1;37mtoo.\33[0m""") print from utils import parse_timespan _pass_fail("parse_timespan 1", parse_timespan("1h"), 3600) _pass_fail("parse_timespan 2", parse_timespan("1m"), 60) _pass_fail("parse_timespan 3", parse_timespan("1s"), 1) _pass_fail("parse_timespan 4", parse_timespan("1h2m3s"), 3723) _pass_fail("parse_timespan 5", parse_timespan("17"), 17) _pass_fail("parse_timespan 6", parse_timespan("5h"), 3600 * 5) print # FIXME - these always fail because we don't get the precision right. # not sure what to do about that. from utils import parse_time _pass_fail("parse_time 1", int(parse_time("4:20p")), 1029878400) _pass_fail("parse_time 2", int(parse_time("4m")), 1029796956) _pass_fail("parse_time 3", int(parse_time("9")), 1029796725) _pass_fail("parse_time 4", int(parse_time("1:17:34a")), 1029824254)
text = "This is some text \33[1;37mwith some\33[0m ansi formatting in it to see if we can handle wrapping with it \33[1;37mtoo.\33[0m" _pass_fail( "wrap_text 8 (with ansi)", wrap_text(text), """This is some text \33[1;37mwith some\33[0m ansi formatting in it to see if we can handle wrapping with it \33[1;37mtoo.\33[0m""") _pass_fail( "wrap_text 9 (with ansi)", wrap_text(text, indent=5), """This is some text \33[1;37mwith some\33[0m ansi formatting in it to see if we can handle wrapping with it \33[1;37mtoo.\33[0m""") print from utils import parse_timespan _pass_fail("parse_timespan 1", parse_timespan("1h"), 3600) _pass_fail("parse_timespan 2", parse_timespan("1m"), 60) _pass_fail("parse_timespan 3", parse_timespan("1s"), 1) _pass_fail("parse_timespan 4", parse_timespan("1h2m3s"), 3723) _pass_fail("parse_timespan 5", parse_timespan("17"), 17) _pass_fail("parse_timespan 6", parse_timespan("5h"), 3600 * 5) print # FIXME - these always fail because we don't get the precision right. # not sure what to do about that. from utils import parse_time _pass_fail("parse_time 1", int(parse_time("4:20p")), 1029878400) _pass_fail("parse_time 2", int(parse_time("4m")), 1029796956) _pass_fail("parse_time 3", int(parse_time("9")), 1029796725) _pass_fail("parse_time 4", int(parse_time("1:17:34a")), 1029824254)