def return_data(self, command=None): """Read until exit status is returned. Returns: data: List of right-stripped strings containing output of the command. Raises: AtCommandError: If an error is returned by the modem. """ data = list() while 1: # Read in one line of input. input_line = self.readline().rstrip() # Check for errors and raise exception with specific error code. errors.check_for_errors(input_line) if input_line == 'OK': return data # Append only related data (starting with "command" contents). if command: if input_line.startswith(command): prefix_length = len(command)+2 data.append(input_line[prefix_length:]) else: # Append only non-empty data. if input_line: data.append(input_line)
def send_at(self, cmd, suffix, prefixed=True): """Send serial text to the modem. Arguments: self -- serial port to send to, text -- text value to send, prefixed -- boolean determining weather to strip the AT command prefix from each output line. Returns: List of strings. """ self.write('AT%s%s\r' % (cmd, suffix)) #print "D: - Sending " + ('AT%s%s\r' % (cmd, suffix)) # Read in the echoed text. # Check for errors and raise exception with specific error code. input_line = self.readline() errors.check_for_errors(input_line) # Return the result. if prefixed: # If the text being sent is an AT command, only relevant context # answer (starting with '+command:' value) will be returned by #return_data(). Otherwise any string will be returned. return self.return_data(cmd) else: return self.return_data()
def return_data(self, command=None): """Read until exit status is returned. Returns: data: List of right-stripped strings containing output of the command. Raises: AtCommandError: If an error is returned by the modem. """ data = list() while 1: # Read in one line of input. input_line = self.readline().rstrip() # Check for errors and raise exception with specific error code. errors.check_for_errors(input_line) if input_line == 'OK': return data # Append only related data (starting with "command" contents). if command: if input_line.startswith(command): prefix_length = len(command) + 2 data.append(input_line[prefix_length:]) else: # Append only non-empty data. if input_line: data.append(input_line)
def call_tesseract(input_filename, output_filename, language, pagesegmode): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" current_dir = os.getcwd() error_stream = StringIO.StringIO() try: os.chdir(_working_dir) args = [tesseract_exe_name, input_filename, output_filename] if len(language) > 0: args.append("-l") args.append(language) if len(str(pagesegmode)) > 0: args.append("-psm") args.append(str(pagesegmode)) try: proc = subprocess.Popen(args) except (TypeError, AttributeError): proc = subprocess.Popen(args, shell=True) retcode = proc.wait() if retcode!=0: error_text = error_stream.getvalue() errors.check_for_errors(error_stream_text = error_text) finally: # Guarantee that we return to the original directory error_stream.close() os.chdir(current_dir)
def call_tesseract(input_filename, output_filename, language, pagesegmode): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" current_dir = os.getcwd() error_stream = StringIO.StringIO() try: os.chdir(_working_dir) args = [tesseract_exe_name, input_filename, output_filename] if len(language) > 0: args.append("-l") args.append(language) if len(str(pagesegmode)) > 0: args.append("-psm") args.append(str(pagesegmode)) try: proc = subprocess.Popen(args) except (TypeError, AttributeError): proc = subprocess.Popen(args, shell=True) retcode = proc.wait() if retcode != 0: error_text = error_stream.getvalue() errors.check_for_errors(error_stream_text=error_text) finally: # Guarantee that we return to the original directory error_stream.close() os.chdir(current_dir)
def call_tesseract(input_filename, output_filename): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" args = [tesseract_exe_name, input_filename, output_filename] proc = subprocess.Popen(args) retcode = proc.wait() if retcode!=0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" os.environ["TESSDATA_PREFIX"] = os.path.abspath( os.path.dirname(__file__) )+"/" args = [tesseract_exe_name, input_filename, output_filename, "nobatch", "my" ] proc = subprocess.Popen(args) retcode = proc.wait() if retcode!=0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" devnull = open(os.devnull, 'w') #modified args = [tesseract_exe_name, input_filename, output_filename] proc = subprocess.Popen(args, stderr=devnull) #modified retcode = proc.wait() if retcode!=0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" devnull = open(os.devnull, 'w') #modified args = [tesseract_exe_name, input_filename, output_filename] proc = subprocess.Popen(args, stderr=devnull) #modified retcode = proc.wait() if retcode != 0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" args = [tesseract_exe_name, input_filename, output_filename] args.append("-psm") #added grzegorz pietrusza args.append(str(6)) #added grzegorz pietrusza proc = subprocess.Popen(args) retcode = proc.wait() if retcode!=0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" args = [tesseract_exe_name, input_filename, output_filename] args.append("-psm") #added grzegorz pietrusza args.append(str(6)) #added grzegorz pietrusza proc = subprocess.Popen(args) retcode = proc.wait() if retcode != 0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" path = os.path.join(os.getcwd(), 'pyspider\\pytesser', tesseract_exe_name) args = [path, input_filename, output_filename] print args proc = subprocess.Popen(args) retcode = proc.wait() if retcode != 0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename, language=""): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" args = [tesseract_exe_name, input_filename, output_filename] if len(language) > 0: args.append('-l') args.append(language) proc = subprocess.Popen(args) retcode = proc.wait() if retcode != 0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" if _platform_=='linux' or _platform_=='linux2': args = ['/usr/bin/wine', tesseract_exe_name, input_filename, output_filename] else: args = [tesseract_exe_name, input_filename, output_filename] proc = subprocess.Popen(args) retcode = proc.wait() if retcode != 0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" dest = open(os.devnull, 'w') # Jabba if DEBUG: dest = STDOUT args = [tesseract_exe_name, input_filename, output_filename] proc = Popen(args, stdout=dest, stderr=dest) # Jabba retcode = proc.wait() if retcode != 0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename, language=""): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" args = [tesseract_exe_name, input_filename, output_filename] if len(language) > 0: args.append('-l') args.append(language) proc = subprocess.Popen(args) retcode = proc.wait() if retcode!=0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" os.environ["TESSDATA_PREFIX"] = os.path.abspath( os.path.dirname(__file__)) + "/" args = [ tesseract_exe_name, input_filename, output_filename, "nobatch", "my" ] proc = subprocess.Popen(args) retcode = proc.wait() if retcode != 0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" args = [tesseract_exe_name, input_filename, output_filename] try: proc = subprocess.Popen(args, stderr=subprocess.PIPE, stdout=subprocess.PIPE) except: print "\n[!] Please install tesseract-ocr first!" print "[!] Run 'sudo apt-get install tesseract-ocr'" exit() retcode = proc.wait() if retcode != 0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" args = [tesseract_exe_name, input_filename, output_filename] args.append("-l eng2+eng3+eng4+eng5+eng6+eng7+eng8") args.append("-psm") args.append(str(10)) args.append("letters") proc = subprocess.Popen(args, stderr=subprocess.PIPE, stdout=subprocess.PIPE) retcode = proc.wait() if retcode != 0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename, bool_digits=False): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" # args = [tesseract_exe_name, input_filename, output_filename] if bool_digits: # args = tesseract_exe_name+" "+input_filename+" "+output_filename+" -l eng -psm 7 nobatch eng_digits" # price args = tesseract_exe_name + " " + input_filename + " " + output_filename + " -l test_digits -psm 7 nobatch" # price else: args = tesseract_exe_name + " " + input_filename + " " + output_filename + " -l eng -psm 7 nobatch eng_characters" # English letters # args = tesseract_exe_name+" "+input_filename+" "+output_filename+" -l test_eng -psm 7 nobatch" # English letters # print args proc = subprocess.Popen(args, shell=True) retcode = proc.wait() if retcode != 0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename, bool_digits=False): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" # args = [tesseract_exe_name, input_filename, output_filename] if bool_digits: # args = tesseract_exe_name+" "+input_filename+" "+output_filename+" -l eng -psm 7 nobatch eng_digits" # price args = tesseract_exe_name+" "+input_filename+" "+output_filename+" -l test_digits -psm 7 nobatch" # price else: args = tesseract_exe_name+" "+input_filename+" "+output_filename+" -l eng -psm 7 nobatch eng_characters" # English letters # args = tesseract_exe_name+" "+input_filename+" "+output_filename+" -l test_eng -psm 7 nobatch" # English letters # print args proc = subprocess.Popen(args, shell=True) retcode = proc.wait() if retcode != 0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename, charset=None): """Calls external tesseract on input file (restrictions on types), outputting output_filename + '.txt' Optionally, you can provide a character set to limit the OCR characters the ones specified""" devnull = open(os.devnull, 'w') args = [settings.TESSERACT_PATH, input_filename, output_filename] if charset: util.charset_to_scratch(charset, scratch_charset) args.append(scratch_charset) proc = subprocess.Popen(args, stderr=devnull) retcode = proc.wait() if retcode != 0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename, psm, oem): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" # https://github.com/tesseract-ocr/tesseract/wiki/Command-Line-Usage cmdline = tesseract_exe_name + ' -l eng --psm ' + str(psm) + ' --oem ' + str(oem) + \ ' ' + input_filename + ' ' + output_filename args = cmdline.split() # hide output (echo off) FNULL = open(os.devnull, 'w') proc = subprocess.Popen(args, stdout=FNULL, stderr=subprocess.STDOUT, cwd=os.getcwd()) retcode = proc.wait() if retcode != 0: errors.check_for_errors()
def make_clear(): args = ['./make_clear'] proc = subprocess.Popen(args) retcode = proc.wait() if retcode!=0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename): """Calls external tesseract.exe on input file (restrictions on types), outputting output_filename+'txt'""" args = [tesseract_exe_name, input_filename, output_filename] if retcode!=0: errors.check_for_errors()
def call_tesseract(input_filename, output_filename): args = [tesseract_exe_name, input_filename, output_filename] proc = subprocess.Popen(args) retcode = proc.wait() if retcode!=0: errors.check_for_errors()