[Tutor] Please comment my -first- script

Bernard Lebel python at bernardlebel.com
Thu Aug 19 02:22:47 CEST 2004


Hi Kent,

First, thanks a lot for the suggestions. I implemented them all!

Regarding the part of your email that I included in this reply, I did a
little test, nothing fancy.
I ran two versions of the script: one with everything you suggested
implemented, and one without the part below (the sequences collecting and
iteration statements).

To iterate over 302 files and 11 directories, it took about:
1.25 seconds to complete without the code below
0.75 seconds to complete with the code below.

It was not easy to implemented, but I think it paid off. It's also 15 lines
less!

Here is the script again, if anyone is interested. Warning: in py format.

Thanks again
Bernard

----- Original Message ----- 
From: "Kent Johnson" <kent_johnson at skillsoft.com>

> aNames = {}
> for oFile in oFiles:
>      sName, sSeq, sExt = oFile.split('.')
>      aNames.setdefault(sName, []).append(sSeq)
>
> The loop to test for missing sequences would be something like this:
> for sName, sSeqList in aNames.items():
>      for iFrame in range(iStart, iEnd + 1):
>          # Search in sSeqList for iFrame using a similar loop to what you
> have now with sZero
-------------- next part --------------
"""
Check_Sequence.py

Par Bernard Lebel
Directeur technique, rendering
Action Synthese - Marseille -France-
Aout 2004

Check_Sequence.py est la version pour l interpreteur Python.
Il doit être execute avec Python IDLE - PythonWin -
ou tout autre interpreteur natif Python
La version Check_Sequence.pys est la version pour XSI
et doit etre executee dans le Script Editor de XSI



Description
Check_sequence détecter les frames manquants dans toutes
les passes rendues pour le plan spécifie
et detecte aussi les drop-frames -frames pesant moins de 1k-

Pour l instant, tous les dossiers du plan specifie sont evalues
a l'exception des dossiers 2flame et poubelle
Une version future permettra d etre plus selectif



Utilisation
Lancer l interpreteur Python -en l'occurence PythonWin-
Faire Ctrl I -File > Import-
Selectionner le script - cliquer OK
Entrer le numéro de sequence avec les zeros qui precedent
mais sans le S
Entrer le numero de plan avec les zeros qui precedent
mais sans le P
Entrer le premier frame attendu, sans les zeros qui precedent
Entrer le dernier frame attendu, sans les zeros qui precedent
Lire le rapport

Thanks to Kent Johnson for the many suggestions
"""



# -----------------------------------------------------
# Import block

import os

# -----------------------------------------------------


print '                [[ CHECK SEQUENCE ]]                '

print ''
print '>>>>> IMPORTANT:'
print "1. Assurez-vous d'avoir des dossiers propres avant d'executer le script."
print "2. N'entrez pas le S et le P dans les numeros de sequence et de plan."




sSequence = raw_input( 'Numero de sequence (sans le S): ' )
sPlan = raw_input( 'Numero de plan (sans le P): ' )
iStart = int( raw_input( 'Premier frame: ' ) )
iEnd = int( raw_input( 'Dernier frame: ' ) )
iCount = iEnd - iStart + 1




# Define root search path
sRoot = os.path.join( 'C:\\FRAME2\\SEQUENCES', 'S' + sSequence, 'P' + sPlan )
#sRoot = os.path.join( '\\\\Sata-NAS1500\\FRAME2\\SEQUENCES', 'S' + sSequence, 'P' + sPlan )

if not os.path.exists( sRoot ):
	print 'Pas de plan pour le dossier specifie.'
else:
	print ''
	print '>>>>> INFORMATIONS SUR LE PLAN:'
	print '1. Dossier du plan: ' + sRoot
	print '2. Premier frame: ' + str( iStart )
	print '3. Dernier frame: ' + str( iEnd )
	print '4. Nombre de frames attendus: ' + str( iCount )



	print ''
	print '>>>>> DEBUT DE VERIFICATION DU PLAN'
	
	# Iterate through root folder to collected folders
	for sDirPath, sDirName, oFiles in os.walk( sRoot, True, None ):
	
		if '2flame' in sDirName:
			sDirName.remove( '2flame' )
		
		if 'poubelle' in sDirName:
			sDirName.remove( 'poubelle' )
		
		# Check if directory contains files
		if len( oFiles ) > 0:
			print ''
			print '_____ Verification de >>>>>>>>>>>> ' + sDirPath



			# Get file extention
			sExt = ''
			
			# Get name of first file
			oFirstFile = oFiles[0]
		
			# Split name into elements
			aFirstName = oFirstFile.split( '.' )
			
			if len( aFirstName ) == 1:
				sExt = ''
			elif len( aFirstName ) == 2:
				sExt = aFirstName[1]
			else:
				sExt = aFirstName[-1]
		


			# Create empty dictionary to store sequences
			aNames = {}
			
			# Iterate through files of current directory
			for oFile in oFiles:
				
				# Check the file size
				if os.path.getsize( os.path.join( sDirPath, oFile ) ) < 1024:
					print '          Drop: ' + oFile
			
				# Split file name into elements, and assign variables for each of them
				try:
					sName, sPad, sExt = oFile.split( '.' )
				except ValueError:
					pass
				
				aNames.setdefault( sName, [] ).append( sPad )
				
				
				
			# Iterate over each sequence
			for sName, aPad in aNames.items():
				
				# Now create a virtual sequence of files
				for iFrame in range( iStart, iEnd + 1 ):
					
					# Convert current frame to string
					sFrame = str( iFrame )
					
					# Give 5 chances to test the existance of the file. At each new attempt, add a 0 to the padding
					for iZero in range(5):
						# Check if current padding is found in list of pad numbers
						if not sFrame in aPad:
							# Not found, so add a leading 0 to the padding
							sFrame = sFrame.zfill( len( sFrame ) + 1 )
						else:
							# A match is found, move on to the next sequence.
							break
					else:
						# So we reached here because we could never find a match for the virtual padding and the collected ones.
						print '            Not found: ' + sName + '.' + str(iFrame)
				
	# Script completed!
	print ''
	print '>>>>> FIN DE VERIFICATION DU PLAN'
	


More information about the Tutor mailing list