<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def discover_and_apply(self, directory=None, dry_run=False):
 """ Retrieve the patches and try to apply them against the datamodel :param directory: Directory to search the patch in (default: patches_dir) :param dry_run: Don't actually apply the patches """

        directory = directory or self.patches_dir
        patches_dict = {p.base_version: p for p in self.discover(directory)}
        current_version = self.manifest.version
        if not patches_dict.get(current_version):
            print('No patch to apply')
            return
        if dry_run:
            msg = 'Datamodel should be in version %s !'
        else:
            msg = 'Datamodel in now in version %s !'
        pss = []
        while True:
            patch = patches_dict.get(current_version)
            if not patch:
                print(msg % current_version)
                if pss:
                    print()
                    print(yellow('\n'.join(pss)))
                return
            print('Applying patch %s => %s' % (patch.base_version,
                                               patch.target_version))
            patch_pss = [patch.ps] if patch.ps else []
            if not dry_run:
                patch_pss += self.apply_patch(patch)
            if patch_pss:
                pss.append("Patch %s:\n%s" % (patch.target_version,
                                              tabulate('\n'.join(patch_pss))))
            self.manifest.reload()
            current_version = patch.target_version