From 3889f1f8d40cb6fa72a42f06304f40fbb8cabd41 Mon Sep 17 00:00:00 2001 From: Steven Walter Date: Tue, 5 Aug 2008 08:31:59 -0400 Subject: [PATCH] Port plugins to the new plugin API --- plugins/backup.py | 12 ++++++------ plugins/svn.py | 44 +++++++++++++++++++++----------------------- plugins/tcommit.py | 25 +++++++++++++++---------- 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/plugins/backup.py b/plugins/backup.py index 621592b..0031a17 100644 --- a/plugins/backup.py +++ b/plugins/backup.py @@ -1,15 +1,14 @@ -from yap import YapPlugin, YapError +from yap.yap import YapCore, YapError import os -class BackupPlugin(YapPlugin): +class BackupPlugin(YapCore): "Save a backup of files before reverting them" - def __init__(self, yap): - self.yap = yap - def pre_revert(self, args, flags): + def cmd_revert(self, *args, **flags): files = set(args) - changed = set(self.yap._get_staged_files() + self.yap._get_unstaged_files()) + changed = set(self._get_staged_files() + self._get_unstaged_files()) + if '-a' in flags: x = changed else: @@ -17,3 +16,4 @@ class BackupPlugin(YapPlugin): for f in x: os.system("cp %s %s~" % (f, f)) + super(BackupPlugin, self).cmd_revert(*args, **flags) diff --git a/plugins/svn.py b/plugins/svn.py index e34414c..84e4b32 100644 --- a/plugins/svn.py +++ b/plugins/svn.py @@ -1,5 +1,5 @@ -from yap import YapPlugin, YapError +from yap.yap import YapCore, YapError from yap.util import get_output, takes_options, run_command, run_safely, short_help import os @@ -32,11 +32,8 @@ class RepoBlob(object): data = file(revmap[0]).read() self.metadata[branch] = data -class SvnPlugin(YapPlugin): +class SvnPlugin(YapCore): "Allow yap to interoperate with Subversion repositories" - def __init__(self, yap): - self.yap = yap - def _get_root(self, url): root = get_output("svn info %s 2>/dev/null | gawk '/Repository Root:/{print $3}'" % url) if not root: @@ -59,7 +56,7 @@ class SvnPlugin(YapPlugin): tags = trunk.replace('trunk', 'tags') if tags != trunk: os.system("git config svn-remote.svn.tags %s/*:refs/tags/*" % tags) - self.yap.cmd_repo("svn", url) + self.cmd_repo("svn", url) os.system("git config yap.svn.enabled 1") def _create_tagged_blob(self): @@ -90,7 +87,7 @@ class SvnPlugin(YapPlugin): raise YapError("Directory exists: %s" % directory) os.chdir(directory) - self.yap.cmd_init() + self.cmd_init() run_command("git config svn-remote.svn.noMetadata 1") self._configure_repo(url) os.system("git svn fetch -r %s:HEAD" % flags.get('-r', '1')) @@ -131,7 +128,7 @@ class SvnPlugin(YapPlugin): os.system("git format-patch -k --stdout '%s' > %s" % (base[0], tmpfile)) start = get_output("git rev-parse HEAD") - self.yap.cmd_point("refs/remotes/svn/%s" + self.cmd_point("refs/remotes/svn/%s" % branch, **{'-f': True}) stat = os.stat(tmpfile) @@ -139,7 +136,7 @@ class SvnPlugin(YapPlugin): if size > 0: rc = run_command("git am -3 %s" % tmpfile) if (rc): - self.yap.cmd_point(start[0], **{'-f': True}) + self.cmd_point(start[0], **{'-f': True}) raise YapError("Failed to port changes to new svn branch") finally: os.unlink(tmpfile) @@ -151,7 +148,7 @@ class SvnPlugin(YapPlugin): if not current: raise YapError("Not on a branch!") current = current[0].replace('refs/heads/', '') - self.yap._confirm_push(current, branch, "svn") + self._confirm_push(current, branch, "svn") if run_command("git update-index --refresh"): raise YapError("Can't push with uncommitted changes") @@ -168,14 +165,16 @@ class SvnPlugin(YapPlugin): return bool(enabled) # Ensure users don't accidentally kill our "svn" repo - def pre_repo(self, args, flags): - if not self._enabled(): - return - if '-d' in flags and args and args[0] == "svn": - raise YapError("Refusing to delete special svn repository") + def cmd_repo(self, *args, **flags): + if self._enabled(): + if '-d' in flags and args and args[0] == "svn": + raise YapError("Refusing to delete special svn repository") + super(SvnPlugin, self).cmd_repo(*args, **flags) # Configure git-svn if we just cloned a yap-svn repo - def post_clone(self): + def cmd_clone(self, *args, **flags): + super(SvnPlugin, self).cmd_clone(*args, **flags) + if self._enabled(): # nothing to do return @@ -205,7 +204,7 @@ class SvnPlugin(YapPlugin): if args and not run_command("svn info %s" % args[0]): self._clone_svn(*args, **flags) else: - self.yap._call_base("cmd_clone", *args, **flags) + super(SvnPlugin, self).cmd_clone(*args, **flags) def cmd_fetch(self, *args, **flags): if self._enabled(): @@ -219,12 +218,12 @@ class SvnPlugin(YapPlugin): raise YapError("Not on a branch!") current = current[0].replace('refs/heads/', '') - remote, merge = self.yap._get_tracking(current) + remote, merge = self._get_tracking(current) if remote == "svn": os.system("git svn fetch svn") self._create_tagged_blob() return - self.yap._call_base("cmd_fetch", *args, **flags) + super(SvnPlugin, self).cmd_fetch(*args, **flags) def cmd_push(self, *args, **flags): if self._enabled(): @@ -239,12 +238,11 @@ class SvnPlugin(YapPlugin): raise YapError("Not on a branch!") current = current[0].replace('refs/heads/', '') - remote, merge = self.yap._get_tracking(current) + remote, merge = self._get_tracking(current) if remote == "svn": self._push_svn(merge, **flags) return - - self.yap._call_base("cmd_push", *args, **flags) + super(SvnPlugin, self).cmd_push(*args, **flags) @short_help("change options for the svn plugin") def cmd_svn(self, subcmd): @@ -253,7 +251,7 @@ class SvnPlugin(YapPlugin): if subcmd not in ["enable"]: raise TypeError - if "svn" in [x[0] for x in self.yap._list_remotes()]: + if "svn" in [x[0] for x in self._list_remotes()]: raise YapError("A remote named 'svn' already exists") diff --git a/plugins/tcommit.py b/plugins/tcommit.py index 2c34d16..e6fd4b2 100644 --- a/plugins/tcommit.py +++ b/plugins/tcommit.py @@ -1,15 +1,12 @@ -from yap import YapPlugin +from yap.yap import YapCore from yap.util import get_output, takes_options import pickle import os -class TCommitPlugin(YapPlugin): +class TCommitPlugin(YapCore): "Provide a 'temporory commit' mechanism" - def __init__(self, yap): - self.yap = yap - def _add_branch(self, branch): repo = get_output("git rev-parse --git-dir") if not repo: @@ -48,15 +45,23 @@ class TCommitPlugin(YapPlugin): @takes_options("t") def cmd_commit(self, *args, **flags): if '-t' in flags: - self.yap.cmd_commit(*[], **{'-a': 1, '-m': 'yap wip'}) + override = True + args = [] + flags = {'-a': 1, '-m': 'yap wip'} + else: + override = False + + super(TCommitPlugin, self).cmd_commit(*args, **flags) + + if override is True: branch = get_output("git symbolic-ref HEAD") if branch: self._add_branch(branch[0]) - else: - self.yap._call_base("cmd_commit", *args, **flags) - def post_switch(self): + def cmd_switch(self, *args, **flags): + super(TCommitPlugin, self).cmd_switch(*args, **flags) + branch = get_output("git symbolic-ref HEAD") if branch[0] in self._get_branches(): - self.yap.cmd_uncommit() + self.cmd_uncommit() self._remove_branch(branch[0]) -- 2.11.4.GIT