<s> import os <EOL> import sys <EOL> import time <EOL> from datetime import datetime <EOL> from itertools import chain <EOL> from random import randint , shuffle <EOL> import cProfile , pstats , StringIO <EOL> from timegaps import FileSystemEntry , TimeFilter <EOL> import logging <EOL> logging . basicConfig ( <EOL> format = '<STR_LIT>' , <EOL> datefmt = '<STR_LIT>' ) <EOL> log = logging . getLogger ( ) <EOL> log . setLevel ( logging . DEBUG ) <EOL> def main ( ) : <EOL> t0 = time . time ( ) <EOL> now = time . time ( ) <EOL> fses = list ( fsegen ( ref = now , N_per_cat = <NUM_LIT:5> * <NUM_LIT:10> ** <NUM_LIT:4> , max_timecount = <NUM_LIT:9> ) ) <EOL> shuffle ( fses ) <EOL> nbr_fses = len ( fses ) <EOL> n = <NUM_LIT:8> <EOL> rules = { <EOL> "<STR_LIT>" : n , <EOL> "<STR_LIT>" : n , <EOL> "<STR_LIT>" : n , <EOL> "<STR_LIT>" : n , <EOL> "<STR_LIT>" : n , <EOL> "<STR_LIT>" : n <EOL> } <EOL> sduration = time . time ( ) - t0 <EOL> log . info ( "<STR_LIT>" , sduration ) <EOL> log . info ( "<STR_LIT>" ) <EOL> pr = cProfile . Profile ( ) <EOL> pr . enable ( ) <EOL> a , r = TimeFilter ( rules , now ) . filter ( fses ) <EOL> pr . disable ( ) <EOL> s = StringIO . StringIO ( ) <EOL> ps = pstats . Stats ( pr , stream = s ) . sort_stats ( '<STR_LIT:time>' ) <EOL> ps . print_stats ( <NUM_LIT:20> ) <EOL> print s . getvalue ( ) <EOL> class FileSystemEntryMock ( FileSystemEntry ) : <EOL> def __init__ ( self , modtime ) : <EOL> self . modtime = modtime <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ . __name__ , self . moddate ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ . __name__ , self . modtime ) <EOL> def nrandint ( n , min , max ) : <EOL> for _ in xrange ( n ) : <EOL> yield randint ( min , max ) <EOL> def fsegen ( ref , N_per_cat , max_timecount ) : <EOL> N = N_per_cat <EOL> c = max_timecount <EOL> nowminusXyears = ( ref - <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * i for i in nrandint ( N , <NUM_LIT:1> , c ) ) <EOL> nowminusXmonths = ( ref - <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT:30> * i for i in nrandint ( N , <NUM_LIT:1> , c ) ) <EOL> nowminusXweeks = ( ref - <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT:7> * i for i in nrandint ( N , <NUM_LIT:1> , c ) ) <EOL> nowminusXdays = ( ref - <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * i for i in nrandint ( N , <NUM_LIT:1> , c ) ) <EOL> nowminusXhours = ( ref - <NUM_LIT> * <NUM_LIT> * i for i in nrandint ( N , <NUM_LIT:1> , c ) ) <EOL> nowminusXseconds = ( ref - <NUM_LIT:1> * i for i in nrandint ( N , <NUM_LIT:1> , c ) ) <EOL> times = chain ( <EOL> nowminusXyears , <EOL> nowminusXmonths , <EOL> nowminusXweeks , <EOL> nowminusXdays , <EOL> nowminusXhours , <EOL> nowminusXseconds , <EOL> ) <EOL> return ( FileSystemEntryMock ( modtime = t ) for t in times ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
