
    Yh                     j    d Z ddlZddlZddlmZ ddlZd Zd Zd Zd Ze	dk    r e             dS dS )	z
Created by Jaided AI
Released Date: 19/08/2022
Description:
A wrapper for DCN operator for DBNet. This script is called inside the setup.py
of EasyOCR. It can also be called as a standalone script to compile the operator
manually.
    N)datetimec                    t          | t                    s| g} d | D             } d}t          d           t          |d          5                     t          j                                        d          dz                       d                                         d                    d                                         d	                    d                     fd
| D              d d d            n# 1 swxY w Y   t          d	                    t          j                            |                               t          d           t          d           t          d	                    |                     d S )Nc                 f    g | ].}t          |t                    r|n|                    d           /S )utf-8)
isinstancebytesencode).0errors     s/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/easyocr/scripts/compile_dbnet_dcn.py
<listcomp>zprint_error.<locals>.<listcomp>   s7    ___uz%//JeeU\\'5J5J___    z=https://github.com/JaidedAI/EasyOCR/tree/master/easyocr/DBNetz)Failed to compile dcn operator for DBNet.wb%H:%M:%S - %d %b %Y
r   zCFailed to compile dcn operator for DBNet with the following error.
z+##########################################
c                 :    g | ]}                     |          S  )write)r
   r   fids     r   r   zprint_error.<locals>.<listcomp>   s%    ...e5		...r   z!Error message can be found in {}.z*##########################################z=EasyOCR can still be used with CRAFT text detector (default).z_To use DBNet text detector, please check {} for troubleshoot and compile dcn operator manually.)r   listprintopenr   r   nowstrftimer	   formatospathabspath)errorslog_pathurlr   s      @r   print_errorr"      s   fd## __X^___F
IC	
5666	h		 /		8<>>**+@AADHPPQXYYZZZ		X__`ghhiii		=((11222....v....	/ / / / / / / / / / / / / / /
 

-
4
4RW__X5N5N
O
OPPP	&MMM	
IJJJ	
k
r
rsv
w
wxxxxxs   B.DDDc                 h   t          |d          5 }|                    t          j                                        d          dz                       d                     |                    | dz                       d                     d d d            n# 1 swxY w Y   t          |            d S )Nr   r   r   r   )r   r   r   r   r   r	   r   )textr    r   s      r   print_successr%      s    	h		 1		8<>>**+@AADHPPQXYYZZZ		4$;&&w//0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
$KKKKKs   A;BBBc                    t           j                            | dddd          }|dk    rt          j        t           j                            |d                    }t          j        t           j                            |d                    }d                    t           j                            t           j                            | d                              }t          ||           |o|S |d	k    rt          j        t           j                            |d
                    }t          j        t           j                            |d                    }d                    t           j                            t           j                            | d                              }t          ||           |o|S t          d          )NDBNetassetsopsdcncpuzdeform_conv_cpu.*.sozdeform_pool_cpu.*.soz0DCN CPU operator is compiled successfully at {}.cudazdeform_conv_cuda.*.sozdeform_pool_cuda.*.soz1DCN CUDA operator is compiled successfully at {}.z,'cpu_or_cuda' must be either 'cpu' or 'cuda')r   r   joinglobr   r   r%   
ValueError)	
parent_dirr    cpu_or_cudadcn_dirconv_cpu_existpool_cpu_existsuccess_messageconv_cuda_existpool_cuda_exists	            r   validate_compilationr8   $   s   gll:w%GGGe27<<9O#P#PQQ27<<9O#P#PQQLSSTVT[TcTcdfdkdpdpq{  }D  eE  eE  UF  UF  G  Gox0000.0			)BGLL:Q$R$RSS)BGLL:Q$R$RSSMTTUWU\UdUdegeleqeqr|  ~E  fF  fF  VG  VG  H  Hox0002?2GHHHr   c            	      .   t          j                    } t           j                            t           j                            t           j                            t
                                        }t           j                            |dd          }	 t          d           t          j        t           j                            |dddd                     t          j
        ddd	          }|j        d
k    rt          j        t           j                            |d                     t          ||d          rt          j
        ddd	          }t          ||d          rt          j
        ddd	          }n0t          |j                   t          |j        |j        g|           n:# t"          $ r-}t          d                    |          |           Y d }~nd }~ww xY wt          j        |            d S # t          j        |            w xY w)Nr'   zlog.txtzCompiling DCN operators...r(   r)   r*   z#python setup.py build_ext --inplaceT)shellcapture_outputr   r+   ztouch dcn_cpu_compiling_successr,   z touch dcn_cuda_compiling_successz{})r   getcwdr   dirnamer   __file__r-   r   chdir
subprocessrun
returncoder8   __dict__r"   stdoutstderr	Exceptionr   )cwdr0   r    resultr   s        r   mainrI   6   s   
)++C1J1J!K!KLLJw||Jw	::H*+++
j%FFGGG1PT
 
 
 !!HRW\\*g66777#J%@@ #5TTX   $J&AA #6dUY   &/"""6AAA 2 2 2DKK&&111111112 	s1   DF. -G> .
G%8#G G>  G%%G> >H__main__)
__doc__r   r.   r   r@   r"   r%   r8   rI   __name__r   r   r   <module>rM      s     
			           y y y   I I I$  8 zDFFFFF r   