@ -127,10 +127,10 @@ class Uploader(): 
			
		
	
		
		
			
				
					
					      url_resp_json  =  json . loads ( url_resp . text )        url_resp_json  =  json . loads ( url_resp . text )   
			
		
	
		
		
			
				
					
					      url  =  url_resp_json [ ' url ' ]        url  =  url_resp_json [ ' url ' ]   
			
		
	
		
		
			
				
					
					      headers  =  url_resp_json [ ' headers ' ]        headers  =  url_resp_json [ ' headers ' ]   
			
		
	
		
		
			
				
					
					      cloudlog . info ( " upload_url v1.3  %s   %s " ,  url ,  str ( headers ) )        cloudlog . debug ( " upload_url v1.3  %s   %s " ,  url ,  str ( headers ) )   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					      if  fake_upload :        if  fake_upload :   
			
		
	
		
		
			
				
					
					        cloudlog . info ( " *** WARNING, THIS IS A FAKE UPLOAD TO  %s  *** "  %  url )          cloudlog . debug ( " *** WARNING, THIS IS A FAKE UPLOAD TO  %s  *** "  %  url )   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        class  FakeResponse ( ) :          class  FakeResponse ( ) :   
			
		
	
		
		
			
				
					
					          def  __init__ ( self ) :            def  __init__ ( self ) :   
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -164,7 +164,7 @@ class Uploader(): 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    cloudlog . event ( " upload " ,  key = key ,  fn = fn ,  sz = sz )      cloudlog . event ( " upload " ,  key = key ,  fn = fn ,  sz = sz )   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    cloudlog . info ( " checking  %r  with size  %r " ,  key ,  sz )      cloudlog . debug ( " checking  %r  with size  %r " ,  key ,  sz )   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    if  sz  ==  0 :      if  sz  ==  0 :   
			
		
	
		
		
			
				
					
					      try :        try :   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -174,10 +174,10 @@ class Uploader(): 
			
		
	
		
		
			
				
					
					        cloudlog . event ( " uploader_setxattr_failed " ,  exc = self . last_exc ,  key = key ,  fn = fn ,  sz = sz )          cloudlog . event ( " uploader_setxattr_failed " ,  exc = self . last_exc ,  key = key ,  fn = fn ,  sz = sz )   
			
		
	
		
		
			
				
					
					      success  =  True        success  =  True   
			
		
	
		
		
			
				
					
					    else :      else :   
			
		
	
		
		
			
				
					
					      cloudlog . info ( " uploading  %r " ,  fn )        cloudlog . debug ( " uploading  %r " ,  fn )   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					      stat  =  self . normal_upload ( key ,  fn )        stat  =  self . normal_upload ( key ,  fn )   
			
		
	
		
		
			
				
					
					      if  stat  is  not  None  and  stat . status_code  in  ( 200 ,  201 ,  412 ) :        if  stat  is  not  None  and  stat . status_code  in  ( 200 ,  201 ,  412 ) :   
			
		
	
		
		
			
				
					
					        cloudlog . event ( " upload_success "  if  stat . status_code  !=  412  else  " upload_ignored " ,  key = key ,  fn = fn ,  sz = sz )          cloudlog . event ( " upload_success "  if  stat . status_code  !=  412  else  " upload_ignored " ,  key = key ,  fn = fn ,  sz = sz ,  debug = True )   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					        try :          try :   
			
		
	
		
		
			
				
					
					          # tag file as uploaded            # tag file as uploaded   
			
		
	
		
		
			
				
					
					          setxattr ( fn ,  UPLOAD_ATTR_NAME ,  UPLOAD_ATTR_VALUE )            setxattr ( fn ,  UPLOAD_ATTR_NAME ,  UPLOAD_ATTR_VALUE )   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -185,14 +185,12 @@ class Uploader(): 
			
		
	
		
		
			
				
					
					          cloudlog . event ( " uploader_setxattr_failed " ,  exc = self . last_exc ,  key = key ,  fn = fn ,  sz = sz )            cloudlog . event ( " uploader_setxattr_failed " ,  exc = self . last_exc ,  key = key ,  fn = fn ,  sz = sz )   
			
		
	
		
		
			
				
					
					        success  =  True          success  =  True   
			
		
	
		
		
			
				
					
					      else :        else :   
			
		
	
		
		
			
				
					
					        cloudlog . event ( " upload_failed " ,  stat = stat ,  exc = self . last_exc ,  key = key ,  fn = fn ,  sz = sz )          cloudlog . event ( " upload_failed " ,  stat = stat ,  exc = self . last_exc ,  key = key ,  fn = fn ,  sz = sz ,  debug = True )   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					        success  =  False          success  =  False   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    return  success      return  success   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					def  uploader_fn ( exit_event ) : def  uploader_fn ( exit_event ) :  
			
		
	
		
		
			
				
					
					  cloudlog . info ( " uploader_fn " )   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					  params  =  Params ( )    params  =  Params ( )   
			
		
	
		
		
			
				
					
					  dongle_id  =  params . get ( " DongleId " ) . decode ( ' utf8 ' )    dongle_id  =  params . get ( " DongleId " ) . decode ( ' utf8 ' )   
			
		
	
		
		
			
				
					
					
 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -209,8 +207,14 @@ def uploader_fn(exit_event): 
			
		
	
		
		
			
				
					
					  backoff  =  0.1    backoff  =  0.1   
			
		
	
		
		
			
				
					
					  while  not  exit_event . is_set ( ) :    while  not  exit_event . is_set ( ) :   
			
		
	
		
		
			
				
					
					    sm . update ( 0 )      sm . update ( 0 )   
			
		
	
		
		
			
				
					
					    on_wifi  =  force_wifi  or  sm [ ' deviceState ' ] . networkType  ==  NetworkType . wifi   
			
		
	
		
		
			
				
					
					    offroad  =  params . get ( " IsOffroad " )  ==  b ' 1 '      offroad  =  params . get ( " IsOffroad " )  ==  b ' 1 '   
			
		
	
		
		
			
				
					
					    network_type  =  sm [ ' deviceState ' ] . networkType  if  not  force_wifi  else  NetworkType . wifi   
			
		
	
		
		
			
				
					
					    if  network_type  ==  NetworkType . none :   
			
		
	
		
		
			
				
					
					      if  allow_sleep :   
			
		
	
		
		
			
				
					
					        time . sleep ( 60  if  offroad  else  5 )   
			
		
	
		
		
			
				
					
					      continue   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    on_wifi  =  network_type  ==  NetworkType . wifi   
			
		
	
		
		
			
				
					
					    allow_raw_upload  =  params . get ( " IsUploadRawEnabled " )  !=  b " 0 "      allow_raw_upload  =  params . get ( " IsUploadRawEnabled " )  !=  b " 0 "   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    d  =  uploader . next_file_to_upload ( with_raw = allow_raw_upload  and  on_wifi  and  offroad )      d  =  uploader . next_file_to_upload ( with_raw = allow_raw_upload  and  on_wifi  and  offroad )   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -221,13 +225,12 @@ def uploader_fn(exit_event): 
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    key ,  fn  =  d      key ,  fn  =  d   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    cloudlog . event ( " uploader_netcheck " ,  is_on_wifi = on_wifi )      cloudlog . debug ( " upload  %r  over  %s " ,  d ,  network_type )   
			
				
				
			
		
	
		
		
			
				
					
					    cloudlog . info ( " to upload  %r " ,  d )   
			
		
	
		
		
	
		
		
			
				
					
					    success  =  uploader . upload ( key ,  fn )      success  =  uploader . upload ( key ,  fn )   
			
		
	
		
		
			
				
					
					    if  success :      if  success :   
			
		
	
		
		
			
				
					
					      backoff  =  0.1        backoff  =  0.1   
			
		
	
		
		
			
				
					
					    elif  allow_sleep :      elif  allow_sleep :   
			
		
	
		
		
			
				
					
					      cloudlog . info ( " backoff  %r " ,  backoff )        cloudlog . info ( " upload  backoff %r " ,  backoff )   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					      time . sleep ( backoff  +  random . uniform ( 0 ,  backoff ) )        time . sleep ( backoff  +  random . uniform ( 0 ,  backoff ) )   
			
		
	
		
		
			
				
					
					      backoff  =  min ( backoff * 2 ,  120 )        backoff  =  min ( backoff * 2 ,  120 )   
			
		
	
		
		
			
				
					
					    cloudlog . info ( " upload done, success= %r " ,  success )      cloudlog . info ( " upload done, success= %r " ,  success )