Ejemplo n.º 1
0
    def cmd_sessions(self, *args):
        parser = argparse.ArgumentParser(prog="sessions", description="Open a file", epilog="List or switch sessions")
        group = parser.add_mutually_exclusive_group()
        group.add_argument("-l", "--list", action="store_true", help="List all existing sessions")
        group.add_argument("-s", "--switch", type=int, help="Switch to the specified session")

        try:
            args = parser.parse_args(args)
        except:
            return

        if args.list:
            if not __sessions__.sessions:
                self.log("info", "There are no opened sessions")
                return

            rows = []
            for session in __sessions__.sessions:
                current = ""
                if session == __sessions__.current:
                    current = "Yes"

                rows.append([session.id, session.file.name, session.file.md5, session.created_at, current])

            self.log("info", "Opened Sessions:")
            self.log("table", dict(header=["#", "Name", "MD5", "Created At", "Current"], rows=rows))
        elif args.switch:
            for session in __sessions__.sessions:
                if args.switch == session.id:
                    __sessions__.switch(session)
                    return

            self.log("warning", "The specified session ID doesn't seem to exist")
        else:
            parser.print_usage()
Ejemplo n.º 2
0
    def cmd_sessions(self, *args):
        def usage():
            print("usage: sessions [-h] [-l] [-s=session]")

        def help():
            usage()
            print("")
            print("Options:")
            print("\t--help (-h)\tShow this help message")
            print("\t--list (-l)\tList all existing sessions")
            print("\t--switch (-s)\tSwitch to the specified session")
            print("")

        try:
            opts, argv = getopt.getopt(args, "hls:", ["help", "list", "switch="])
        except getopt.GetoptError as e:
            print(e)
            usage()
            return

        arg_list = False
        arg_switch = None

        for opt, value in opts:
            if opt in ("-h", "--help"):
                help()
                return
            elif opt in ("-l", "--list"):
                arg_list = True
            elif opt in ("-s", "--switch"):
                arg_switch = int(value)

        if arg_list:
            if not __sessions__.sessions:
                print_info("There are no opened sessions")
                return

            rows = []
            for session in __sessions__.sessions:
                current = ""
                if session == __sessions__.current:
                    current = "Yes"

                rows.append([session.id, session.file.name, session.file.md5, session.created_at, current])

            print_info("Opened Sessions:")
            print(table(header=["#", "Name", "MD5", "Created At", "Current"], rows=rows))
            return
        elif arg_switch:
            for session in __sessions__.sessions:
                if arg_switch == session.id:
                    __sessions__.switch(session)
                    return

            print_warning("The specified session ID doesn't seem to exist")
            return

        usage()
Ejemplo n.º 3
0
    def cmd_sessions(self, *args):
        parser = argparse.ArgumentParser(prog='sessions',
                                         description="Open a file",
                                         epilog="List or switch sessions")
        group = parser.add_mutually_exclusive_group()
        group.add_argument('-l',
                           '--list',
                           action='store_true',
                           help="List all existing sessions")
        group.add_argument('-s',
                           '--switch',
                           type=int,
                           help="Switch to the specified session")

        try:
            args = parser.parse_args(args)
        except:
            return

        if args.list:
            if not __sessions__.sessions:
                self.log('info', "There are no opened sessions")
                return

            rows = []
            for session in __sessions__.sessions:
                current = ''
                if session == __sessions__.current:
                    current = 'Yes'

                rows.append([
                    session.id, session.file.name, session.file.md5,
                    session.created_at, current
                ])

            self.log('info', "Opened Sessions:")
            self.log(
                "table",
                dict(header=['#', 'Name', 'MD5', 'Created At', 'Current'],
                     rows=rows))
        elif args.switch:
            for session in __sessions__.sessions:
                if args.switch == session.id:
                    __sessions__.switch(session)
                    return

            self.log('warning',
                     "The specified session ID doesn't seem to exist")
        else:
            parser.print_usage()
Ejemplo n.º 4
0
    def cmd_sessions(self, *args):
        parser = argparse.ArgumentParser(prog='sessions', description="Open a file", epilog="List or switch sessions")
        group = parser.add_mutually_exclusive_group()
        group.add_argument('-l', '--list', action='store_true', help="List all existing sessions")
        group.add_argument('-s', '--switch', type=int, help="Switch to the specified session")

        try:
            args = parser.parse_args(args)
        except:
            return

        if args.list:
            if not __sessions__.sessions:
                self.log('info', "There are no opened sessions")
                return

            rows = []
            for session in __sessions__.sessions:
                current = ''
                if session == __sessions__.current:
                    current = 'Yes'

                rows.append([
                    session.id,
                    session.file.name,
                    session.file.md5,
                    session.created_at,
                    current
                ])

            self.log('info', "Opened Sessions:")
            self.log("table", dict(header=['#', 'Name', 'MD5', 'Created At', 'Current'], rows=rows))
        elif args.switch:
            for session in __sessions__.sessions:
                if args.switch == session.id:
                    __sessions__.switch(session)
                    return

            self.log('warning', "The specified session ID doesn't seem to exist")
        else:
            parser.print_usage()
Ejemplo n.º 5
0
    def run(self, *args):
        try:
            args = self.parser.parse_args(args)
        except SystemExit:
            return

        if args.list:
            if not __sessions__.sessions:
                self.log('info', "There are no opened sessions")
                return

            rows = []
            for session in __sessions__.sessions:
                current = ''
                if session == __sessions__.current:
                    current = 'Yes'

                rows.append([
                    session.id, session.file.name, session.file.md5,
                    session.created_at, current
                ])

            self.log('info', "Opened Sessions:")
            self.log(
                "table",
                dict(header=['#', 'Name', 'MD5', 'Created At', 'Current'],
                     rows=rows))
        elif args.switch:
            for session in __sessions__.sessions:
                if args.switch == session.id:
                    __sessions__.switch(session)
                    return

            self.log('warning',
                     "The specified session ID doesn't seem to exist")
        else:
            self.parser.print_usage()
Ejemplo n.º 6
0
    def run(self, *args):
        try:
            args = self.parser.parse_args(args)
        except SystemExit:
            return

        if args.list:
            if not __sessions__.sessions:
                self.log('info', "There are no opened sessions")
                return

            rows = []
            for session in __sessions__.sessions:
                current = ''
                if session == __sessions__.current:
                    current = 'Yes'

                rows.append([
                    session.id,
                    session.file.name,
                    session.file.md5,
                    session.created_at,
                    current
                ])

            self.log('info', "Opened Sessions:")
            self.log("table", dict(header=['#', 'Name', 'MD5', 'Created At', 'Current'], rows=rows))
        elif args.switch:
            for session in __sessions__.sessions:
                if args.switch == session.id:
                    __sessions__.switch(session)
                    return

            self.log('warning', "The specified session ID doesn't seem to exist")
        else:
            self.parser.print_usage()
Ejemplo n.º 7
0
    def cmd_sessions(self, *args):
        def usage():
            print("usage: sessions [-h] [-l] [-s=session]")

        def help():
            usage()
            print("")
            print("Options:")
            print("\t--help (-h)\tShow this help message")
            print("\t--list (-l)\tList all existing sessions")
            print("\t--switch (-s)\tSwitch to the specified session")
            print("")

        try:
            opts, argv = getopt.getopt(args, 'hls:',
                                       ['help', 'list', 'switch='])
        except getopt.GetoptError as e:
            print(e)
            usage()
            return

        arg_list = False
        arg_switch = None

        for opt, value in opts:
            if opt in ('-h', '--help'):
                help()
                return
            elif opt in ('-l', '--list'):
                arg_list = True
            elif opt in ('-s', '--switch'):
                arg_switch = int(value)

        if arg_list:
            if not __sessions__.sessions:
                print_info("There are no opened sessions")
                return

            rows = []
            for session in __sessions__.sessions:
                current = ''
                if session == __sessions__.current:
                    current = 'Yes'

                rows.append([
                    session.id, session.file.name, session.file.md5,
                    session.created_at, current
                ])

            print_info("Opened Sessions:")
            print(
                table(header=['#', 'Name', 'MD5', 'Created At', 'Current'],
                      rows=rows))
            return
        elif arg_switch:
            for session in __sessions__.sessions:
                if arg_switch == session.id:
                    __sessions__.switch(session)
                    return

            print_warning("The specified session ID doesn't seem to exist")
            return

        usage()
Ejemplo n.º 8
0
    def cmd_sessions(self, *args):
        def usage():
            print("usage: sessions [-h] [-l] [-s=session]")

        def help():
            usage()
            print("")
            print("Options:")
            print("\t--help (-h)\tShow this help message")
            print("\t--list (-l)\tList all existing sessions")
            print("\t--switch (-s)\tSwitch to the specified session")
            print("")

        try:
            opts, argv = getopt.getopt(args, 'hls:', ['help', 'list', 'switch='])
        except getopt.GetoptError as e:
            print(e)
            usage()
            return

        arg_list = False
        arg_switch = None

        for opt, value in opts:
            if opt in ('-h', '--help'):
                help()
                return
            elif opt in ('-l', '--list'):
                arg_list = True
            elif opt in ('-s', '--switch'):
                arg_switch = int(value)

        if arg_list:
            if not __sessions__.sessions:
                print_info("There are no opened sessions")
                return

            rows = []
            for session in __sessions__.sessions:
                current = ''
                if session == __sessions__.current:
                    current = 'Yes'

                rows.append([
                    session.id,
                    session.file.name,
                    session.file.md5,
                    session.created_at,
                    current
                ])

            print_info("Opened Sessions:")
            print(table(header=['#', 'Name', 'MD5', 'Created At', 'Current'], rows=rows))
            return
        elif arg_switch:
            for session in __sessions__.sessions:
                if arg_switch == session.id:
                    __sessions__.switch(session)
                    return

            print_warning("The specified session ID doesn't seem to exist")
            return

        usage()