#!/usr/bin/env python3

# http://inamidst.com/saxo/
# Created by Sean B. Palmer

import os
import saxo

@saxo.command(authorised=True, private=True)
def off(arg):
    if not arg:
        return "Turn a command off"

    if "." in arg:
        return "Refusing to touch commands containing '.'"

    base = saxo.env("base")
    command = os.path.join(base, "commands", arg)

    if os.path.islink(command):
        os.remove(command)
        with open(command, "w") as f:
            f.write("")
        return "Replaced symlink commands/%s with an empty file" % arg
    elif os.path.isfile(command):
        os.chmod(command, 0o644)
        return "Changed permissions of commands/%s to 644" % arg
    elif os.path.exists(command):
        return "Error: Command is neither a symlink nor a regular file"
    return "Error: No such command"
