Exemplo n.º 1
0
 def my_startfile(filepath, operation=None):
     print("#@ os.startfile: ", filepath, operation)
     try:
         if operation is None:
             return os_startfile(filepath)
         else:
             return os_startfile(filepath, operation)
     except WindowsError:
         print("#@ os.startfile failed: ", filepath, operation)
Exemplo n.º 2
0
 def my_startfile(filepath, operation=None):
     print("#@ os.startfile: ", filepath, operation)
     try:
         if operation is None:
             return os_startfile(filepath)
         else:
             return os_startfile(filepath, operation)
     except WindowsError:
         print("#@ os.startfile failed: ", filepath, operation)
Exemplo n.º 3
0
	def start(file):
		return os_startfile(file)
Exemplo n.º 4
0
    def run(self):
        stop = False

        for folder in ['trash', 'plain', 'hash']:
            if stop:
                break

            # Let's convert the single date to a path
            arg_dir = '/'.join(self.parentArgs.dir.split('-'))
            review_folder = self.settings['data_dir'] + '/organized/' + folder + "/" + arg_dir

            if not os_path.exists(review_folder):
                print 'Folder "' + folder + '" not found, skipping...'
                continue

            files = [os_path.join(w_path, filename)
                     for w_path, dirs, files in os_walk(review_folder)
                     for filename in files
                     if not filename.endswith(".csv")]

            idx = 0

            while idx < len(files):
                rfile = files[idx]

                # Clear the screen before displaying the text
                system('cls' if name == 'nt' else 'clear')

                # Let's the terminal size, so I can fill it with the file text
                cols, rows = get_terminal_size()

                print colorama.Fore.YELLOW + rfile
                print("")

                with open(rfile) as tfile:
                    i = 0
                    for line in tfile:
                        i += 1
                        if i >= (rows - 6):
                            break

                        if len(line) <= cols:
                            print line.strip('\n\r')
                        else:
                            print line[0:cols].strip('\n\r')

                files_left = len(files) - idx
                print("")
                print colorama.Fore.YELLOW + "Folder: " + folder + " " + colorama.Fore.CYAN + str(files_left) + colorama.Fore.YELLOW + " files left"

                input_descr = colorama.Fore.MAGENTA + "[o]"
                input_descr += colorama.Fore.CYAN + "open "
                input_descr += colorama.Fore.MAGENTA + "[s]"
                input_descr += colorama.Fore.CYAN + "kip folder "
                input_descr += colorama.Fore.MAGENTA + "[n]"
                input_descr += colorama.Fore.CYAN + "ext "
                input_descr += colorama.Fore.MAGENTA + "[p]"
                input_descr += colorama.Fore.CYAN + "revious "
                input_descr += colorama.Fore.MAGENTA + "[q]"
                input_descr += colorama.Fore.CYAN + "uit=> "

                sys_stdout.write(input_descr)
                sys_stdout.flush()

                answer = getch()

                while answer == '':
                    pass

                idx += 1

                # Opening a file with the default application AND being cross platform is a PITA...
                if answer == 'o':
                    current_os = platform_system()
                    if current_os == 'Windows':
                        from os import startfile as os_startfile
                        os_startfile(rfile)
                    elif current_os == 'Linux':
                        subprocess_call(["xdg-open", rfile])
                    elif current_os == 'Darwin':
                        system("open " + rfile)

                    # Let's start the loop again to read the new key
                    answer = getch()

                    while answer == '':
                        pass

                if answer == 'n':
                    print("")
                elif answer == 'p':
                    if idx >= 2:
                        idx -= 2
                    continue
                elif answer == 's':
                    break
                elif answer == 'q':
                    print("")
                    stop = True
                    break
                else:
                    print("")

        print(colorama.Fore.GREEN + "Review completed")
Exemplo n.º 5
0
    def _gettrainingdata(self):
        files = [
            path.join(w_path, filename)
            for w_path, dirs, files in walk(self.settings['data_dir'] + "/" +
                                            'raw') for filename in files
            if not filename.endswith(".csv")
        ]
        while 1:
            rfile = random_choice(files)

            trash = len(
                listdir(self.settings['data_dir'] + "/" + 'training/trash'))
            plain = len(
                listdir(self.settings['data_dir'] + "/" + 'training/plain'))
            hashes = len(
                listdir(self.settings['data_dir'] + "/" + 'training/hash'))

            # Clear the screen before displaying the text
            system('cls' if name == 'nt' else 'clear')

            # Let's the terminal size, so I can fill it with the file text
            cols, rows = get_terminal_size()

            print colorama.Fore.YELLOW + rfile
            print("")

            with open(rfile) as tfile:
                i = 0
                for line in tfile:
                    i += 1
                    if i >= (rows - 6):
                        break

                    if len(line) <= cols:
                        print line.strip('\n\r')
                    else:
                        print line[0:cols].strip('\n\r')

            print("")
            print colorama.Fore.YELLOW + "Trash: " + str(
                trash) + " Plain: " + str(plain) + " Hash: " + str(hashes)

            input_descr = colorama.Fore.MAGENTA + "[o]"
            input_descr += colorama.Fore.CYAN + "open "
            input_descr += colorama.Fore.MAGENTA + "[t]"
            input_descr += colorama.Fore.CYAN + "rash "
            input_descr += colorama.Fore.MAGENTA + "[p]"
            input_descr += colorama.Fore.CYAN + "lain "
            input_descr += colorama.Fore.MAGENTA + "[h]"
            input_descr += colorama.Fore.CYAN + "ash "
            input_descr += colorama.Fore.MAGENTA + "[s]"
            input_descr += colorama.Fore.CYAN + "kip "
            input_descr += colorama.Fore.MAGENTA + "[q]"
            input_descr += colorama.Fore.CYAN + "uit=> "

            sys_stdout.write(input_descr)
            sys_stdout.flush()

            answer = getch()

            while answer == '':
                pass

            # Opening a file with the default application AND being cross platform is a PITA...
            if answer == 'o':
                current_os = platform_system()
                if current_os == 'Windows':
                    from os import startfile as os_startfile
                    os_startfile(rfile)
                elif current_os == 'Linux':
                    subprocess_call(["xdg-open", rfile])
                elif current_os == 'Darwin':
                    system("open " + rfile)

                # Let's start the loop again to read the new key
                answer = getch()

                while answer == '':
                    pass

            if answer == 't':
                shutil_copyfile(
                    rfile, self.settings['data_dir'] + "/" +
                    'training/trash/' + path.basename(rfile))
            elif answer == 'p':
                shutil_copyfile(
                    rfile, self.settings['data_dir'] + "/" +
                    'training/plain/' + path.basename(rfile))
            elif answer == 'h':
                shutil_copyfile(
                    rfile, self.settings['data_dir'] + "/" + 'training/hash/' +
                    path.basename(rfile))
            elif answer == 's':
                print("")
                continue
            elif answer == 'q':
                print("")
                print(colorama.Fore.GREEN + "Training complete")
                break
            else:
                print("")
                continue
Exemplo n.º 6
0
    def _gettrainingdata(self):
        files = [path.join(w_path, filename)
                 for w_path, dirs, files in walk(self.settings['data_dir'] + "/" + 'raw')
                 for filename in files
                 if not filename.endswith(".csv")]
        while 1:
            rfile = random_choice(files)

            trash  = len(listdir(self.settings['data_dir'] + "/" + 'training/trash'))
            plain  = len(listdir(self.settings['data_dir'] + "/" + 'training/plain'))
            hashes = len(listdir(self.settings['data_dir'] + "/" + 'training/hash'))

            # Clear the screen before displaying the text
            system('cls' if name == 'nt' else 'clear')

            # Let's the terminal size, so I can fill it with the file text
            cols, rows = get_terminal_size()

            print colorama.Fore.YELLOW + rfile
            print("")

            with open(rfile) as tfile:
                i = 0
                for line in tfile:
                    i += 1
                    if i >= (rows - 6):
                        break

                    if len(line) <= cols:
                        print line.strip('\n\r')
                    else:
                        print line[0:cols].strip('\n\r')

            print("")
            print colorama.Fore.YELLOW + "Trash: " + str(trash) + " Plain: " + str(plain) + " Hash: " + str(hashes)

            input_descr = colorama.Fore.MAGENTA + "[o]"
            input_descr += colorama.Fore.CYAN + "open "
            input_descr += colorama.Fore.MAGENTA + "[t]"
            input_descr += colorama.Fore.CYAN + "rash "
            input_descr += colorama.Fore.MAGENTA + "[p]"
            input_descr += colorama.Fore.CYAN + "lain "
            input_descr += colorama.Fore.MAGENTA + "[h]"
            input_descr += colorama.Fore.CYAN + "ash "
            input_descr += colorama.Fore.MAGENTA + "[s]"
            input_descr += colorama.Fore.CYAN + "kip "
            input_descr += colorama.Fore.MAGENTA + "[q]"
            input_descr += colorama.Fore.CYAN + "uit=> "

            sys_stdout.write(input_descr)
            sys_stdout.flush()

            answer = getch()

            while answer == '':
                pass

            # Opening a file with the default application AND being cross platform is a PITA...
            if answer == 'o':
                current_os = platform_system()
                if current_os == 'Windows':
                    from os import startfile as os_startfile
                    os_startfile(rfile)
                elif current_os == 'Linux':
                    subprocess_call(["xdg-open", rfile])
                elif current_os == 'Darwin':
                    system("open " + rfile)

                # Let's start the loop again to read the new key
                answer = getch()

                while answer == '':
                    pass

            if answer == 't':
                shutil_copyfile(rfile, self.settings['data_dir'] + "/" + 'training/trash/' + path.basename(rfile))
            elif answer == 'p':
                shutil_copyfile(rfile, self.settings['data_dir'] + "/" + 'training/plain/' + path.basename(rfile))
            elif answer == 'h':
                shutil_copyfile(rfile, self.settings['data_dir'] + "/" + 'training/hash/' + path.basename(rfile))
            elif answer == 's':
                print("")
                continue
            elif answer == 'q':
                print("")
                print(colorama.Fore.GREEN + "Training complete")
                break
            else:
                print("")
                continue
Exemplo n.º 7
0
    def run(self):
        stop = False

        for folder in ['trash', 'plain', 'hash']:
            if stop:
                break

            # Let's convert the single date to a path
            arg_dir = '/'.join(self.parentArgs.dir.split('-'))
            review_folder = self.settings[
                'data_dir'] + '/organized/' + folder + "/" + arg_dir

            if not os_path.exists(review_folder):
                print 'Folder "' + folder + '" not found, skipping...'
                continue

            files = [
                os_path.join(w_path, filename)
                for w_path, dirs, files in os_walk(review_folder)
                for filename in files if not filename.endswith(".csv")
            ]

            idx = 0

            while idx < len(files):
                rfile = files[idx]

                # Clear the screen before displaying the text
                system('cls' if name == 'nt' else 'clear')

                # Let's the terminal size, so I can fill it with the file text
                cols, rows = get_terminal_size()

                print colorama.Fore.YELLOW + rfile
                print("")

                with open(rfile) as tfile:
                    i = 0
                    for line in tfile:
                        i += 1
                        if i >= (rows - 6):
                            break

                        if len(line) <= cols:
                            print line.strip('\n\r')
                        else:
                            print line[0:cols].strip('\n\r')

                files_left = len(files) - idx
                print("")
                print colorama.Fore.YELLOW + "Folder: " + folder + " " + colorama.Fore.CYAN + str(
                    files_left) + colorama.Fore.YELLOW + " files left"

                input_descr = colorama.Fore.MAGENTA + "[o]"
                input_descr += colorama.Fore.CYAN + "open "
                input_descr += colorama.Fore.MAGENTA + "[s]"
                input_descr += colorama.Fore.CYAN + "kip folder "
                input_descr += colorama.Fore.MAGENTA + "[n]"
                input_descr += colorama.Fore.CYAN + "ext "
                input_descr += colorama.Fore.MAGENTA + "[p]"
                input_descr += colorama.Fore.CYAN + "revious "
                input_descr += colorama.Fore.MAGENTA + "[q]"
                input_descr += colorama.Fore.CYAN + "uit=> "

                sys_stdout.write(input_descr)
                sys_stdout.flush()

                answer = getch()

                while answer == '':
                    pass

                idx += 1

                # Opening a file with the default application AND being cross platform is a PITA...
                if answer == 'o':
                    current_os = platform_system()
                    if current_os == 'Windows':
                        from os import startfile as os_startfile
                        os_startfile(rfile)
                    elif current_os == 'Linux':
                        subprocess_call(["xdg-open", rfile])
                    elif current_os == 'Darwin':
                        system("open " + rfile)

                    # Let's start the loop again to read the new key
                    answer = getch()

                    while answer == '':
                        pass

                if answer == 'n':
                    print("")
                elif answer == 'p':
                    if idx >= 2:
                        idx -= 2
                    continue
                elif answer == 's':
                    break
                elif answer == 'q':
                    print("")
                    stop = True
                    break
                else:
                    print("")

        print(colorama.Fore.GREEN + "Review completed")