11import logging
22
3- from django .core .management .base import BaseCommand
43from django .core .management .base import CommandParser
54
65from stac_api .models .collection import CollectionAsset
76from stac_api .models .item import Asset
87from stac_api .utils import CommandHandler
9-
10- logger = logging .getLogger (__name__ )
8+ from stac_api .utils import CustomBaseCommand
119
1210# increase the log level so boto3 doesn't spam the output
1311logging .getLogger ('boto3' ).setLevel (logging .WARNING )
1715class Handler (CommandHandler ):
1816
1917 def update (self ):
20- self .print_success ('Running command to update file size' )
18+ self .print ('Running command to update file size' )
2119
2220 asset_limit = self .options ['count' ]
2321
2422 asset_qs = Asset .objects .filter (file_size = 0 , is_external = False )
2523 total_asset_count = asset_qs .count ()
2624 assets = asset_qs .all ()[:asset_limit ]
2725
28- self .print_success (f'Update file size for { len (assets )} assets out of { total_asset_count } ' )
26+ self .print (f'Update file size for { len (assets )} assets out of { total_asset_count } ' )
2927
3028 for asset in assets :
3129 try :
@@ -45,14 +43,13 @@ def update(self):
4543 asset .file_size = None
4644 asset .save ()
4745 print ("_" , end = "" , flush = True )
48- logger .error ('file %s could not be found' , asset .file )
49- print ()
46+ self .print_error ('file %s could not be found' , asset .file )
5047
5148 collection_asset_qs = CollectionAsset .objects .filter (file_size = 0 )
5249 total_asset_count = collection_asset_qs .count ()
5350 collection_assets = collection_asset_qs .all ()[:asset_limit ]
5451
55- self .print_success (
52+ self .print (
5653 f"Update file size for { len (collection_assets )} collection assets out of "
5754 f"{ total_asset_count } "
5855 )
@@ -73,14 +70,12 @@ def update(self):
7370 # bucket.
7471 collection_asset .file_size = None
7572 collection_asset .save ()
76- print ("_" , end = "" , flush = True )
77- logger .error ('file %s could not be found' , collection_asset .file )
73+ self .print_error ('file %s could not be found' , collection_asset .file )
7874
79- print ()
8075 self .print_success ('Update completed' )
8176
8277
83- class Command (BaseCommand ):
78+ class Command (CustomBaseCommand ):
8479 help = """Requests the file size of every asset / collection asset from the s3 bucket and
8580 updates the value in the database"""
8681
0 commit comments