U #g@s@ddlmZmZddlmZddlZGdddeZddZdS))existsgetsize)datetimeNc@s6eZdZdZd ddZddZddZeZd d ZdS) LCUsefullnesszK!Determines if loop current files are still usable for a cycle of interest.NcCsL||_||_||_||_|dkr*td}d|_d|_d|_d|_d|_ dS)z!Creates a new LCUsefullness object @param startdate the cycle of interest as a string, format YYYYMMDDHH @param lfile,rfile the loop current l and r files @param logger a logging.Logger for log messages.Npom) startdatelfilerfileloggerlogging getLoggerresultreasonerrorsuccess)selfrrr r r?/lfs/h1/ops/prod/packages/hwrf.v13.2.9/ush/pom/check_lcfiles.py__init__s zLCUsefullness.__init__cCs:|jdkrdS|jr|jS|jr0d|j|jfS|jSdS)NNonez%s %s )r rrrrrrr__str__)s zLCUsefullness.__str__cCs|jdkr||jS)N)r runrrrr__bool__3s zLCUsefullness.__bool__c Csn|j}|j}|j}|j}t|rRt|dkrRt|rRt|dkrR|d||fztt|}WnTt k r}z6d||_ d||_ | |j | |j d|_ W5d}~XYnXztt|}WnVt k r&}z6d||_ d||_ | |j | |j d|_ W5d}~XYnX||kr0t |tr|}zBtt|ddt|ddt|ddt|dd } WnVt k r}z6d ||_ d||_ | |j | |j d|_ W5d}~XYnXt|}zBtt|ddt|ddt|ddt|dd } WnZt k r}z:d t||_ d ||_ | |j | |j d|_ W5d}~XYnX| | j} | dkr| d krd| |f|_ d||f|_||j ||jd|_ n2d| |f|_ ||j |d||fd|_ nd|f|_ | |j d|_ n d||f|_ | |j d|_ n| d||fd|_ dS)NrzLC: %s and %s existsz%datestamp can not be accessed from %sz Error: %sF zInvalid startdate format %sz!Invalid LC datestamp format in %sz Error: %s Zz+LC files are created by %i days ago from %sz+%s and %s files can be used for sharpeningTz.%s and %s are OLD and Not using for sharpeningz(Invalid startdate(in Isthis_LCuseful) %sz$Datestamps in %s and %s do not matchz%s %s files do not exist)rrr r rrinfoint get_endline ValueErrorrrr isinstancestrrdaysrwarn) rrrr r ZldateeZrdateymdht1t2r%rrrr8s           B    B          zLCUsefullness.run)N) __name__ __module__ __qualname____doc__rrrZ __nonzero__rrrrrrs   rc Cs4t|}|}W5QRX|t|dS)zU!Read the last line of the given file and return it. @param file the file to read)openreadsplitlen)filefiddatarrrr!|s r!)os.pathrrrr objectrr!rrrrs g