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 run(self, args): series = Series(self.get_patches_dir()) if not series.exists(): self.exit_error("No series file found.") db = Db(self.get_pc_dir()) top = None if args.patch: patch_name = args.patch top = Patch(patch_name) else: if db.exists(): top = db.top_patch() if not top: top = series.first_patch() if not top: self.exit_error("No patch in series.") else: print(top) else: patch = series.patch_after(top) if not patch: self.exit_error("No patch available after %s." % top) else: print(patch)
def run(self, options, args): db = Db(self.get_pc_dir()) top = db.top_patch() series = Series(self.get_patches_dir()) if top is None: patches = series.patches() else: patches = series.patches_after(top) for patch in patches: print patch
def run(self, args): db = Db(self.get_pc_dir()) top = db.top_patch() series = Series(self.get_patches_dir()) if top is None: patches = series.patches() else: patches = series.patches_after(top) for patch in patches: print(patch)
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)
def run(self, args): series = Series(self.get_patches_dir()) if args.v: applied = Db(self.get_pc_dir()).patches() for patch in applied[:-1]: print("+ " + patch.get_name()) if applied: print("= " + applied[-1].get_name()) patches = series.patches_after(applied[-1]) else: patches = series.patches() for patch in patches: print(" " + patch.get_name()) else: for patch in series.patches(): print(patch.get_name())
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)
def run(self, args): series = Series(self.get_patches_dir()) db = Db(self.get_pc_dir()) top = None if args.patch: top = Patch(args.patch) else: if db.exists(): top = db.top_patch() if not top: self.exit_error("No patches applied.") else: patch = series.patch_before(top) if not patch: self.exit_error("No patch available before %s." % top) else: print(patch)
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)
def run(self, options, args): series = Series(self.get_patches_dir()) db = Db(self.get_pc_dir()) top = None if len(args) > 0: top = Patch(args[0]) else: if db.exists(): top = db.top_patch() if not top: top = series.first_patch() if not top: self.exit_error("No patch in series.") else: print top else: patch = series.patch_before(top) if not patch: self.exit_error("No patch available after %s." % patch) else: print patch
def __init__(self, cwd, quilt_pc, quilt_patches): super(Revert, 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)
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)
def run(self, option, args): series = Series(self.get_patches_dir()) for patch in series.patches(): print patch
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 tmp_series(): with TmpDirectory() as dir: patches = os.path.join(dir.get_name(), "patches") os.mkdir(patches) yield (dir.get_name(), Series(patches))
class Push(Command): applying = Signal() applying_patch = Signal() applied = Signal() applied_patch = Signal() applied_empty_patch = Signal() def __init__(self, cwd, quilt_pc, quilt_patches): super(Push, 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 _apply_patch(self, patch, force=False, quiet=False): patch_name = patch.get_name() pc_dir = self.quilt_pc + patch_name patch_file = self.quilt_patches + File(patch_name) refresh = File(pc_dir.get_name() + "~refresh") forced = False self.applying_patch(patch) if patch_file.exists(): try: patch.run(self.cwd, patch_dir=self.quilt_patches, backup=True, prefix=pc_dir.get_name(), quiet=quiet) except SubprocessError as e: if not force: patch = RollbackPatch(self.cwd, pc_dir) patch.rollback() patch.delete_backup() raise QuiltError("Patch %s does not apply" % patch_name) else: refresh.touch() forced = True self.db.add_patch(patch) if pc_dir.exists(): timestamp = pc_dir + File(".timestamp") timestamp.touch() else: pc_dir.create() if not patch_file.exists(): self.applied_empty_patch(patch, False) elif pc_dir.is_empty(): self.applied_empty_patch(patch, True) elif forced: raise QuiltError("Applied patch %s (forced; needs refresh)" % patch.get_name()) else: self.applied_patch(patch) def _check(self): if not self.series.exists() or not self.series.patches(): raise NoPatchesInSeries(self.series) top = self.db.top_patch() if top is not None: refresh = top.get_name() + "~refresh" refresh = os.path.join(self.quilt_pc.get_name(), refresh) if os.path.exists(refresh): raise QuiltError("Patch %s needs to be refreshed" % \ top.get_name()) def apply_patch(self, patch_name, force=False, quiet=False): """ Apply all patches up to patch_name """ self._check() patch = Patch(patch_name) patches = self.series.patches_until(patch)[:] applied = self.db.applied_patches() for patch in applied: if patch in patches: patches.remove(patch) if not patches: raise AllPatchesApplied(self.series, self.db.top_patch()) self.applying(patch) try: for cur_patch in patches: self._apply_patch(cur_patch, force, quiet) finally: self.db.save() self.applied(self.db.top_patch()) def apply_next_patch(self, force=False, quiet=False): """ Apply next patch in series file """ self._check() top = self.db.top_patch() if not top: patch = self.series.first_patch() else: patch = self.series.patch_after(top) if not patch: raise AllPatchesApplied(self.series, top) self.applying(patch) self._apply_patch(patch, force, quiet) self.db.save() self.applied(self.db.top_patch()) def apply_all(self, force=False, quiet=False): """ Apply all patches in series file """ self._check() top = self.db.top_patch() if top: patches = self.series.patches_after(top) else: patches = self.series.patches() if not patches: raise AllPatchesApplied(self.series, top) try: for patch in patches: self.applying(patch) self._apply_patch(patch, force, quiet) finally: self.db.save() self.applied(self.db.top_patch())