#!/usr/bin/env python3

import os
import shutil
import sys

def files(path):
    for file in os.listdir(path):
        if os.path.isdir(os.path.join(path, file)):
            yield os.path.join(path, file)

current_build_number = int(sys.argv[1])

base = "/home/eagle0/bin/deploy/main/"

for file in os.listdir(base):
    os.chdir(base)
    if file.isnumeric() and os.path.isdir(file):
        if int(file) < current_build_number - 1:
            print('Removing old build ' + file)
            shutil.rmtree(file)
