1616import csv
1717import logging
1818import os
19+ import subprocess
20+ from pathlib import Path
1921from typing import TypedDict , List , Dict
2022
2123from gtfs import stop_txt_is_lat_log_required
@@ -39,6 +41,40 @@ class ShapeTrips(TypedDict):
3941 trip_ids : List [str ]
4042
4143
44+ def get_volume_size (mountpoint : str ):
45+ """
46+ Returns the total size of the specified filesystem mount point in a human-readable format.
47+
48+ This function uses the `df` command-line utility to determine the size of the filesystem
49+ mounted at the path specified by `mountpoint`. If the mount point does not exist, the function
50+ prints an error message to the standard error and returns "N/A".
51+
52+ Parameters:
53+ mountpoint: str
54+ The filesystem mount point path to check.
55+
56+ Returns:
57+ str
58+ The total size of the specified filesystem mount point in human-readable format. If the
59+ mount point is not found, returns "N/A".
60+ """
61+ mp = Path (mountpoint )
62+ if not mp .exists ():
63+ logging .warning ("Mountpoint not found: %s" , mountpoint )
64+ return "N/A"
65+ cmd = [
66+ "bash" ,
67+ "-c" ,
68+ "df -h \" $1\" | awk 'NR==2 {print $2}'" ,
69+ "_" , # $0 placeholder (ignored)
70+ str (mp ), # $1
71+ ]
72+ result = subprocess .run (cmd , capture_output = True , text = True , check = True )
73+ size = result .stdout .strip ()
74+
75+ return size
76+
77+
4278class CsvCache :
4379 """
4480 CsvCache provides cached access to GTFS CSV files in a specified working directory.
@@ -68,6 +104,7 @@ def __init__(
68104 self .trips_no_shapes_per_route : Dict [str , List [str ]] = {}
69105
70106 self .logger .info ("Using work directory: %s" , self .workdir )
107+ self .logger .info ("Size of workdir: %s" , get_volume_size (self .workdir ))
71108
72109 def debug_log_size (self , label : str , obj : object ) -> None :
73110 """Log the deep size of an object in bytes when DEBUG is enabled."""
0 commit comments