#! /usr/bin/env python3 # This script is archived in https://gitlab.linphone.org/BC/Private/tools/maven_cleanup GIT repository. # Please update the script there when you make changes on this machine. import argparse import os from os.path import join, getsize import datetime import time import shutil parser = argparse.ArgumentParser(description=""" Will remove all alpha, beta and pre artefacts that are older than 1 month. Won't touch releases. """) parser.add_argument('--do-it', action='store_true', default=False, help=""" Do the actual operation. Without specifying this option, no removal will be done. """) args = parser.parse_args() do_it = args.do_it for root, dirs, files in os.walk('.'): for file in [f for f in files if f.endswith('.aar')]: if "-alpha." in file or "-beta." in file or "-pre." in file: file_path = str(root) + "/" + str(file) creation = time.ctime(os.path.getmtime(file_path)) creation_datetime = datetime.datetime.strptime(creation, "%a %b %d %H:%M:%S %Y") if creation_datetime < datetime.datetime.now() - datetime.timedelta(days=30): if do_it: shutil.rmtree(root) else: print('{0} -> {1}'.format(file_path, creation_datetime))