def backupVersionedFile(old_file, version):
 numTries = 0
 new_file = u'{}.v{}'.format(old_file, version)
 while (not os.path.isfile(new_file)):
  if (not os.path.isfile(old_file)):
   sickrage.srCore.srLogger.debug((u"Not creating backup, %s doesn't exist" % old_file))
   break
  try:
   sickrage.srCore.srLogger.debug((u'Trying to back up %s to %s' % (old_file, new_file)))
   shutil.copyfile(old_file, new_file)
   sickrage.srCore.srLogger.debug(u'Backup done')
   break
  except Exception as e:
   sickrage.srCore.srLogger.warning((u'Error while trying to back up %s to %s : %r' % (old_file, new_file, e)))
   numTries += 1
   time.sleep(1)
   sickrage.srCore.srLogger.debug(u'Trying again.')
  if (numTries >= 10):
   sickrage.srCore.srLogger.error((u'Unable to back up %s to %s please do it manually.' % (old_file, new_file)))
   return False
 return True

def backupVersionedFile ( old_file , version ) : numTries = 0 new_file = u'{}.v{}' . format ( old_file , version ) while ( not os . path . isfile ( new_file ) ) : if ( not os . path . isfile ( old_file ) ) : sickrage . srCore . srLogger . debug ( ( u"Not creating backup, %s doesn't exist" % old_file ) ) break try : sickrage . srCore . srLogger . debug ( ( u'Trying to back up %s to %s' % ( old_file , new_file ) ) ) shutil . copyfile ( old_file , new_file ) sickrage . srCore . srLogger . debug ( u'Backup done' ) break except Exception as e : sickrage . srCore . srLogger . warning ( ( u'Error while trying to back up %s to %s : %r' % ( old_file , new_file , e ) ) ) numTries += 1 time . sleep ( 1 ) sickrage . srCore . srLogger . debug ( u'Trying again.' ) if ( numTries >= 10 ) : sickrage . srCore . srLogger . error ( ( u'Unable to back up %s to %s please do it manually.' % ( old_file , new_file ) ) ) return False return True
back up an old version of a file .