Auto remove branch builds older than 100 days
This commit is contained in:
@@ -25,8 +25,11 @@ import argparse
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
|
DOWNLOAD_DIR = "/data/www/vhosts/builder.blender.org/webroot/download/"
|
||||||
|
|
||||||
# Parse package filename to extract branch and platform
|
# Parse package filename to extract branch and platform
|
||||||
class Package:
|
class Package:
|
||||||
def __init__(self, zipname):
|
def __init__(self, zipname):
|
||||||
@@ -90,13 +93,12 @@ class Package:
|
|||||||
|
|
||||||
|
|
||||||
def get_download_dir(branch):
|
def get_download_dir(branch):
|
||||||
download_prefix = "/data/www/vhosts/builder.blender.org/webroot/download/"
|
|
||||||
if not branch or branch == 'master':
|
if not branch or branch == 'master':
|
||||||
directory = download_prefix
|
directory = DOWNLOAD_DIR
|
||||||
elif branch == 'experimental-build':
|
elif branch == 'experimental-build':
|
||||||
directory = os.path.join(download_prefix, "experimental")
|
directory = os.path.join(DOWNLOAD_DIR, "experimental")
|
||||||
else:
|
else:
|
||||||
directory = os.path.join(download_prefix, branch)
|
directory = os.path.join(DOWNLOAD_DIR, branch)
|
||||||
os.makedirs(directory, exist_ok=True)
|
os.makedirs(directory, exist_ok=True)
|
||||||
|
|
||||||
return directory
|
return directory
|
||||||
@@ -157,8 +159,9 @@ def extract_zipfile_packages(zipfile, packages, branch):
|
|||||||
sys.stderr.write('Failed to unzip package: %s\n' % str(ex))
|
sys.stderr.write('Failed to unzip package: %s\n' % str(ex))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def remove_older_packages(branch, platform, new_packages):
|
def remove_replaced_packages(branch, platform, new_packages):
|
||||||
# Remove other files from the same platform and branch
|
# Remove other files from the same platform and branch that are replaced
|
||||||
|
# by the new packages.
|
||||||
directory = get_download_dir(branch)
|
directory = get_download_dir(branch)
|
||||||
|
|
||||||
for filename in os.listdir(directory):
|
for filename in os.listdir(directory):
|
||||||
@@ -173,8 +176,28 @@ def remove_older_packages(branch, platform, new_packages):
|
|||||||
try:
|
try:
|
||||||
os.remove(os.path.join(directory, filename))
|
os.remove(os.path.join(directory, filename))
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
sys.stderr.write('Failed to remove old packages: %s\n' % str(ex))
|
sys.stderr.write('Failed to remove replaced package: %s\n' % str(ex))
|
||||||
|
|
||||||
|
def remove_old_packages():
|
||||||
|
# Remove any branch packages that are 100 days or older.
|
||||||
|
cutoff_time = time.time() - 100 * 86400
|
||||||
|
|
||||||
|
for dirname in os.listdir(DOWNLOAD_DIR):
|
||||||
|
dirpath = os.path.join(DOWNLOAD_DIR, dirname)
|
||||||
|
if not os.path.isdir(dirpath):
|
||||||
|
continue
|
||||||
|
|
||||||
|
for filename in os.listdir(dirpath):
|
||||||
|
filepath = os.path.join(dirpath, filename)
|
||||||
|
if not os.path.isfile(filepath):
|
||||||
|
continue
|
||||||
|
|
||||||
|
file_mtime = os.stat(filepath).st_mtime
|
||||||
|
if file_mtime < cutoff_time:
|
||||||
|
try:
|
||||||
|
os.remove(filepath)
|
||||||
|
except Exception as ex:
|
||||||
|
sys.stderr.write('Failed to remove old package: %s\n' % str(ex))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
@@ -186,4 +209,5 @@ if __name__ == "__main__":
|
|||||||
branch, platform = get_branch_platform(packages)
|
branch, platform = get_branch_platform(packages)
|
||||||
extract_zipfile_packages(zipfile, packages, branch)
|
extract_zipfile_packages(zipfile, packages, branch)
|
||||||
|
|
||||||
remove_older_packages(branch, platform, packages)
|
remove_replaced_packages(branch, platform, packages)
|
||||||
|
remove_old_packages()
|
||||||
|
Reference in New Issue
Block a user