1
0
Fork 0
mirror of https://github.com/lineageos4microg/docker-lineage-cicd synced 2024-05-07 11:36:06 +02:00

Fix old file removal

This commit is contained in:
Nicola Corna 2018-03-16 11:24:29 +01:00
parent 7e1ccbb8d3
commit 43e95e1720
2 changed files with 26 additions and 14 deletions

View File

@ -299,7 +299,7 @@ for branch in $BRANCH_NAME; do
echo ">> [$(date)] Delta generation for $codename failed" | tee -a "$DEBUG_LOG"
fi
if [ "$DELETE_OLD_DELTAS" -gt "0" ]; then
/usr/bin/python /root/clean_up.py -n $DELETE_OLD_DELTAS -V $los_ver -N 1 "$DELTA_DIR" &>> $DEBUG_LOG
/usr/bin/python /root/clean_up.py -n $DELETE_OLD_DELTAS -V $los_ver -N 1 "$DELTA_DIR/$codename" &>> $DEBUG_LOG
fi
cd "$source_dir"
else
@ -324,10 +324,18 @@ for branch in $BRANCH_NAME; do
# Remove old zips and logs
if [ "$DELETE_OLD_ZIPS" -gt "0" ]; then
/usr/bin/python /root/clean_up.py -n $DELETE_OLD_ZIPS -V $los_ver -N 1 "$ZIP_DIR"
if [ "$ZIP_SUBDIR" = true ]; then
/usr/bin/python /root/clean_up.py -n $DELETE_OLD_ZIPS -V $los_ver -N 1 "$ZIP_DIR/$zipsubdir"
else
/usr/bin/python /root/clean_up.py -n $DELETE_OLD_ZIPS -V $los_ver -N 1 -c $codename "$ZIP_DIR"
fi
fi
if [ "$DELETE_OLD_LOGS" -gt "0" ]; then
/usr/bin/python /root/clean_up.py -n $DELETE_OLD_LOGS -V $los_ver -N 1 "$LOGS_DIR"
if [ "$LOGS_SUBDIR" = true ]; then
/usr/bin/python /root/clean_up.py -n $DELETE_OLD_LOGS -V $los_ver -N 1 "$LOGS_DIR/$logsubdir"
else
/usr/bin/python /root/clean_up.py -n $DELETE_OLD_LOGS -V $los_ver -N 1 -c $codename "$LOGS_DIR"
fi
fi
if [ -f /root/userscripts/post-build.sh ]; then
echo ">> [$(date)] Running post-build.sh for $codename" >> "$DEBUG_LOG"

View File

@ -26,7 +26,8 @@ from argparse import ArgumentParser
ROM_NAME = "lineage"
def clean_path(path, builds_to_keep, current_version, old_builds_to_keep):
def clean_path(path, builds_to_keep, current_version, old_builds_to_keep,
current_codename):
files = []
scandir = path[:-1] if path[-1] == "/" else path
@ -61,17 +62,18 @@ def clean_path(path, builds_to_keep, current_version, old_builds_to_keep):
build_list.sort(key=lambda b: b[0])
n_builds = len(build_list)
if current_version:
if current_version == build_hash[0]:
keep_num = builds_to_keep
if not current_codename or build_hash[1] == current_codename:
if current_version:
if current_version == build_hash[0]:
keep_num = builds_to_keep
else:
keep_num = old_builds_to_keep
else:
keep_num = old_builds_to_keep
else:
keep_num = builds_to_keep
keep_num = builds_to_keep
if n_builds > keep_num:
for b in build_list[0:n_builds-keep_num]:
list(map(remove, b[1]))
if n_builds > keep_num:
for b in build_list[0:n_builds-keep_num]:
list(map(remove, b[1]))
def main():
@ -87,9 +89,11 @@ def main():
parser.add_argument('-N', metavar='N_BUILDS_OLD', type=int, nargs='?',
default=1, help='select the number of builds to keep '
'when not of the specified version')
parser.add_argument('-c', metavar='CODENAME', type=str, nargs='?',
help='clean only CODENAME zips')
args = parser.parse_args()
for path in args.paths:
clean_path(path, args.n, args.V, args.N)
clean_path(path, args.n, args.V, args.N, args.c)
if __name__ == "__main__":