File: //usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/archive.pyo
�
d�bc @ ss d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l j j Z d d l m
Z
d Z d Z e j
d � e j
d e j � e j
d e j � e j
d e j � e j
d
� g Z e j
d e j � Z e j
d � Z e j
d
� Z d e f d � � YZ d e f d � � YZ d e f d � � YZ d e f d � � YZ d e f d � � YZ d S( i����N( t datetime( t fileutilt historyi2 s ^VmSettings.\d+\.json$s ^(.*)\.(\d+)\.(agentsManifest)$s ^(.*)\.(\d+)\.(manifest\.xml)$s ^(.*)\.(\d+)\.(xml)$s waagent_status\.(\d+)\.json$s ^(.*)/GoalState\.(\d+)\.xml$sB ^\d{4}\-\d{2}\-\d{2}T\d{2}:\d{2}:\d{2}\.\d+(_incarnation_(\d+))?$$sF ^\d{4}\-\d{2}\-\d{2}T\d{2}:\d{2}:\d{2}\.\d+(_incarnation_(\d+))?\.zip$t StateFlusherc B sV e Z d � Z d � Z d � Z e d � � Z d � Z d � Z d � Z d � Z
RS( c C s� | | _ t j j | j t � } t j j | � s� y t j | � Wq� t k
r� } | j t j
k r� t j d | j | j
� q� q� Xn d S( Ns {0} : {1}( t _sourcet ost patht joint ARCHIVE_DIRECTORY_NAMEt existsR t mkdirt OSErrort errnot EEXISTt loggert errort strerror( t selft lib_dirt directoryt exception( ( sH /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/archive.pyt __init__= s c C sh | j � } | s d S| j | � } | d k r5 d S| j | � rW | j | | � n
| j | � d S( N( t _get_files_to_archivet _get_archive_namet Nonet _mkdirt _archivet _purge( R t filest archive_name( ( sH /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/archive.pyt flushH s c C s t j j | j t | � S( N( R R R R R ( R t name( ( sH /usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/archive.pyt history_dirV s c C s� d } d } xl | D]d } t j | � } | s4 q n t j j | � } | d k s^ | | k r | } | j � d } q q W| d k r� | d k r� t j | � j � d j
| � Sd S( s�
Gets the most recently modified GoalState.*.xml and uses that timestamp and incarnation for the archive name.
In a normal workflow, we expect there to be only one GoalState.*.xml at a time, but if the previous one
wasn't purged for whatever reason, we take the most recently modified goal state file.
If there are no GoalState.*.xml files, we return None.
i s _incarnation_{0}N( R t _GOAL_STATE_PATTERNt matchR R t getmtimet groupsR t utcfromtimestampt isoformatt format( R t latest_timestamp_mst incarnationt current_fileR"