Procházet zdrojové kódy

more sub-commands for git; quote info in help, and add a reply function to irc actions to automatically reply to a nick

tags/v0.1
Ben Kurtovic před 13 roky
rodič
revize
0478d0934e
3 změnil soubory, kde provedl 53 přidání a 7 odebrání
  1. +4
    -0
      irc/actions.py
  2. +47
    -5
      irc/commands/git.py
  3. +2
    -2
      irc/commands/help.py

+ 4
- 0
irc/actions.py Zobrazit soubor

@@ -23,6 +23,10 @@ class Actions:
"""send a message"""
self.send("PRIVMSG %s :%s" % (target, msg))

def reply(self, target, nick, msg):
"""send a message as a reply"""
self.say(target, "%s%s%s: %s" % (chr(2), nick, chr(0x0f), msg))

def action(self, target, msg):
"""send a message as an action"""
self.say(target,"%sACTION %s%s" % (chr(1), msg, chr(1)))


+ 47
- 5
irc/commands/git.py Zobrazit soubor

@@ -31,9 +31,15 @@ def call(a, d):
elif data.args[0] == "checkout":
do_checkout()

elif data.args[0] == "delete":
do_delete()

elif data.args[0] == "pull":
do_pull()

elif data.args[0] == "status":
do_status()

else: # they asked us to do something we don't know
actions.say(data.chan, "\x02%s\x0F: unknown argument: \x0303%s\x0301." % (data.nick, data.args[0]))

@@ -45,11 +51,20 @@ def exec_shell(command):

def do_help():
"""display all commands"""
help = ["\x0303branch\x0301 (show current branch)", "\x0303branches\x0301 (show all branches)",
"\x0303checkout\x0301 (switch branches)", "\x0303pull\x0301 (update current branch)"]
help = ', '.join(help)

actions.say(data.chan, "\x02%s\x0F: sub-commands are: %s" % (data.nick, help))
help_dict = {
"branch": "get current branch",
"branches": "get all branches",
"checkout": "switch branches",
"delete": "delete an old branch",
"pull": "update everything from the remote server",
"status": "check if we are out of date"
}
help = ""
for key in help_dict.keys():
help += "\x0303%s\x0301: (%s)," % (key, help_dict[key])
help = help[:-1] # trim last comma

actions.say(data.chan, "\x02%s\x0F: sub-commands are: %s." % (data.nick, help))

def do_branch():
"""get our current branch"""
@@ -88,6 +103,25 @@ def do_checkout():
except subprocess.CalledProcessError: # git couldn't switch branches
actions.say(data.chan, "\x02%s\x0F: branch \x0302%s\x0301 does not exist!" % (data.nick, branch))

def do_delete():
"""delete a branch, while making sure that we are not on it"""
try:
delete_branch = data.args[1]
except IndexError: # no branch name provided
actions.say(data.chan, "\x02%s\x0F: delete which branch?" % data.nick)
return

current_branch = exec_shell("git name-rev --name-only HEAD")
current_branch = current_branch[:-1] # strip newline

if current_branch == delete_branch:
actions.say(data.chan, "\x02%s\x0F: you're currently on this branch; please checkout to a different branch before deleting." % data.nick)
return

exec_shell("git branch -d %s" % delete_branch)

actions.say(data.chan, "\x02%s\x0F: branch \x0302%s\x0301 has been deleted locally." % (data.nick, delete_branch))

def do_pull():
"""pull from remote repository"""
branch = exec_shell("git name-rev --name-only HEAD")
@@ -100,3 +134,11 @@ def do_pull():
actions.say(data.chan, "\x02%s\x0F: done; no new changes." % data.nick)
else:
actions.say(data.chan, "\x02%s\x0F: done; new changes merged." % data.nick)

def do_status():
"""check whether we have anything to pull"""
result = exec_shell("git fetch --dry-run")
if not result:
actions.say(data.chan, "\x02%s\x0F: local copy is up-to-date with remote." % data.nick)
else:
actions.say(data.chan, "\x02%s\x0F: remote is ahead of local copy." % (data.nick))

+ 2
- 2
irc/commands/help.py Zobrazit soubor

@@ -19,7 +19,7 @@ def do_general_help():

def do_command_help():
command = data.args[0]
try:
exec "from irc.commands import %s as this_command" % command
except ImportError:
@@ -29,6 +29,6 @@ def do_command_help():
info = this_command.__doc__

if info:
actions.say(data.chan, "\x02%s\x0F: Info for command \x0303%s\x0301: %s" % (data.nick, command, info))
actions.say(data.chan, "\x02%s\x0F: Info for command \"\x0303%s\x0301: %s\"" % (data.nick, command, info))
else:
actions.say(data.chan, "\x02%s\x0F: Sorry, no information for \x0303%s\x0301." % (data.nick, command))

Načítá se…
Zrušit
Uložit