<s> from __future__ import print_function <EOL> import subprocess <EOL> import sys <EOL> import logging <EOL> import dateutil . parser <EOL> import pytz <EOL> from datetime import datetime , timedelta <EOL> logging . basicConfig ( format = "<STR_LIT>" ) <EOL> logger = logging . getLogger ( __name__ ) <EOL> def run ( args , dry_run = False ) : <EOL> if dry_run : <EOL> print ( "<STR_LIT>" + "<STR_LIT:U+0020>" . join ( args ) ) <EOL> return "<STR_LIT>" <EOL> p = subprocess . Popen ( args , stdin = subprocess . PIPE , stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE ) <EOL> stdout , stderr = p . communicate ( ) <EOL> if p . returncode : <EOL> logger . error ( "<STR_LIT>" <EOL> % ( args [ <NUM_LIT:0> ] , stdout , stderr ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> return stdout <EOL> if run ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:-c>' , '<STR_LIT>' ] ) . strip ( ) != '<STR_LIT:f>' : <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> run ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> now = datetime . now ( tz = pytz . utc ) <EOL> with open ( '<STR_LIT>' , '<STR_LIT:w>' ) as f : <EOL> f . write ( now . isoformat ( ) ) <EOL> f . write ( "<STR_LIT:\n>" ) <EOL> backups = { } <EOL> lines = run ( [ '<STR_LIT>' , '<STR_LIT>' ] ) . split ( "<STR_LIT:\n>" ) <EOL> for line in lines [ <NUM_LIT:1> : ] : <EOL> if line : <EOL> backup_name , date , _ , _ = line . split ( ) <EOL> backups [ dateutil . parser . parse ( date ) ] = backup_name <EOL> one_month_ago = now - timedelta ( days = <NUM_LIT:30> ) <EOL> for date in sorted ( backups . keys ( ) , reverse = True ) : <EOL> if date < one_month_ago : <EOL> run ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , backups [ date ] ] ) <EOL> break </s>
