14771477
14781478
14791479class UspImageReceiver (ImageReceiver ):
1480+ default_pfx = 'USP_unknown'
1481+
14801482 def __init__ (self , outdir ):
14811483 super ().__init__ (outdir , '.jpg' )
14821484 self .last_fname = ''
@@ -1487,14 +1489,16 @@ def re_fname(self, fname, t):
14871489 t = self .last_date
14881490 self .last_fname = fname
14891491 x = pathlib .Path (fname )
1490- return str (x .with_name (x .stem + '_' + self .strftime (t ) + x .suffix ))
1491- return fname
1492+ return x .stem + '_' + self .strftime (t ) + x .suffix
1493+ elif fname :
1494+ return str (pathlib .Path (fname ).name )
1495+ return fname or f'{ self .default_pfx } _{ self .strftime (t )} '
14921496
14931497 def generate_fid (self , fname = '' , force = 0 , t = None ):
1494- if self .current_fid .startswith ('unknown_' ) and fname :
1498+ if self .current_fid .startswith (self . default_pfx ) and fname :
14951499 self .rename_image (self .current_fid , self .re_fname (fname , t ))
14961500 elif force or not (self .current_fid and self .merge_mode ):
1497- self .current_fid = self .re_fname (fname , t ) or f'USP_unknown_ { self . strftime ( t ) } '
1501+ self .current_fid = self .re_fname (fname , t )
14981502 return self .current_fid
14991503
15001504 def push_data (self , data , t = None , ** kw ):
@@ -1511,7 +1515,12 @@ def push_data(self, data, t=None, **kw):
15111515
15121516 elif data .message == FILETRANSFER_INIT :
15131517 self .generate_fid (packet .file_name .partition ('\0 ' )[0 ], 1 , t )
1514- img = self .get_image (t = t )
1518+ try :
1519+ img = self .get_image (t = t )
1520+ except (FileNotFoundError , PermissionError ):
1521+ self .close ()
1522+ img = self .get_image (t = t )
1523+
15151524 with img .lock :
15161525 img .has_starter = 1
15171526
0 commit comments