Skip to content

Commit

Permalink
fix LGTM reports for python
Browse files Browse the repository at this point in the history
  • Loading branch information
zdenop committed Mar 31, 2019
1 parent f47c7c9 commit a0527b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/training/tesstrain.py
Expand Up @@ -16,7 +16,9 @@
# Tesseract. For a detailed description of the phases, see
# https://github.com/tesseract-ocr/tesseract/wiki/TrainingTesseract
#
import sys, os, logging
import sys
import os
import logging

if (sys.version_info.major < 3) or (sys.version_info.major == 3 and sys.version_info.minor < 6):
raise Exception("Must be using Python minimum version 3.6!")
Expand Down
9 changes: 5 additions & 4 deletions src/training/tesstrain_utils.py
Expand Up @@ -20,7 +20,6 @@
from datetime import date
from tempfile import TemporaryDirectory, mkdtemp
from pathlib import Path
from shutil import which
import logging
import subprocess
import argparse
Expand All @@ -38,6 +37,7 @@

class TrainingArgs(argparse.Namespace):
def __init__(self):
super(TrainingArgs, self).__init__()
self.uname = platform.uname().system.lower()
self.lang_code = "eng"
self.timestamp = str(date.today())
Expand All @@ -56,6 +56,7 @@ def __init__(self):
self.extract_font_properties = True
self.distort_image = False


def err_exit(msg):
log.critical(msg)
sys.exit(1)
Expand All @@ -66,11 +67,11 @@ def err_exit(msg):
# Usage: run_command CMD ARG1 ARG2...
def run_command(cmd, *args, env=None):
for d in ("", "api/", "training/"):
testcmd = which(f"{d}{cmd}")
if which(testcmd):
testcmd = shutil.which(f"{d}{cmd}")
if shutil.which(testcmd):
cmd = testcmd
break
if not which(cmd):
if not shutil.which(cmd):
err_exit(f"{cmd} not found")

log.debug(f"Running {cmd}")
Expand Down

0 comments on commit a0527b4

Please sign in to comment.