3535import threading
3636import time
3737import traceback
38- from typing import List
38+ from typing import List , Dict , TypedDict
3939
4040import fcp3 as fcp
4141from fcp3 import CRITICAL , ERROR , INFO , DETAIL , DEBUG # , NOISY
@@ -427,6 +427,20 @@ def fallbackLogger(self, level: int, msg: str) -> None:
427427 print (msg )
428428
429429
430+ class File (TypedDict , total = False ):
431+ mimetype : str
432+ hash : str
433+ name : str
434+ uri : str
435+ sizebytes : int
436+ state : str
437+ path : str
438+ dda : bool
439+ id : str | None
440+ target : str
441+ chkname : str
442+
443+
430444class SiteState :
431445 """
432446 Stores the current state of a single freesite's insertion, in a way
@@ -479,7 +493,8 @@ def __init__(self, **kw):
479493 self .uriPub = kw .get ('uriPub' , '' )
480494 self .uriPriv = kw .get ('uriPriv' , '' )
481495 self .updateInProgress = True
482- self .files = []
496+ self .files : List [File ] = []
497+ self .filesDict : Dict [str , File ]
483498 self .maxConcurrent = kw .get ('maxconcurrent' , defaultMaxConcurrent )
484499 self .priority = kw .get ('priority' , defaultPriority )
485500 self .basedir = kw .get ('basedir' , defaultBaseDir )
@@ -703,7 +718,7 @@ def writeVars(comment: str = "", tail: str = "", **kw):
703718 finally :
704719 self .fileLock .release ()
705720
706- def getFile (self , name : str ):
721+ def getFile (self , name : str ) -> File | None :
707722 """
708723 returns the control record for file 'name'
709724 """
@@ -1113,7 +1128,7 @@ def scan(self) -> None:
11131128 physFiles = []
11141129 physDict = {}
11151130 for f in lst :
1116- rec = {}
1131+ rec : File = {}
11171132 try :
11181133 enc = "utf-8"
11191134 f ['fullpath' ].decode (enc )
@@ -1404,7 +1419,7 @@ def allocId(self, name: str) -> str:
14041419 """
14051420 return "freesitemgr|%s|%s" % (self .name , name )
14061421
1407- def markManifestFiles (self ):
1422+ def markManifestFiles (self ) -> None :
14081423 """
14091424 Selects the files which should directly be put in the manifest and
14101425 marks them with rec['target'] = 'manifest'. All other files
@@ -1497,7 +1512,7 @@ def markManifestFiles(self):
14971512 if rec ['name' ] in fileNamesInIndex
14981513 and rec ['name' ].lower ().endswith ('.css' )])
14991514 fileNamesInManifest = set ()
1500- recByIndexAndSize = []
1515+ recByIndexAndSize : List [ File ] = []
15011516 recByIndexAndSize .extend (rec for rec in recBySize
15021517 if rec ['name' ] in fileNamesInIndexCSS )
15031518 recByIndexAndSize .extend (rec for rec in recBySize
@@ -1541,7 +1556,7 @@ def markManifestFiles(self):
15411556 rec ['target' ] = 'manifest'
15421557 totalsize += rec ['sizebytes' ]
15431558
1544- def makeManifest (self ):
1559+ def makeManifest (self ) -> None :
15451560 """
15461561 Create a site manifest insertion command buffer from our
15471562 current inventory
@@ -1564,10 +1579,10 @@ def makeManifest(self):
15641579 # add each file's entry to the command buffer
15651580 n = 0
15661581 # cache DDA requests to avoid stalling for ages on big sites
1567- hasDDAtested = {}
1582+ hasDDAtested : Dict [ str , bool ] = {}
15681583 datatoappend = []
15691584
1570- def fileMsgLines (n , rec ) :
1585+ def fileMsgLines (n : int , rec : File ) -> List [ str ] :
15711586 if (rec .get ('target' , 'separate' ) == 'separate' and
15721587 rec .get ('uri' , None )):
15731588 return [
0 commit comments