def do_is_admin(self, arg):
        """ is_admin [user] """
        cmds = arg.split()
        if validate_user(cmds[0]):

            res = self.multi_q.is_user_admin(cmds[0])
            print generate_table(table_contents_to_s(res))
    def do_is_admin(self, arg):
        """ is_admin [user] """
        cmds = arg.split()
        if validate_user(cmds[0]):

            res = self.multi_q.is_user_admin(cmds[0])
            print generate_table(table_contents_to_s(res))
    def do_users(self, arg):
        args = arg.split()
        if len(args) == 0 or args[0] not in self.services:
            print("Please specify a valid service")
            return

        service = self.services[args[0]]
        users = {"Users": service.users()}
        print generate_table(users)
    def do_is_admin(self, arg):
        from global_query import is_user_admin_in
        print "Enter user email address"
        user = raw_input("> ")
        services = ["google", "hipchat", "slack"]
        result = is_user_admin_in(user, services)

        # convert values to lists with strings
        for key in result:
            result[key] = [str(result[key])]
        print generate_table(result)
 def do_get_groups(self, arg):
     """ get_groups [service] [user] """
     # yes: slack, google, asana,
     cmds = arg.split()
     if len(cmds) == 2:
         service = self.services[cmds[0]]
         user = cmds[1]
         groups = {"Groups": service.get_user_groups(user)}
         print(generate_table(groups))
     else:
         service = self.services[cmds[0]]
         groups = {"Groups": service.all_groups()}
         print(generate_table(groups))
 def do_get_groups(self, arg):
     """ get_groups [service] [user] """
     # yes: slack, google, asana,
     cmds = arg.split()
     if len(cmds) == 2:
         service = self.services[cmds[0]]
         user = cmds[1]
         groups = {"Groups": service.get_user_groups(user)}
         print(generate_table(groups))
     else:
         service = self.services[cmds[0]]
         groups = {"Groups": service.all_groups()}
         print(generate_table(groups))
    def do_get_members(self, arg):
        """ get_members [service] [group] """
        cmds = arg.split()
        if validate_i_in_list(cmds[0], ["google", "slack", "asana", "hipchat"]):

            service = self.services[cmds[0]]
            cmds.pop(0)
            group = ""
            for i in cmds:
                group += i + " "
            group = group.strip().lower()
            members = {group: service.get_members(group)}
            print generate_table(members)
    def do_get_members(self, arg):
        """ get_members [service] [group] """
        cmds = arg.split()
        if validate_i_in_list(cmds[0],
                              ["google", "slack", "asana", "hipchat"]):

            service = self.services[cmds[0]]
            cmds.pop(0)
            group = ""
            for i in cmds:
                group += i + " "
            group = group.strip().lower()
            members = {group: service.get_members(group)}
            print generate_table(members)
    def do_get_users(self, arg):
        """ get_users [service] """
        cmds = arg.split()
        if validate_i_in_list(cmds[0], ["google", "asana", "slack", "hipchat"]):

            service = self.services[cmds[0]]
            users = {"Users": service.all_users()}
            print(generate_table(users))
    def do_get_users(self, arg):
        """ get_users [service] """
        cmds = arg.split()
        if validate_i_in_list(cmds[0],
                              ["google", "asana", "slack", "hipchat"]):

            service = self.services[cmds[0]]
            users = {"Users": service.all_users()}
            print(generate_table(users))
    def do_get_user(self, arg):
        """ get_user [service] [user] """
        # yes: slack, google, asana, hipchat
        cmds = arg.split()
        if len(cmds) == 2:
            service = self.services[cmds[0]]
            user = cmds[1].lower()
            pprint(service.get_user(user))

        elif "@" in cmds[0]:
            res = self.multi_q.is_user(cmds[0].lower())
            print generate_table(table_contents_to_s(res))

        elif cmds[0] not in self.services:
            print("Please specify a valid service")

        else:
            service = self.services[cmds[0].lower()]
            if len(cmds) > 1:
                pprint(service.get_user(cmds[1].lower()))
            else:
                user = raw_input("Please enter a valid email address: ")
                pprint(service.get_user(user))
    def do_get_user(self, arg):
        """ get_user [service] [user] """
        # yes: slack, google, asana, hipchat
        cmds = arg.split()
        if len(cmds) == 2:
            service = self.services[cmds[0]]
            user = cmds[1].lower()
            pprint(service.get_user(user))

        elif "@" in cmds[0]:
            res = self.multi_q.is_user(cmds[0].lower())
            print generate_table(table_contents_to_s(res))

        elif cmds[0] not in self.services:
            print("Please specify a valid service")

        else:
            service = self.services[cmds[0].lower()]
            if len(cmds) > 1:
                pprint(service.get_user(cmds[1].lower()))
            else:
                user = raw_input("Please enter a valid email address: ")
                pprint(service.get_user(user))
 def do_list_hipchat_users(self, arg):
     import hipchat_create as hc
     users = dict(Users=hc.all_users())
     print generate_table(users)
 def do_list_slack_users(self, arg):
     import slack_create as sc
     users = dict(Users=sc.all_users())
     print generate_table(users)
 def do_list_google_users(self, arg):
     import google_create as gc
     users = dict(Users=gc.all_users())
     print generate_table(users)