
    y h                     ^    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        yy)	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 cg c]%  }t        |t              r|n|j                  d      ' } }d}t	        d       t        |d      5 }|j                  t        j                         j                  d      dz   j                  d             |j                  dj                  d             |j                  dj                  d             | D cg c]  }|j                  |       c} d d d        t	        d	j                  t        j                  j                  |                   t	        d
       t	        d       t	        dj                  |             y c c}w c c}w # 1 sw Y   {xY w)Nutf-8z=https://github.com/JaidedAI/EasyOCR/tree/master/easyocr/DBNetz)Failed to compile dcn operator for DBNet.wb%H:%M:%S - %d %b %Y
zCFailed to compile dcn operator for DBNet with the following error.
z+##########################################
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.)
isinstancelistbytesencodeprintopenwriter   nowstrftimeformatospathabspath)errorslog_patherrorurlfids        }/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/easyocr/scripts/compile_dbnet_dcn.pyprint_errorr      s5   fd#X^_uz%/eU\\'5JJ_F_
IC	
56	h	 /		8<<>**+@ADHPPQXYZ		X__`ghi		=((12'-.e5	.	/
 

-
4
4RWW__X5N
OP	&M	
IJ	
k
r
rsv
wx ` 	/	/ /s$   *E1B	E;&E6>E;6E;;Fc                 *   t        |d      5 }|j                  t        j                         j	                  d      dz   j                  d             |j                  | dz   j                  d             d d d        t        |        y # 1 sw Y   xY w)Nr   r   r   r   )r   r   r   r   r   r   r   )textr   r   s      r   print_successr      sv    	h	 1		8<<>**+@ADHPPQXYZ		4$;&&w/01 
$K1 1s   A(B		Bc                    t         j                  j                  | dddd      }|dk(  rt        j                  t         j                  j                  |d            }t        j                  t         j                  j                  |d            }dj	                  t         j                  j                  t         j                  j                  | d                  }t        ||       |xr |S |d	k(  rt        j                  t         j                  j                  |d
            }t        j                  t         j                  j                  |d            }dj	                  t         j                  j                  t         j                  j                  | d                  }t        ||       |xr |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_compilationr2   $   sh   ggll:w%GGe277<<9O#PQ277<<9O#PQLSSTVT[T[TcTcdfdkdkdpdpq{  }D  eE  UF  Gox00.0		))BGGLL:Q$RS))BGGLL:Q$RSMTTUWU\U\UdUdegeleleqeqr|  ~E  fF  VG  Hox02?2GHH    c            	      $   t        j                         } t         j                  j                  t         j                  j                  t         j                  j	                  t
                          }t         j                  j                  |dd      }	 t        d       t        j                  t         j                  j                  |dddd             t        j                  ddd	      }|j                  d
k(  r~t        j                  t         j                  j                  |d             t        ||d      rt        j                  ddd	      }t        ||d      rPt        j                  ddd	      }n7t        |j                         t        |j                  |j                   g|       t        j                  |        y # t"        $ r%}t        dj%                  |      |       Y d }~?d }~ww xY w# 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
returncoder2   __dict__r   stdoutstderr	Exceptionr   )cwdr*   r   resultr   s        r   mainrD   6   sm   
))+C1J!KLJww||Jw	:H*+
j%FG1PT
 !HHRWW\\*g67#J%@#5TTX $J&A#6dUY &//"6A 	  2DKK&112 	s+   DG 	G5G0+G8 0G55G8 8H__main__)
__doc__r   r(   r   r;   r   r   r2   rD   __name__ r3   r   <module>rI      sB    
   y I$8 zF r3   