From 1f44238f40c07c400b3cd9f2568d54753e4cd4bc Mon Sep 17 00:00:00 2001 From: Duncan Calvert Date: Sat, 23 Nov 2024 12:59:39 -0600 Subject: [PATCH 1/3] Add Python script for listing LFS file by size. --- .tools/list-lfs-by-size.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .tools/list-lfs-by-size.py diff --git a/.tools/list-lfs-by-size.py b/.tools/list-lfs-by-size.py new file mode 100644 index 0000000..aea40a2 --- /dev/null +++ b/.tools/list-lfs-by-size.py @@ -0,0 +1,37 @@ +import re +import subprocess + +# Get the output of the git lfs ls-files -s command +def get_lfs_files(): + result = subprocess.run(['git', 'lfs', 'ls-files', '-s'], capture_output=True, text=True) + return result.stdout.strip().split('\n') + +# Convert human-readable sizes to bytes +def size_to_bytes(size_str): + size, unit = size_str.split() + size = float(size) + if unit == 'KB': + return int(size * 1024) + elif unit == 'MB': + return int(size * 1024 * 1024) + elif unit == 'GB': + return int(size * 1024 * 1024 * 1024) + return int(size) + +# Parse the LFS output and sort by size +lfs_files = get_lfs_files() +file_info = [] +for line in lfs_files: + match = re.search(r'(.*) \((.*?)\)$', line) + if match: + file_path = match.group(1) + size_str = match.group(2) + size_bytes = size_to_bytes(size_str) + file_info.append((size_bytes, file_path, size_str)) + +# Sort the files by size (largest first) +file_info.sort(key=lambda x: x[0], reverse=True) + +# Print the sorted list +for size_bytes, file_path, size_str in file_info: + print(f"{file_path} ({size_str})") From f4845e9af3e5e2d6b51523c00da311db5dcf0810 Mon Sep 17 00:00:00 2001 From: Duncan Calvert Date: Sat, 23 Nov 2024 13:06:37 -0600 Subject: [PATCH 2/3] Convert to bash. --- .tools/list-lfs-by-size.py | 37 ------------------------------------- .tools/list_lfs_by_size.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 37 deletions(-) delete mode 100644 .tools/list-lfs-by-size.py create mode 100755 .tools/list_lfs_by_size.sh diff --git a/.tools/list-lfs-by-size.py b/.tools/list-lfs-by-size.py deleted file mode 100644 index aea40a2..0000000 --- a/.tools/list-lfs-by-size.py +++ /dev/null @@ -1,37 +0,0 @@ -import re -import subprocess - -# Get the output of the git lfs ls-files -s command -def get_lfs_files(): - result = subprocess.run(['git', 'lfs', 'ls-files', '-s'], capture_output=True, text=True) - return result.stdout.strip().split('\n') - -# Convert human-readable sizes to bytes -def size_to_bytes(size_str): - size, unit = size_str.split() - size = float(size) - if unit == 'KB': - return int(size * 1024) - elif unit == 'MB': - return int(size * 1024 * 1024) - elif unit == 'GB': - return int(size * 1024 * 1024 * 1024) - return int(size) - -# Parse the LFS output and sort by size -lfs_files = get_lfs_files() -file_info = [] -for line in lfs_files: - match = re.search(r'(.*) \((.*?)\)$', line) - if match: - file_path = match.group(1) - size_str = match.group(2) - size_bytes = size_to_bytes(size_str) - file_info.append((size_bytes, file_path, size_str)) - -# Sort the files by size (largest first) -file_info.sort(key=lambda x: x[0], reverse=True) - -# Print the sorted list -for size_bytes, file_path, size_str in file_info: - print(f"{file_path} ({size_str})") diff --git a/.tools/list_lfs_by_size.sh b/.tools/list_lfs_by_size.sh new file mode 100755 index 0000000..fe13899 --- /dev/null +++ b/.tools/list_lfs_by_size.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Function to convert human-readable sizes to bytes +size_to_bytes() { + local size=$(echo $1 | cut -d' ' -f1) + local unit=$(echo $1 | cut -d' ' -f2) + size=${size%.*} # Remove decimal part + case $unit in + KB) echo $((size * 1024)) ;; + MB) echo $((size * 1024 * 1024)) ;; + GB) echo $((size * 1024 * 1024 * 1024)) ;; + *) echo $size ;; + esac +} + +# Get LFS files, convert sizes to bytes, sort, and print +git lfs ls-files -s | +while IFS= read -r line; do + if [[ $line =~ (.*)\((.*)\)$ ]]; then + file_path="${BASH_REMATCH[1]}" + size_str="${BASH_REMATCH[2]}" + size_bytes=$(size_to_bytes "$size_str") + printf "%020d|%s|%s\n" "$size_bytes" "$file_path" "$size_str" + fi +done | +sort -r | +while IFS='|' read -r size_bytes file_path size_str; do + echo "${file_path}(${size_str})" +done From e8448ecd0b8c6694744055bd9a9c05180996e267 Mon Sep 17 00:00:00 2001 From: Duncan Calvert Date: Wed, 27 Nov 2024 13:50:26 -0600 Subject: [PATCH 3/3] Fix tests. --- .github/workflows/test-tools.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-tools.yml b/.github/workflows/test-tools.yml index 9a533de..c5cc759 100644 --- a/.github/workflows/test-tools.yml +++ b/.github/workflows/test-tools.yml @@ -19,7 +19,7 @@ jobs: - name: Install deps run: apt update && apt install -y sudo wget curl openjdk-17-jdk - name: Install Gradle - run: sudo bash ./.tools/installGradle-8.11.sh + run: sudo bash ./.tools/installGradle-8.11.1.sh - name: Check Gradle run: gradle --version install-gradle-windows-test: @@ -42,7 +42,7 @@ jobs: } - name: Install Gradle shell: pwsh - run: .tools/installGradle-8.11.ps1 + run: .tools/installGradle-8.11.1.ps1 - name: Refresh environment shell: pwsh run: |