<commit_before>#!/usr/bin/env python
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

import ast
import cmd
import readline
import sys
import traceback
import types
from src.console_controller import ConsoleController

def try_catch(command, args=None):
    try:
        if args is not None:
            return command(*args)
        else:
            return command()
    except:
        print("Sorry, that command raised an exception. Here's what I know:\n")
        print(traceback.format_exc())
        
###################################################################################################
# Define a custom cmd line base class to fix some bugs in cmd.Cmd
###################################################################################################

# TODO This class introduces some cool opportunities - we might be able to put all the duplicated
# functionality of subconsoles (i.e. home related code) into this class so the subconsoles' code
# can be more concise

class GagCmdBase(cmd.Cmd):

    def __init__(self):
        cmd.Cmd.__init__(self)
        self.helptext = ""
        readline.set_history_length(1000)
        try:
            readline.read_history_file('.gaghistory')
        except IOError:
            sys.stderr.write("No .gaghistory file available...\n")
        
    def get_names(self):
        return dir(self)

    def precmd(self, line):
        readline.write_history_file('.gaghistory')
        return line

    def emptyline(self):
        print(self.helptext)

###################################################################################################
# End cmd base class
###################################################################################################

class GagCmd(GagCmdBase):

## Setup, loading and saving sessions, exit, etc.

    intro = "                                                                                \n                                        ,,                                      \n              ~++=:,                  =OMNZ:                  :=?77I=,          \n           :7DMMMMMMD7:              ~DMMMMZ               =$DMMMMMMMM8+        \n         :7NMMMMMMMMMMN7,            $MMMMMN=            ~ZMMMMMMMMMMMMZ,       \n        ?NMMMNZ+~+IONMMN?           INMMNMMMI           INMMMDZ?~,,:+I?:        \n       +NMMN7:      :?$I:          INMMNZMMMZ         :$MMMD?                   \n      :8MMM?                      7MMMD+=NMM8,       :OMMMO~                    \n      7MMMZ,                     7MMMD= ,8MMM?       ZMMMZ,                     \n     :8MMN+                    ,$MMMN+   IMMMO      ~NMMD~     ,+$ZI+==~,       \n     ~DMMD~    ~7OZ$Z8NNZ:    +DMMMD$I?~:~DMMN+     +NMM8      IMMMMMMMMO:      \n      $MMM8:   ,OMMMMMMMN=   INMMN$$MMMMMMMMMMZ     ~DMMMI     ~8MMMMMMMZ:      \n      ,ZMMMD?,   ?NMMMNZ~   INMMD+ =ONMMMMMMMMN~     +DMMM$:     ,=$MMMD:       \n       ,$MMMMM87+IONMMMI   ?NMMN=     :=+??OMMM$      =8MMMM87=, ,+8MMMZ        \n         +8MMMMMMMMMMMO~  ~D0GE?           =NMM$       :$NMMMMMMNMMMMMO:        \n           :I8NMMMMNO+,   :OMD?             +Z7~         :I8NMMMMMMMDI,         \n               :~~:        ,,,                               ~?7$7?~            \n                                                                                \n                                                                                "+\
    "\nWelcome to the GAG console!\n"+\
    "Type 'help' for available commands.\n"

    no_genome_message = "\nIt looks like no genome is currently loaded. Try the 'load' command.\n"+\
            "Type 'help load' to learn how to use it, or just 'help' for general advice.\n"

    def __init__(self):
        GagCmdBase.__init__(self)
        self.prompt = "GAG> "
        self.controller = ConsoleController() 

    def precmd(self, line):
        line = GagCmdBase.precmd(self, line)
        print('----------------------------------------')
        return line
        
    def postcmd(self, stop, line):
        stop = GagCmdBase.postcmd(self, stop, line)
        print('----------------------------------------')
        return stop

    def help_load(self):
        print("\nThis command takes you the GAG LOAD menu. There you can specify the location of")
        print("your files and load them into memory.")
        print("Alternately, just type 'load <path>' and avoid the submenu altogether.\n")

    def do_load(self, line):
        path_to_load = line.strip()
        loadcmd = LoadCmd(self.prompt, self.controller, path_to_load)
        loadcmd.cmdloop()

    def help_flag(self):
        print("\nThis command takes you to the GAG FLAG menu. There you can flag features based")
        print("on certain criteria to mark suspicious data. Alternately, just type:\n")
        print("'remove <criteria> <value>'\n")
        print("if you've done this before :)\n")

    def do_flag(self, line):
        if self.controller.genome_is_loaded():
            filtercmd = FlagCmd(self.prompt, self.controller, line)
            filtercmd.cmdloop()
        else:
            print(self.no_genome_message)
    
    def help_remove(self):
        print("\nThis command takes you to the GAG REMOVE menu. There you can remove features based")
        print("on certain criteria to filter out bad data. Alternately, just type:\n")
        print("'remove <criteria> <value>'\n")
        print("if you've done this before :)\n")

    def do_remove(self, line):
        if self.controller.genome_is_loaded():
            filtercmd = RemoveCmd(self.prompt, self.controller, line)
            filtercmd.cmdloop()
        else:
            print(self.no_genome_message)
            
    def help_fix(self):
        print("\nThis command takes you to the GAG FIX menu. There you can apply fixes to the genome,")
        print("to resolve issues such as terminal Ns, invalid start and stop codons, etc.")
        print("Fixes are applied when you type the 'info' command or when you write")
        print("the genome to a file.")
        print("Alternately, just type 'fix <name_of_fix> if you've done this before :)\n")<commit_msg>Changed 'remove' to 'flag' in flag help<commit_after>#!/usr/bin/env python
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

import ast
import cmd
import readline
import sys
import traceback
import types
from src.console_controller import ConsoleController

def try_catch(command, args=None):
    try:
        if args is not None:
            return command(*args)
        else:
            return command()
    except:
        print("Sorry, that command raised an exception. Here's what I know:\n")
        print(traceback.format_exc())
        
###################################################################################################
# Define a custom cmd line base class to fix some bugs in cmd.Cmd
###################################################################################################

# TODO This class introduces some cool opportunities - we might be able to put all the duplicated
# functionality of subconsoles (i.e. home related code) into this class so the subconsoles' code
# can be more concise

class GagCmdBase(cmd.Cmd):

    def __init__(self):
        cmd.Cmd.__init__(self)
        self.helptext = ""
        readline.set_history_length(1000)
        try:
            readline.read_history_file('.gaghistory')
        except IOError:
            sys.stderr.write("No .gaghistory file available...\n")
        
    def get_names(self):
        return dir(self)

    def precmd(self, line):
        readline.write_history_file('.gaghistory')
        return line

    def emptyline(self):
        print(self.helptext)

###################################################################################################
# End cmd base class
###################################################################################################

class GagCmd(GagCmdBase):

## Setup, loading and saving sessions, exit, etc.

    intro = "                                                                                \n                                        ,,                                      \n              ~++=:,                  =OMNZ:                  :=?77I=,          \n           :7DMMMMMMD7:              ~DMMMMZ               =$DMMMMMMMM8+        \n         :7NMMMMMMMMMMN7,            $MMMMMN=            ~ZMMMMMMMMMMMMZ,       \n        ?NMMMNZ+~+IONMMN?           INMMNMMMI           INMMMDZ?~,,:+I?:        \n       +NMMN7:      :?$I:          INMMNZMMMZ         :$MMMD?                   \n      :8MMM?                      7MMMD+=NMM8,       :OMMMO~                    \n      7MMMZ,                     7MMMD= ,8MMM?       ZMMMZ,                     \n     :8MMN+                    ,$MMMN+   IMMMO      ~NMMD~     ,+$ZI+==~,       \n     ~DMMD~    ~7OZ$Z8NNZ:    +DMMMD$I?~:~DMMN+     +NMM8      IMMMMMMMMO:      \n      $MMM8:   ,OMMMMMMMN=   INMMN$$MMMMMMMMMMZ     ~DMMMI     ~8MMMMMMMZ:      \n      ,ZMMMD?,   ?NMMMNZ~   INMMD+ =ONMMMMMMMMN~     +DMMM$:     ,=$MMMD:       \n       ,$MMMMM87+IONMMMI   ?NMMN=     :=+??OMMM$      =8MMMM87=, ,+8MMMZ        \n         +8MMMMMMMMMMMO~  ~D0GE?           =NMM$       :$NMMMMMMNMMMMMO:        \n           :I8NMMMMNO+,   :OMD?             +Z7~         :I8NMMMMMMMDI,         \n               :~~:        ,,,                               ~?7$7?~            \n                                                                                \n                                                                                "+\
    "\nWelcome to the GAG console!\n"+\
    "Type 'help' for available commands.\n"

    no_genome_message = "\nIt looks like no genome is currently loaded. Try the 'load' command.\n"+\
            "Type 'help load' to learn how to use it, or just 'help' for general advice.\n"

    def __init__(self):
        GagCmdBase.__init__(self)
        self.prompt = "GAG> "
        self.controller = ConsoleController() 

    def precmd(self, line):
        line = GagCmdBase.precmd(self, line)
        print('----------------------------------------')
        return line
        
    def postcmd(self, stop, line):
        stop = GagCmdBase.postcmd(self, stop, line)
        print('----------------------------------------')
        return stop

    def help_load(self):
        print("\nThis command takes you the GAG LOAD menu. There you can specify the location of")
        print("your files and load them into memory.")
        print("Alternately, just type 'load <path>' and avoid the submenu altogether.\n")

    def do_load(self, line):
        path_to_load = line.strip()
        loadcmd = LoadCmd(self.prompt, self.controller, path_to_load)
        loadcmd.cmdloop()

    def help_flag(self):
        print("\nThis command takes you to the GAG FLAG menu. There you can flag features based")
        print("on certain criteria to mark suspicious data. Alternately, just type:\n")
        print("'flag <criteria> <value>'\n")
        print("if you've done this before :)\n")

    def do_flag(self, line):
        if self.controller.genome_is_loaded():
            filtercmd = FlagCmd(self.prompt, self.controller, line)
            filtercmd.cmdloop()
        else:
            print(self.no_genome_message)
    
    def help_remove(self):
        print("\nThis command takes you to the GAG REMOVE menu. There you can remove features based")
        print("on certain criteria to filter out bad data. Alternately, just type:\n")
        print("'remove <criteria> <value>'\n")
        print("if you've done this before :)\n")

    def do_remove(self, line):
        if self.controller.genome_is_loaded():
            filtercmd = RemoveCmd(self.prompt, self.controller, line)
            filtercmd.cmdloop()
        else:
            print(self.no_genome_message)
            
    def help_fix(self):
        print("\nThis command takes you to the GAG FIX menu. There you can apply fixes to the genome,")
        print("to resolve issues such as terminal Ns, invalid start and stop codons, etc.")
        print("Fixes are applied when you type the 'info' command or when you write")
        print("the genome to a file.")
        print("Alternately, just type 'fix <name_of_fix> if you've done this before :)\n")
{'fraction_non_alphanumeric': 0.17258800521512385, 'fraction_numerical': 0.00651890482398957, 'mean_word_length': 1.7499439838673538, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 20, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4947009', 'n_tokens_mistral': 3441, 'n_tokens_neox': 3330, 'n_words': 965}