Python Operator: Context is Incorrect I currently am writing python operator whith the task of appending the current scene into a new file and then linking it back into the original file. There is one problem: When loading a new file the bpy.context changes and I do not quite know how to reload it. This leads to the error "context is incorrect" when trying to append the original scene into the new file. Here is how my code looks so far:

class BPC_main_Outsource(bpy.types.Operator):
    bl_idname = "scene.outsource"
    bl_label = "Outsource"
    def execute(self, context):        
        compScene = bpy.context.scene #get scene
        bpy.ops.wm.save_mainfile() #save current file
        blendFile  = bpy.data.filepath #get path of current file
        apFilename = compScene.name #determine scene's name
        bpy.ops.wm.read_homefile() #load a new file
        oldScene = bpy.context.scene #get current scene in new file
        blendFile = blendFile.replace("\\", r"/")
        apPath = "//" + bpy.path.basename(blendFile) + "/Scene/" + apFilename #build append path
        apDirectory = blendFile + "/Scene/" #build append directory
        bpy.ops.wm.append(filepath=apPath, directory=apDirectory, filename=apFilename) #append scene from main file
        bpy.ops.scene.delete() #delete old scene in new file 
        #TODO: save file, open original file, link back
        return {"FINISHED"}


Any help on how to fix this would be greatly appreciated. Thanks in advance.
Script saves the current file, removes all scenes but the context scene and saves that to a file in the current blends directory with name "SCENE_&lt;context.scene.name&gt;" eg SCENE_Scene.blend for the scene.name of "Scene".  

After which it reopens the original file, links to the scene in the created file, and deletes the original.

import bpy

class BPC_main_Outsource(bpy.types.Operator):
    bl_idname = "scene.outsource"
    bl_label = "Outsource"

    @classmethod
    def poll(cls, context):
        return bpy.data.filepath != "" and context.scene.library is None

    def execute(self, context):
        from os import path

        compScene = context.scene #get scene
        blendFile  = bpy.data.filepath #get path of current file
        clean_name = bpy.path.clean_name(bpy.path.display_name(blendFile))
        apFilename = compScene.name 
        screen_name = context.screen.name
        scene_file_path = blendFile.replace(clean_name, "SCENE_%s" % apFilename)

        if path.isfile(scene_file_path):
            print("Scene file %s already exists" % scene_file_path)
            return {'CANCELLED'}

        bpy.ops.wm.save_mainfile()      

        # remove all but context scene
        for scene in bpy.data.scenes:
            if scene == compScene:
                continue
            bpy.data.scenes.remove(scene)


        # save with only compScene
        bpy.ops.wm.save_as_mainfile(filepath=scene_file_path)        
        # reopen original,link saved scene
        bpy.ops.wm.open_mainfile(filepath=blendFile)  
        scene = bpy.data.scenes.get(apFilename)     
        # link the scene back
        with bpy.data.libraries.load(scene_file_path, link=True, relative=True) as (data_from, data_to):
            data_to.scenes = [apFilename]
        # rename the original scene, remove crashes my blender    
        screen = bpy.data.screens.get(screen_name) 
        scn = screen.scene
        if scene and screen:

            scene.name = "%s_ORIGINAL" % scene.name
            scn = bpy.data.scenes.get(apFilename)
            #c = context.copy()
            print("CONTEXT", bpy.context.window, context.window)
            c = {"scene": scene,
                 "screen": screen,
                 "area": screen.areas[0],
                 "region": screen.areas[0].regions[0],
                 "edit_object": None,
                 "blend_data": bpy.data,
                 "window": bpy.data.window_managers[0].windows[0]
                 }
            bpy.ops.scene.delete(c)
            screen.scene = scn

        return {"FINISHED"}

bpy.utils.register_class(BPC_main_Outsource)

# test run
if bpy.ops.scene.outsource.poll():
    bpy.ops.scene.outsource()
else:
    print("Failed POLL is scene already linked?")