コード例 #1
0
    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
コード例 #2
0
ファイル: flask.py プロジェクト: touilleMan/mongopatcher
def discover(patches, verbose, name):
    """List the patches available in the given patches directory"""
    patches = _get_mongopatcher().discover(directory=patches)
    if name:
        import re

        patches = [p for p in patches if re.match(name, p.target_version)]
    if not patches:
        print("No patches found")
    else:
        print("Patches available:")
        for patch in patches:
            if verbose:
                print()
                print(patch.target_version)
                print("~" * len(patch.target_version))
                print(tabulate(patch.patchnote))
            else:
                print(" - %s" % patch.target_version)
コード例 #3
0
ファイル: flask.py プロジェクト: Scille/mongopatcher
def discover(patches, verbose, name):
    """List the patches available in the given patches directory"""
    if not patches:
        patches = current_app.config['MONGOPATCHER_PATCHES_DIR']
    patches = _get_mongopatcher().discover(patches)
    if name:
        import re
        patches = [p for p in patches if re.match(name, p.target_version)]
    if not patches:
        print('No patches found')
    else:
        print('Patches available:')
        for patch in patches:
            if verbose:
                print()
                print(patch.target_version)
                print("~" * len(patch.target_version))
                print(tabulate(patch.patchnote))
            else:
                print(' - %s' % patch.target_version)