def _do_apply_filename(self, target_filename): print 'Applying patches to: %s' % target_filename patches = PatchManager.get_patches_for_filename(target_filename) patch_datas = [p.patch_data for p in patches] print ' - Patches Found: %d' % len(patches) try: # Apply the patches: PatchManager.apply_patchs(target_filename, patch_datas) # Remove these patches from the database: for p in patches: session.delete(p) session.commit() PatchManager.clear_empty_patchsets() except PatchApplyError: print 'Error applying patch to XX'