def delete_deployment_if_too_old(client, deployment, max_date, dry_run):
    started_at = dateutil.parser.parse(deployment.version)
    age = now() - started_at
    if started_at < max_date:
        if dry_run is True:
            log.warning("Would delete %s for %s as it is %s old" % (deployment.id, deployment.affected_apps[0], age))
        else:
            log.warning("Deleting %s for %s as it is %s old" % (deployment.id, deployment.affected_apps[0], age))
            client.delete_deployment(deployment_id=deployment.id, force=True)
    else:
        if dry_run is True:
            log.warning("NOT deleting %s for %s as it is %s old" % (deployment.id, deployment.affected_apps[0], age))
dataset/ETHPy150Open Yelp/paasta/paasta_tools/contrib/delete_old_marathon_deployments.py/delete_deployment_if_too_old/original