Skip to content

Commit

Permalink
Merge pull request #215 from NMD03/master
Browse files Browse the repository at this point in the history
Add [ailbuilder] cleanup
  • Loading branch information
Terrtia committed Mar 7, 2024
2 parents 38d71e9 + 2b9c1bf commit d2c9745
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions other_installers/LXD/build/ailbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
import re
import os
import shutil
from time import sleep
from typing import List, Optional
from pathlib import Path
Expand Down Expand Up @@ -70,6 +71,14 @@ def build(self) -> None:
except Exception as e:
print(f"Failed to run {cmd} for {self.id}: {e}")

def cleanup(self, num_to_keep: int) -> None:
files = os.listdir(self.outputdir)
repo_images = [f for f in files if f.startswith(self.name)]
if len(repo_images) > num_to_keep:
repo_images.sort(key=lambda x: os.path.getmtime(os.path.join(self.outputdir, x)))
for image in repo_images[:-num_to_keep]:
shutil.rmtree(os.path.join(self.outputdir, image))

class GitHub(Repo):
"""Class for tracking GitHub repositories."""

Expand Down Expand Up @@ -126,8 +135,10 @@ def main():
while True:
for repo in repos:
repo.build()
repo.cleanup(num_to_keep=3)
for package in aptpkg:
package.build()
repo.cleanup(num_to_keep=3)
sleep(config["check_interval"])

if __name__ == "__main__":
Expand Down

0 comments on commit d2c9745

Please sign in to comment.