[Durian-svn] [7281] moving scripts into a package, WIP

campbell institute at blender.org
Sun Jul 18 12:03:40 CEST 2010


Revision: 7281
          https://blenderinstitute.dyndns.org/durian-svn/?do=log&project=durian&path=/&rev=7281
Author:   campbell
Date:     2010-07-18 12:03:40 +0200 (Sun, 18 Jul 2010)
Log Message:
-----------
moving scripts into a package, WIP

Added Paths:
-----------
    pro/scripts/op/sequencer_utils/
    pro/scripts/op/sequencer_utils/__init__.py
    pro/scripts/op/sequencer_utils/size_mismatch.py
    pro/scripts/op/sequencer_utils/switch_finals.py

Removed Paths:
-------------
    pro/scripts/utilities/sequencer_switch_finals.py

Added: pro/scripts/op/sequencer_utils/__init__.py
===================================================================
--- pro/scripts/op/sequencer_utils/__init__.py	                        (rev 0)
+++ pro/scripts/op/sequencer_utils/__init__.py	2010-07-18 10:03:40 UTC (rev 7281)
@@ -0,0 +1,57 @@
+import space_sequencer
+
+def colins_report(data):
+    
+    
+
+class SizeMismatchImages(bpy.types.Operator):
+    ''''''
+    bl_idname = "sequencer.size_mismatch_images"
+    bl_label = "Sel Images Different to Render Size"
+
+    def execute(self, context):
+        import size_mismatch_select
+        errors = size_mismatch_select.main(context)
+        colins_report(errors)
+        return {'FINISHED'}
+
+
+class SwitchFinals(bpy.types.Operator):
+    ''''''
+    bl_idname = "sequencer.switch_finals"
+    bl_label = "Switch Finals"
+
+    def execute(self, context):
+        import switch_finals
+        errors = switch_finals.main(context)
+        colins_report(errors)
+        return {'FINISHED'}
+
+def menu_func_switch_finals(self, context):
+    self.layout.operator("sequencer.switch_finals")
+
+def menu_func_size_mismatch(self, context):
+    self.layout.operator("sequencer.size_mismatch_images")
+
+def register():
+    bpy.types.register(SizeMismatchImages)
+    bpy.types.register(SwitchFinals)
+    bpy.types.SEQUENCER_HT_header.append(menu_func_switch_finals)
+    bpy.types.SEQUENCER_HT_header.append(menu_func_size_mismatch)
+
+
+def unregister():
+    bpy.types.unregister(SizeMismatchImages)
+    bpy.types.unregister(SwitchFinals)
+    bpy.types.SEQUENCER_HT_header.remove(menu_func_switch_finals)
+    bpy.types.SEQUENCER_HT_header.remove(menu_func_size_mismatch)
+
+    # bpy.types.unregister(PadFrames)
+    # bpy.types.SEQUENCER_MT_strip.remove(menu_func_pad)    
+    # bpy.types.SEQUENCER_HT_header.remove(menu_func)
+
+'''
+if __name__ == "__main__":
+    register()
+    bpy.ops.object.vertex_loop_blend()
+'''
\ No newline at end of file

Added: pro/scripts/op/sequencer_utils/size_mismatch.py
===================================================================
--- pro/scripts/op/sequencer_utils/size_mismatch.py	                        (rev 0)
+++ pro/scripts/op/sequencer_utils/size_mismatch.py	2010-07-18 10:03:40 UTC (rev 7281)
@@ -0,0 +1,87 @@
+import os
+import subprocess
+
+DO_QUICKY = True
+
+def image_size(filepath):
+    '''
+    Return the size of an image
+    '''
+    ext = os.path.splitext(filepath)[1].lower()
+
+    if ext == ".exr":
+        out, err = subprocess.Popen(["exrheader", filepath], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
+    
+        lines = str(out).split("\\n")
+        lines_size = [l for l in lines if "displayWindow " in l]
+
+        # size
+        size_exr = lines_size[0].replace("(", "").replace(")", "").split()[-2:]
+        size_exr = int(size_exr[0]) + 1, int(size_exr[1]) + 1
+
+        return size_exr
+    else:
+        out, err = subprocess.Popen(["identify", filepath], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
+        lines = str(out).strip() # should be one line only
+        # example output:
+        #  ./pro/chars/textures/hyena_hair_ottimi.jpg JPEG 500x917 500x917+0+0 8-bit DirectClass 200KiB 0.000u 0:00.000
+        
+        for word in lines.split()[2:]: # 
+            nums = word.split("x")
+            if len(nums) == 2 and nums[0].isdigit() and nums[1].isdigit():
+                return int(nums[0]), int(nums[1])
+    
+    raise Exception("Couldn't find image size")
+
+def sel_bad_images():
+    import bpy
+    render = bpy.context.scene.render
+    size = render.resolution_x, render.resolution_y
+    
+    seqs = []
+    for seq in bpy.context.scene.sequence_editor.sequences:
+        seq.select = False
+        if seq.type == 'IMAGE':
+            seqs.append(seq)
+            
+    seqs.sort(key=lambda seq: seq.frame_final_start)
+    
+    errors = []
+    
+    for i, seq in enumerate(seqs):
+        print(i, "of", len(seqs), seq.name)
+        frame_start = seq.frame_start
+        frame_end = frame_start + seq.frame_length
+        directory = bpy.utils.expandpath(seq.directory)
+
+        elems = [seq.getStripElem(i) for i in range(frame_start, frame_end)]
+        elems = [elem for elem in elems if elem]
+        for elem in elems:
+            filepath = os.path.join(directory, elem.filename)
+            print("\t" + filepath)
+            
+            if not os.path.exists(filepath):
+                errors.append(" ".join([seq.name, "frame:", str(seq.frame_final_start), "missing:", filepath]))
+            else:
+                size_im = image_size(filepath)
+                if size_im != size:
+                    errors.append(" ".join([seq.name, "frame:", str(seq.frame_final_start), "size:", str(size_im)]))
+                    seq.select = True
+
+            if DO_QUICKY:
+                break
+
+    data = ""
+    data += ("Image Mismatch Errors:")
+    for error in errors:
+        data += ("\t%s\n" % error)
+
+    return
+
+
+def main():
+    return sel_bad_images()
+
+
+if __name__ == "__main__":
+    main()

Copied: pro/scripts/op/sequencer_utils/switch_finals.py (from rev 7259, pro/scripts/utilities/sequencer_switch_finals.py)
===================================================================
--- pro/scripts/op/sequencer_utils/switch_finals.py	                        (rev 0)
+++ pro/scripts/op/sequencer_utils/switch_finals.py	2010-07-18 10:03:40 UTC (rev 7281)
@@ -0,0 +1,212 @@
+# import bpy
+import os
+import blend_render_info
+
+
+DEBUG = False
+
+# CONSTANTS
+CONTEXT = 'SEL' # SEL or ALL
+IMAGE_EXT = ".exr" # .exr or .jpg
+AVI_DIR = "//render/"
+EXR_DIR = "/shared/render"
+SVN_DIR = "/d/pro/scenes"
+
+# LOG ERRORS
+MISSING_BLENDS = [] # avis that have no blends
+MISSING_EXRS = [] # avis that have no exrs
+MISSING_EXRS_FILES = [] # avis that have no exrs
+BAD_AVI_LENGTHS = [] # blends that are not the same length as the avis
+
+def blend_path_list(path):
+    for dirpath, dirnames, filenames in os.walk(path):
+        for filename in filenames:
+            if filename.endswith(".blend"):
+                yield os.path.join(dirpath, filename)
+
+
+blend_lookup = {}
+for blend in blend_path_list(SVN_DIR):
+    basename = os.path.splitext(os.path.basename(blend))[0]
+    blend_lookup[basename] = blend
+
+def convert_avi_to_exr(filepath):
+    '''
+    Takes the full avi path
+    '''
+    if filepath.startswith(AVI_DIR):
+        base_name = os.path.splitext(filepath)[0]
+        base_name = os.path.basename(base_name)
+
+        if DEBUG:
+            print(filepath)
+
+        blend_name = blend_lookup.get(base_name, "")
+
+        if not blend_name:
+            MISSING_BLENDS.append(base_name)
+        else:
+            exr_path_current = os.path.join(EXR_DIR, base_name)
+            exr_path_final = os.path.join(EXR_DIR, base_name, "final")
+
+            # add extra check that there is at least 1 valid image in the directory
+            if os.path.exists(exr_path_final) and [f for f in os.listdir(exr_path_final) if f.endswith(IMAGE_EXT)]:
+                exr_path = exr_path_final
+            else:
+                exr_path = exr_path_current
+
+            # print(base_name)
+            if os.path.exists(exr_path):
+                # Should be no more then 1 anyway
+                frame_start, frame_end, scene = blend_render_info.read_blend_rend_chunk(blend_name)[0]
+
+                # print(exr_path)
+                exrs = []
+                '''
+                for f in os.listdir(exr_path):
+                    if f.startswith(base_name) and f.endswith(IMAGE_EXT):
+                        f_num = f.split("_")[-1].split(".")[0]
+                        val = int(f_num)
+                        if val >= frame_start and val <= frame_end:
+                            exrs.append(f)
+                        else:
+                            if DEBUG:
+                                print("remove_me", f)
+                '''
+
+                for i in range(frame_start, frame_end + 1):
+                    exr_name = "%s_%.6d%s" % (base_name, i, IMAGE_EXT)
+                    exr_name_full = os.path.join(exr_path, exr_name)
+                    if not os.path.exists(exr_name_full):
+                        MISSING_EXRS_FILES.append(exr_name_full)
+                    else:
+                        exrs.append(os.path.basename(exr_name_full))
+
+
+                if exrs:
+                    tot = frame_end - frame_start
+                    if(tot > len(exrs)):
+                        if DEBUG:
+                            print("%s missing %d frames" % (base_name, tot - len(exrs)))
+                            return "", [], frame_start, frame_end
+                    # print("PATH:", exr_path)
+                    return exr_path, exrs, frame_start, frame_end
+            else:
+                print("\texr path missing: %s" % exr_path)
+
+    return "", [], -1, -1
+
+
+def convert_exr_to_avi(basepath):
+    '''
+    Takes the base path only
+    '''
+    basename = os.path.basename(basepath)
+    filepath = os.path.join(AVI_DIR, basename + ".avi")
+    if os.path.exists(filepath):
+        return filepath
+
+    return ""
+
+
+try:
+    import bpy
+except:
+    bpy = None
+
+def main():
+    if not bpy:
+        return
+
+    '''
+    a = convert_avi_to_exr("//render/04.2g_comp.avi")[0]
+    print(convert_exr_to_avi(a))
+    '''
+
+
+    def add_strip(image_dir, images):
+        files = []
+        
+        if not image_dir.endswith(os.path.sep):
+            image_dir += os.path.sep
+
+        bpy.ops.sequencer.image_strip_add( \
+            directory=image_dir, \
+            frame_start=-1000, \
+            channel=1, \
+            replace_sel=True, \
+            files=[{"name": image} for image in images])
+        
+        return bpy.context.scene.sequence_editor.active_strip
+
+    if CONTEXT == 'SEL':
+        seq_ls = bpy.context.selected_sequences[:]
+    else:
+        seq_ls = bpy.context.scene.sequence_editor.sequences_all[:]
+
+    for seq in seq_ls:
+        if seq.type != 'MOVIE':
+            continue
+
+        filepath = seq.filepath
+        
+        image_dir, image_files, frame_start, frame_end = convert_avi_to_exr(filepath)
+
+        if not image_dir:
+            MISSING_EXRS.append(filepath)
+        else:
+            if len(image_files) == seq.frame_length:
+                seq.select = True
+                print("swapping:", filepath, len(image_files), seq.frame_length)

@@ Diff output truncated at 10240 characters. @@


More information about the Durian-svn mailing list