Esempio n. 1
0
    def build(self):
        #TODO can suppose makefile

        try:
            fileType = self.__kidDir.fileType
            command = self.commandDict[fileType]()
            self.binSh('-c', command, _err=process_errlog)
            
            writeUserLog('codevs info: Congratulation! Build successfully')

        except sh.ErrorReturnCode:
            writeUserLog('codevs error: build err,\n'
                  '\tfailed to build your code,\n'
                  '\tyou should check your code carefully.')
            sys.exit(1)

        except KeyError as err:
            writeUserLog('codevs error: no valid file in src,\n'
                  '\tplease checkout your files suffix.')
            sys.exit(1)
        
        except Exception as err:
            writeUserLog('codevs error: sorry,\n'
                  '\tthere is a error in our cli\n')
            writeCodeVsLog(err)
            sys.exit(1)
Esempio n. 2
0
def main():
    """CodeVS

    Usage:
      codevs [options]
      codevs build <dir>               
      codevs run [options] <dir> 
      codevs make [options] [<target>] 
      codevs token <token> <file>
      codevs show
      codevs push <token>
      codevs rm <token>                 

    Cmd:
      build     Build the files in dir/src/ to executable file(dir/Main)
                ——you should put your source file into dir/src
      run       Build the files in dir/src/ to executable file(dir/Main) and exec it, you can use -a or --args to set arguments for your program
                ——you should put your source file into dir/src
      make      build your program accroding your makefile, also you can use target , e.g. make -f ./example.mk install
      token     Set a Token to a file
      show      Show all token file
      push      Push a file with especial token 
      rm        Remove a token and the file if it exist.

    Options:
      for run
      -a ARGUMENTS, --args=ARGUMENTS   set arguments for your program
      
      for make
      -f FILE       set makefile name as FILE not makefile
      -C DIR        set make dir as DIR not crrunt dir

      -h --help     Show this screen.
      --version     Show version.

    """
    try:
        setup_signal()
        arguments = docopt(main.__doc__, version='CodeVS α')

        # get right cmd
        cmd = cliCommond(arguments)
        cmd_router[cmd](arguments)

    except KeyError :
        message = '{:-^70}\n'.format('CodeVs')
        message += 'Welcome to use CodeVs-cli!\n\n'
        message += 'You should use "codevs build your_project_dir" to build source to exec\nutable file,\n'
        message += 'Also , you may want to "codevs run your_project_dir" to run project di\nrectly,\n'
        message += 'Linuxer like write makefile , just run command "codevs make".\n'
        message += '\n"codevs --help" give you more help information.\n'
        message += '{:-^70}\n'.format('To Code Fun!')
        message += '{: >70}\n'.format('lovely by wph95, mpsss and CodeVsers')
        loggers.writeUserLog(message)

    except Exception as err:
        print('codevs error: sorry,\n'
              '\tthere is a error in our cli\n')
        loggers.writeCodeVsLog(err)
        sys.exit(1)
Esempio n. 3
0
    def make(self, argstrnig):
        try:
            self.binSh('-c', ' '.join(['make', argstrnig]), _err=process_errlog, _out=process_errlog)

        except sh.ErrorReturnCode:
            print('codevs error: make err,\n'
                  '\tfailed to make your code,\n'
                  '\tyou should check your code or makefile carefully.')
            sys.exit(1)
        
        except Exception as err:
            print('codevs error: sorry,\n'
                  '\tthere is a error in our cli\n')
            writeCodeVsLog(err)
            sys.exit(1)
Esempio n. 4
0
    def run(self, args):
        exec_filename = os.path.join(self.dirabsname, 'Main')
        exec_line = ' '.join([exec_filename,args.strip()])

        try:
            self.binSh('-c',exec_line, _err=process_errlog, _out=process_errlog,_in=sys.stdin)

        except sh.ErrorReturnCode:
            writeUserLog('codevs error: run err,\n'
                  '\tthere is a logic error in your code')
            sys.exit(1)

        except Exception as err:
            writeUserLog('codevs error: sorry,\n'
                  '\tthere is a error in our cli\n')
            writeCodeVsLog(err)
            sys.exit(1)