info = { 'icon' : 'COPYDOWN', 'description' : 'Go in render node mode waiting for jobs in watchfolder', 'checkfiles' : False, 'stamp' : False, 'cmds' : '' } import os from os import listdir from os.path import join, dirname, basename, exists, isfile, isdir, splitext import re from time import sleep import time import datetime ## Blender import bpy from mathutils import Vector, Matrix C = bpy.context D = bpy.data scn = scene = C.scene def submit_to_watchfolder(checkfiles=False): '''submitter (with or without file_copy)''' if D.is_dirty or not D.is_saved: print('!!! Not submitted : File must be saved first') return totalframes = scn.frame_end - scn.frame_start if not overwrite: #check if output path exists and have file out = scn.render.filepath outfolder = dirname(out) if exists(outfolder): outname = basename(out) refile = re.compile(outname.rstrip('#') + r'\d{4}') outlist = [f for f in listdir(outfolder) if refile.match(f)] if outlist: print(f'!!! Abort submission : Overwrite is False and {len(outlist)} files already exists ({totalframes} wanted)') return print(f'{totalframes} frames to render') watchfolder = '/z/___SERIE/WIND-UPS/episodes/00/watchfolder' if not exists(watchfolder): print(f'watchfolder not found at {watchfolder}') watchfolder = '/mnt/admserveur/prod/___SERIE/WIND-UPS/episodes/00/watchfolder' if not exists(watchfolder): print(f'ABORT : watchfolder not found at {watchfolder}') return 1 #save a copy to the file ? the_file = D.filepath finalname = basename(D.filepath) ''' if use_copy: #save a copy head, tail = os.path.split(D.filepath) name, ext = splitext(tail) uid = datetime.datetime.now().strftime('_rdtemp%Y%m%d%H%M%S') finalname = name + uid + ext the_file = join(head, finalname) bpy.ops.wm.save_as_mainfile(filepath=the_file, copy=True) link = join(watchfolder, finalname) print(f'Create symlink:\n src: {finalname}\n dest: {link}')#the_file, complete path to finalname os.symlink(the_file, link)#impossible to create symlink... so fuck-it. ''' noext = splitext(finalname)[0] stby = join(watchfolder, 'stby--' + noext)# + '.txt' todo = join(watchfolder, 'todo--' + noext)# + '.txt' running = join(watchfolder, 'runn--' + noext)# + '.txt' done = join(watchfolder, 'done--' + noext)# + '.txt' bad = 0 statelist = [] if exists(stby): statelist.append(basename(stby)) if exists(todo): statelist.append(basename(todo)) if exists(running): statelist.append(basename(running)) if exists(done): statelist.append(basename(done)) for f in os.listdir(watchfolder): if splitext(f)[0][len('stby--'):] == noext: print('Something already exists') if exists(todo): bad = 1 print(f'{noext}: Job already submitted') if len(statelist) > 1: print('problem : job exists in multiple states') for state in statelist: print(state) bad = 1 if bad: print('skip') return with open(todo, 'w') as fd: fd.write(the_file+'\n') if info['stamp']: fd.write('stamp\n') if info['cmds']: fd.write(info['cmds']) print(f'Created job {todo}') print(f'Submit {basename(D.filepath)}') submit_to_watchfolder(checkfiles=info['checkfiles'])