Skip to content

Commit

Permalink
[app][fix] attr missing
Browse files Browse the repository at this point in the history
  • Loading branch information
M3ssman committed Jun 18, 2024
1 parent 480cda1 commit 6b43c4e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
10 changes: 4 additions & 6 deletions cli_record_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,17 @@ def wrap_save_record_state(status: str, urn, **kwargs):
req_dst_dir = os.path.join(LOCAL_WORK_ROOT, local_ident)
if os.path.exists(req_dst_dir):
shutil.rmtree(req_dst_dir)

proc_type = CFG.get(odem.CFG_SEC_OCR, 'workflow_type', fallback=None)
if proc_type is None:
LOGGER.warning("no 'workflow_type' config option in section ocr defined. defaults to 'OCRD_PAGE_PARALLEL'")
odem_process: ODEMProcessImpl = ODEMProcessImpl(record, req_dst_dir)
odem_process.logger = LOGGER
odem_process.logger.info("[%s] odem from %s, %d executors", local_ident, OAI_RECORD_FILE, EXECUTORS)
odem_process.configuration = CFG
LOCAL_STORE_ROOT = CFG.get('global', 'local_store_root', fallback=None)
if LOCAL_STORE_ROOT is not None:
STORE_DIR = os.path.join(LOCAL_STORE_ROOT, local_ident)
STORE = df.LocalStore(STORE_DIR, req_dst_dir)
odem_process.store = STORE
local_store_root = CFG.get('global', 'local_store_root', fallback=None)
if local_store_root is not None:
store_root_dir = os.path.join(local_store_root, local_ident)
odem_process.store = df.LocalStore(store_root_dir, req_dst_dir)
process_resource_monitor: odem_rm.ProcessResourceMonitor = odem_rm.ProcessResourceMonitor(
odem_rm.from_configuration(CFG),
LOGGER.error,
Expand Down
16 changes: 7 additions & 9 deletions cli_record_server_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
CFG = None



def _notify(subject, message):
if CFG.has_section('mail') and CFG.has_option('mail', 'connection'):
try:
Expand All @@ -45,7 +44,7 @@ def _notify(subject, message):
LOGGER.warning("No [mail] section in config, no mail sent!")


class OAIServiceClient:
class Client:
"""Implementation of OAI Service client with
capabilities to get next OAI Record data
and communicate results (done|fail)
Expand Down Expand Up @@ -119,7 +118,7 @@ def update(self, status, oai_urn, **kwargs):
return requests.post(f'{self.oai_server_url}/update', json=self.record_data, timeout=60)


CLIENT: typing.Optional[OAIServiceClient] = None
CLIENT: typing.Optional[Client] = None


def oai_arg_parser(value):
Expand Down Expand Up @@ -235,7 +234,7 @@ def oai_arg_parser(value):
PORT = CFG.getint('record-server', 'record_server_port')
LOGGER.info("Client instance listens %s:%s for '%s' (format:%s)",
HOST, PORT, OAI_RECORD_FILE_NAME, DATA_FIELDS)
CLIENT = OAIServiceClient(OAI_RECORD_FILE_NAME, HOST, PORT)
CLIENT = Client(OAI_RECORD_FILE_NAME, HOST, PORT)
CLIENT.logger = LOGGER

# try to get next data record
Expand Down Expand Up @@ -269,11 +268,10 @@ def oai_arg_parser(value):
if os.path.exists(req_dst_dir):
shutil.rmtree(req_dst_dir)

LOCAL_STORE_ROOT = CFG.get('global', 'local_store_root', fallback=None)
if LOCAL_STORE_ROOT is not None:
STORE_DIR = os.path.join(LOCAL_STORE_ROOT, local_ident)
STORE = df.LocalStore(STORE_DIR, req_dst_dir)
odem_process.store = STORE
local_store_root = CFG.get('global', 'local_store_root', fallback=None)
if local_store_root is not None:
store_root_dir = os.path.join(local_store_root, local_ident)
odem_process.store = df.LocalStore(store_root_dir, req_dst_dir)

process_resource_monitor: odem_rm.ProcessResourceMonitor = odem_rm.ProcessResourceMonitor(
odem_rm.from_configuration(CFG),
Expand Down
2 changes: 1 addition & 1 deletion lib/odem/ocr/ocr_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def _preserve_log(self, work_subdir, image_ident):
_org_log = os.path.join(work_subdir, 'ocrd.log')
if os.path.exists(_org_log):
_ts = time.strftime(ODEM_PAGE_TIME_FORMAT, time.localtime())
_log_label = f'ocrd_odem_{self.odem.process_identifier}_{image_ident}_{_ts}.log'
_log_label = f'ocrd_odem_{self.odem_process.process_identifier}_{image_ident}_{_ts}.log'
_rebranded = os.path.join(work_subdir, _log_label)
os.rename(_org_log, _rebranded)
shutil.copy(_rebranded, _local_ocr_log)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli_oai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_exit_on_data_exhausted(mock_request):
# arrange
_the_list_label = 'oai-record-test'
_rsp = f'{odem.MARK_DATA_EXHAUSTED.format(_the_list_label)}'.encode()
client = rsc.OAIServiceClient(_the_list_label, '1.2.3.4', '9999')
client = rsc.Client(_the_list_label, '1.2.3.4', '9999')
mock_resp = unittest.mock.Mock()
mock_resp.status_code = 404
mock_resp.headers = {'Content-Type': 'text/xml'}
Expand Down

0 comments on commit 6b43c4e

Please sign in to comment.