コード例 #1
0
class PopCommand(Command):

    name = "pop"
    help = "Remove patch(es) from the stack of applied patches."

    all = OptionArgument("-a", "--all", dest="all", action="store_true",
                         help="remove all applied patches")

    patch = Argument(nargs="?")

    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 unapplying(self, patch):
        print("Removing patch %s" % patch.get_name())

    def unapplied(self, patch):
        if not patch:
            print("No patches applied")
        else:
            print("Now at patch %s" % patch.get_name())

    def empty_patch(self, patch):
        print("Patch %s appears to be empty, removing" % patch.get_name())
コード例 #2
0
ファイル: add.py プロジェクト: jayvdb/python-quilt
class AddCommand(Command):

    name = "add"
    help = "Add one or more files to the topmost or named patch."

    patch = OptionArgument("-p",
                           help="patch to add files to",
                           metavar="PATCH",
                           dest="patch")
    file = Argument(nargs="+")

    def add_args(self, parser):
        parser.add_option("-p",
                          help="patch to add files to",
                          metavar="PATCH",
                          dest="patch")

    def run(self, args):
        add = Add(os.getcwd(), self.get_pc_dir(), self.get_patches_dir())
        add.file_added.connect(self.file_added)
        add.add_files(args.file, args.patch)

    def file_added(self, file, patch):
        print("File %s added to patch %s" %
              (file.get_name(), patch.get_name()))
コード例 #3
0
class RefreshCommand(Command):

    name = "refresh"
    help = "Refreshes the specified patch, or the topmost patch by default."

    edit = OptionArgument("-e",
                          dest="edit",
                          action="store_true",
                          default=False,
                          help="open patch in editor before refreshing")
    patch = Argument(nargs="?")

    def run(self, args):
        refresh = Refresh(os.getcwd(), self.get_pc_dir(),
                          self.get_patches_dir())

        refresh.refreshed.connect(self.refreshed)

        if args.edit:
            refresh.edit_patch.connect(self.edit_patch)

        refresh.refresh(args.patch, args.edit)

    def edit_patch(self, tmpfile):
        editor = os.environ.get("EDITOR", "vi")
        try:
            cmd = [editor]
            cmd.append(tmpfile.get_name())
            Process(cmd).run(cwd=os.getcwd())
        except SubprocessError as e:
            self.exit_error(e, value=e.returncode)

    def refreshed(self, patch):
        print("Patch %s refreshed" % patch.get_name())
コード例 #4
0
ファイル: delete.py プロジェクト: jayvdb/python-quilt
class DeleteCommand(Command):

    name = "delete"
    help = "Remove the specified or topmost patch from the series file."

    remove = OptionArgument("-r",
                            action="store_true",
                            dest="remove",
                            default=False,
                            help="Remove the deleted patch file from the "
                            "patches directory as well.")
    backup = OptionArgument("--backup",
                            action="store_true",
                            default=False,
                            dest="backup",
                            help="Rename the patch file to patch~ rather than "
                            "deleting it. Ignored if not used with `-r'.")
    next = OptionArgument("-n",
                          action="store_true",
                          dest="next",
                          help="Delete the next unapplied patch, "
                          "rather than the specified or topmost patch.")
    patch = Argument(nargs="?")

    def run(self, args):
        delete = Delete(self.get_cwd(), self.get_pc_dir(),
                        self.get_patches_dir())
        delete.deleted_patch.connect(self.deleted_patch)
        delete.deleting_patch.connect(self.deleting_patch)

        if args.next and args.patch:
            self.exit_error("-n parameter doesn't take an argument")

        if args.next:
            delete.delete_next(args.remove, args.backup)
        else:
            delete.delete_patch(args.patch, args.remove, args.backup)

    def deleted_patch(self, patch):
        print("Removed patch %s" % patch.get_name())

    def deleting_patch(self, patch, applied):
        if applied:
            print("Removing currently applied patch %s" % patch.get_name())
        else:
            print("Removing patch %s" % patch.get_name())
コード例 #5
0
ファイル: push.py プロジェクト: jayvdb/python-quilt
class PushCommand(Command):

    name = "push"
    help = " Apply  patch(es)  from the series file."

    all = OptionArgument("-a",
                         dest="all",
                         action="store_true",
                         help="apply all patches in series")
    force = OptionArgument("-f",
                           dest="force",
                           action="store_true",
                           default=False,
                           help="Force apply, even if the patch has rejects.")
    patch = Argument(nargs="?")

    def run(self, args):
        push = Push(self.get_cwd(), self.get_pc_dir(), self.get_patches_dir())
        push.applying_patch.connect(self.applying_patch)
        push.applied.connect(self.applied)
        push.applied_empty_patch.connect(self.applied_empty_patch)

        if args.all:
            push.apply_all(args.force)
        elif args.patch:
            push.apply_patch(args.patch, args.force)
        else:
            push.apply_next_patch(args.force)

    def applying_patch(self, patch):
        print("Applying patch %s" % patch.get_name())

    def applied(self, patch):
        print("Now at patch %s" % patch.get_name())

    def applied_empty_patch(self, patch, exists):
        if exists:
            print("Patch %s appears to be empty; applied" % patch.get_name())
        else:
            print("Patch %s does not exist; applied empty patch" %
                  patch.get_name())
コード例 #6
0
ファイル: patchimport.py プロジェクト: jayvdb/python-quilt
class PatchImportCommand(Command):

    name = "import"
    help = "Import external patches."

    patchname = OptionArgument("-P", metavar="NAME", dest="patchname",
                               help="Import patch as NAME. This option can "
                               "only be used when importing a single patch.")
    patchfile = Argument(nargs="+")

    def run(self, args):
        importp = Import(os.getcwd(), self.get_pc_dir(),
                         self.get_patches_dir())

        if args.patchname:
            if len(args.patchfile) > 1:
                self.exit_error("It's only possible to rename a patch if one "
                                "patch will be imported.")
            importp.import_patch(args.patchfile[0], args.patchname)
        else:
            importp.import_patches(args.patchfile)
コード例 #7
0
ファイル: revert.py プロジェクト: jayvdb/python-quilt
class RevertCommand(Command):

    name = "revert"
    help = "Revert  uncommitted  changes  to  the  topmost  or  named  " \
           "patch for the specified file(s)."

    patch = OptionArgument("-p", metavar="PATCH", dest="patch",
                           help="revert changes in the named patch")
    file = Argument(nargs="+")

    def run(self, args):
        revert = Revert(os.getcwd(), self.get_pc_dir(), self.get_patches_dir())
        revert.file_reverted.connect(self.file_reverted)
        revert.file_unchanged.connect(self.file_unchanged)
        revert.revert_files(args.file, args.patch)

    def file_reverted(self, file, patch):
        print("Changes to %s in patch %s reverted" % (file.get_name(),
                                                      patch.get_name()))

    def file_unchanged(self, file, patch):
        print("File %s is unchanged" % file.get_name())
コード例 #8
0
ファイル: series.py プロジェクト: jayvdb/python-quilt
class SeriesCommand(Command):

    name = "series"
    help = "Print the names of all patches in the series file."

    v = OptionArgument(action="store_true", help="""indicate applied (+)
        and topmost (=) patches""")

    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())