def test_apply_next(self): patch1 = Patch("p1.patch") patch2 = Patch("p2.patch") test_dir = self.data_dir + "test1" with TmpDirectory(dir=self.data_dir.get_name()) as tmp_dir: tmp_test_dir = tmp_dir + "test2" test_dir.copy(tmp_test_dir) pc_dir = tmp_test_dir + "pc" patches_dir = tmp_test_dir + "patches" f1 = tmp_test_dir + File("f1") self.assertTrue(f1.exists()) f2 = tmp_test_dir + File("f2") self.assertTrue(f2.exists()) pop = Pop(tmp_test_dir.get_name(), pc_dir.get_name()) self.assertEquals(patch2, pop.db.top_patch()) pop.unapply_top_patch() self.assertEquals(patch1, pop.db.top_patch()) self.assertTrue(f1.exists()) self.assertFalse(f2.exists()) pop.unapply_top_patch() self.assertEquals(None, pop.db.top_patch()) self.assertFalse(f1.exists()) self.assertFalse(f2.exists())
def _pop(force=False): pop = Pop(os.getcwd(), pc_dir) try: pop.unapply_all(force) except QuiltError, e: print t.red('KO: Error applying patch:' + str(e)) return -1
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 unapply(self): """ Revert all patches""" from quilt.pop import Pop from quilt.error import NoAppliedPatch pop = Pop(self.work_dir, os.path.join(self.work_dir, ".pc")) try: pop.unapply_all() except NoAppliedPatch, e: print e
def pop(self): """ Revert last patch """ from quilt.pop import Pop from quilt.error import NoAppliedPatch pop = Pop(self.work_dir, os.path.join(self.work_dir, ".pc")) try: pop.unapply_top_patch() except NoAppliedPatch, e: print e
def test_unrefreshed(self): with TmpDirectory() as dir: db = Db(dir.get_name()) db.add_patch(Patch("unrefreshed.patch")) db.save() make_file(b"", db.dirname, "unrefreshed.patch~refresh") cmd = Pop(dir.get_name(), db.dirname) with six.assertRaisesRegex(self, QuiltError, r"needs to be refreshed"): cmd.unapply_top_patch()
def _pop(force=False): pop = Pop(os.getcwd(), pc_dir) try: pop.unapply_all(force) except QuiltError as e: print(t.red('KO: Error applying patch:' + str(e))) return -1 except UnknownPatch as e: print(t.red('KO: Error applying patch:' + str(e))) return -1 print(t.green('OK: All Patches removed')) return 0
def run(self, args): pop = Pop(os.getcwd(), self.get_pc_dir()) pop.unapplying.connect(self.unapplying) pop.unapplied.connect(self.unapplied) pop.empty_patch.connect(self.empty_patch) if args.all: pop.unapply_all() elif args.patch: pop.unapply_patch(args.patch) else: pop.unapply_top_patch()
def test_apply_next(self): patch1 = Patch("p1.patch") patch2 = Patch("p2.patch") test_dir = self.data_dir + "test1" with TmpDirectory(dir=self.data_dir.get_name()) as tmp_dir: tmp_test_dir = tmp_dir + "test2" test_dir.copy(tmp_test_dir) pc_dir = tmp_test_dir + "pc" f1 = tmp_test_dir + File("f1") self.assertTrue(f1.exists()) f2 = tmp_test_dir + File("f2") self.assertTrue(f2.exists()) pop = Pop(tmp_test_dir.get_name(), pc_dir.get_name()) self.assertEqual(patch2, pop.db.top_patch()) pop.unapply_top_patch() self.assertEqual(patch1, pop.db.top_patch()) self.assertTrue(f1.exists()) self.assertFalse(f2.exists()) pop.unapply_top_patch() self.assertEqual(None, pop.db.top_patch()) self.assertFalse(f1.exists()) self.assertFalse(f2.exists())
def run(self, options, args): pop = Pop(os.getcwd(), self.get_pc_dir()) pop.unapplying.connect(self.unapplying) pop.unapplied.connect(self.unapplied) pop.empty_patch.connect(self.empty_patch) if options.all: pop.unapply_all() elif not args: pop.unapply_top_patch() else: pop.unapply_patch(args[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)