@@ -0,0 +1,977 @@
+#!/usr/bin/env python%0A# -*- encoding: utf-8 -*-%0Aimport os%0A%0Aimport time%0A%0Aimport sys%0A%0A%0Adef delete(path):%0A    print(path)%0A    try:%0A        os.unlink(path)%0A    except PermissionError as err:%0A        print(f%22Failed to delete %7Bpath%7D: %7Berr%7D%22, file=sys.stderr)%0A%0A%0Adef delete_directory_if_empty(path):%0A    try:%0A        os.rmdir(path)%0A        print(path)%0A    except OSError:%0A        # TODO check that it fails because the directory is not empty%0A        pass%0A%0A%0Adef main():%0A    now = time.time()%0A    max_age = 1 * 24 * 60 * 60%0A    for root, _, filenames in os.walk(%22/tmp%22):%0A        for f in filenames:%0A            path = os.path.join(root, f)%0A            last_access_time = os.stat(path).st_atime%0A            if now - last_access_time %3E max_age:%0A                delete(path)%0A%0A    for root, dirnames, _ in os.walk(%22/tmp%22):%0A        for directory in dirnames:%0A            path = os.path.join(root, directory)%0A            delete_directory_if_empty(path)%0A%0A%0Aif __name__ == %22__main__%22:%0A    main()%0A

Remove old files and empty directories