예제 #1
0
class Import(Command):
    """ Command class to import patches into the patch queue """

    def __init__(self, cwd, quilt_pc, quilt_patches):
        super(Import, self).__init__(cwd)
        self.quilt_pc = Directory(quilt_pc)
        self.quilt_patches = Directory(quilt_patches)
        self.db = Db(quilt_pc)
        self.series = Series(quilt_patches)

    def _import_patches(self, patches, reverse=False, strip=None):
        top = self.db.top_patch()
        patchlist = []
        for patch in patches:
            patchlist.append(Patch(patch, reverse=reverse, strip=strip))
        self.series.add_patches(patchlist, top)
        self.series.save()

    def import_patch(self, patch_name, new_name=None):
        """ Import patch into the patch queue
        The patch is inserted after the current top applied patch
        """
        if new_name:
            dir_name = os.path.dirname(new_name)
            name = os.path.basename(new_name)
            dest_dir = self.quilt_patches + Directory(dir_name)
            dest_dir.create()
        else:
            name = os.path.basename(patch_name)
            dest_dir = self.quilt_patches

        patch_file = File(patch_name)
        dest_file = dest_dir + File(name)
        patch_file.copy(dest_file)
        self._import_patches([name])

    def import_patches(self, patches):
        """ Import several patches into the patch queue """

        dest_dir = self.quilt_patches
        patch_names = []

        for patch in patches:
            patch_name = os.path.basename(patch)
            patch_file = File(patch)
            dest_file = dest_dir + File(patch_name)
            patch_file.copy(dest_file)
            patch_names.append(patch_name)

        self._import_patches(patch_names)
예제 #2
0
class New(Command):

    patch_created = Signal()

    """ Creates a new patch in the queue """
    def __init__(self, cwd, quilt_pc, quilt_patches):
        super(New, self).__init__(cwd)
        self.quilt_pc = Directory(quilt_pc)
        self.quilt_patches = Directory(quilt_patches)
        self.db = Db(quilt_pc)
        self.series = Series(quilt_patches)

    def create(self, patchname):
        """ Adds a new patch with patchname to the queue

        The new patch will be added as the topmost applied patch.
        """
        patch = Patch(patchname)
        if self.series.is_patch(patch):
            raise PatchAlreadyExists(self.series, patchname)

        patch_dir = self.quilt_patches
        patch_dir.create()
        patchfile = patch_dir + File(patchname)
        patchfile.touch()

        pc_dir = self.quilt_pc + patchname
        if pc_dir.exists():
            # be sure that the directory is clear
            pc_dir.delete()

        # create empty .pc/<patchname> directory as quilt does too
        pc_dir.create()

        top = self.db.top_patch()
        # add new patch after the current topmost applied patch
        self.series.add_patches([patch], top)
        # "apply" patch
        self.db.add_patch(patch)

        # create patches/series files
        self.series.save()
        # create .pc/.version and .pc/applied-patches files
        self.db.save()

        self.patch_created(patch)
예제 #3
0
class New(Command):

    patch_created = Signal()
    """ Creates a new patch in the queue """
    def __init__(self, cwd, quilt_pc, quilt_patches):
        super(New, self).__init__(cwd)
        self.quilt_pc = Directory(quilt_pc)
        self.quilt_patches = Directory(quilt_patches)
        self.db = Db(quilt_pc)
        self.series = Series(quilt_patches)

    def create(self, patchname):
        """ Adds a new patch with patchname to the queue

        The new patch will be added as the topmost applied patch.
        """
        patch = Patch(patchname)
        if self.series.is_patch(patch):
            raise PatchAlreadyExists(self.series, patchname)

        patch_dir = self.quilt_patches
        patch_dir.create()
        patchfile = patch_dir + File(patchname)
        patchfile.touch()

        pc_dir = self.quilt_pc + patchname
        if pc_dir.exists():
            # be sure that the directory is clear
            pc_dir.delete()

        # create empty .pc/<patchname> directory as quilt does too
        pc_dir.create()

        top = self.db.top_patch()
        # add new patch after the current topmost applied patch
        self.series.add_patches([patch], top)
        # "apply" patch
        self.db.add_patch(patch)

        # create patches/series files
        self.series.save()
        # create .pc/.version and .pc/applied-patches files
        self.db.save()

        self.patch_created(patch)
예제 #4
0
class New(Command):

    patch_created = Signal()

    """ Creates a new patch in the queue """

    def __init__(self, cwd, quilt_pc, quilt_patches):
        super(New, self).__init__(cwd)
        self.quilt_pc = Directory(quilt_pc)
        self.quilt_patches = Directory(quilt_patches)
        self.db = Db(quilt_pc)
        self.series = Series(quilt_patches)

    def create(self, patchname):
        """ Adds a new patch with patchname to the queue

        The new patch will be added after the top patch
        """
        patch = Patch(patchname)
        if self.series.is_patch(patch):
            raise PatchAlreadyExists(self.series, patchname)

        patch_dir = self.quilt_patches
        patch_dir.create()
        patchfile = patch_dir + File(patchname)
        patchfile.touch()

        pc_dir = self.quilt_pc + patchname
        if pc_dir.exists():
            # be sure that the directory is clear
            pc_dir.delete()
        else:
            pc_dir.create()

        top = self.db.top_patch()
        self.series.add_patches([patch], top)
        self.series.save()

        self.patch_created(patch)
예제 #5
0
class Delete(Command):

    """Command class to delete patches
    """

    deleting_patch = Signal()
    deleted_patch = Signal()

    def __init__(self, cwd, quilt_pc, quilt_patches):
        super(Delete, self).__init__(cwd)
        self.quilt_pc = Directory(quilt_pc)
        self.quilt_patches = Directory(quilt_patches)
        self.db = Db(quilt_pc)
        self.series = Series(quilt_patches)
        self.pop = Pop(cwd, quilt_pc)

    def _delete_patch(self, patch, remove=False, backup=False):
        if self.series.is_empty():
            raise NoPatchesInSeries(self.series)
        if not self.series.is_patch(patch):
            raise UnknownPatch(self.series, patch)

        applied = self.db.top_patch() == patch
        self.deleting_patch(patch, applied)

        if applied:
            self.pop._unapply_patch(patch)
            self.db = self.pop.db
            self.db.save()

        self.series.remove_patch(patch)
        self.series.save()

        patch_file = self.quilt_patches + File(patch.get_name())

        if remove:
            if backup:
                patch_file.copy(File(patch_file.get_name() + "~"))

            patch_file.delete_if_exists()

        self.deleted_patch(patch)

    def delete_next(self, remove=False, backup=False):
        """ Delete next unapplied patch
        If remove is True the patch file will also be removed. If remove and
        backup are True a copy of the deleted patch file will be made.
        """
        patch = self.db.top_patch()
        if patch:
            after = self.series.patch_after(patch)
        else:
            after = self.series.first_patch()
        if not after:
            raise QuiltError("No next patch")

        self._delete_patch(after, remove=remove, backup=backup)

    def delete_patch(self, patch_name=None, remove=False, backup=False):
        """ Delete specified patch from the series
        If remove is True the patch file will also be removed. If remove and
        backup are True a copy of the deleted patch file will be made.
        """
        if patch_name:
            patch = Patch(patch_name)
        else:
            patch = self.db.top_patch()
            if not patch:
                raise NoAppliedPatch(self.db)

        self._delete_patch(patch, remove=remove, backup=backup)
예제 #6
0
class Delete(Command):
    """Command class to delete patches
    """

    deleting_patch = Signal()
    deleted_patch = Signal()

    def __init__(self, cwd, quilt_pc, quilt_patches):
        super(Delete, self).__init__(cwd)
        self.quilt_pc = Directory(quilt_pc)
        self.quilt_patches = Directory(quilt_patches)
        self.db = Db(quilt_pc)
        self.series = Series(quilt_patches)
        self.pop = Pop(cwd, quilt_pc)

    def _delete_patch(self, patch, remove=False, backup=False):
        if self.series.is_empty():
            raise NoPatchesInSeries(self.series)
        if not self.series.is_patch(patch):
            raise UnknownPatch(self.series, patch)

        applied = self.db.top_patch() == patch
        self.deleting_patch(patch, applied)

        if applied:
            self.pop._unapply_patch(patch)
            self.db = self.pop.db
            self.db.save()

        self.series.remove_patch(patch)
        self.series.save()

        patch_file = self.quilt_patches + File(patch.get_name())

        if remove:
            if backup:
                patch_file.copy(File(patch_file.get_name() + "~"))

            patch_file.delete_if_exists()

        self.deleted_patch(patch)

    def delete_next(self, remove=False, backup=False):
        """ Delete next unapplied patch
        If remove is True the patch file will also be removed. If remove and
        backup are True a copy of the deleted patch file will be made.
        """
        patch = self.db.top_patch()
        if patch:
            after = self.series.patch_after(patch)
        else:
            after = self.series.first_patch()
        if not after:
            raise QuiltError("No next patch")

        self._delete_patch(after, remove=remove, backup=backup)

    def delete_patch(self, patch_name=None, remove=False, backup=False):
        """ Delete specified patch from the series
        If remove is True the patch file will also be removed. If remove and
        backup are True a copy of the deleted patch file will be made.
        """
        if patch_name:
            patch = Patch(patch_name)
        else:
            patch = self.db.top_patch()
            if not patch:
                raise NoAppliedPatch(self.db)

        self._delete_patch(patch, remove=remove, backup=backup)