B
    ןEf	                 @   s(   G d d de ZG dd deedZdS )c                   s    e Zd Zi Z fddZ  ZS )	Singletonc                s,   | | j kr"tt| j||| j | < | j |  S )N)
_instancessuperr   __call__)clsargskwargs)	__class__ ./cmf/import_table.pyr      s    
zSingleton.__call__)__name__
__module____qualname__r   r   __classcell__r	   r	   )r   r
   r      s   r   c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
ImportTablec             C   s   t d i | _d S )NZINIT)printimport_table)selfr	   r	   r
   __init__
   s    zImportTable.__init__c             C   s   d S )Nr	   )r   r	   r	   r
   init   s    zImportTable.initc             C   s   d}i t d< tt | d S ]x\}}}|td}x&|D ]}t| ttj|| q6W x&|D ]}t| ttj|| q^W d|kr|	d qW d S )N/T)followlinks.z.git)
ZGLOBAL_IMPORT_TABLEmake_import_configoswalkPROJECT_DIRreplacer   pathjoinremove)r   import_prefixdirnameZdirnames	filenamesZ
subdirnamefilenamer	   r	   r
   make_import_table   s    



zImportTable.make_import_tablec       
      C   s8  |dkrrt jdd d}i }tjtjtddr@t jdd d}x"|j D ]\}}t	||| qLW ||| d< ndd	d
 |
dD }t j|d d d}i }tjtjt|ddrt j|d d d}x"|j D ]\}}t	||| qW |d d  }	x$|j D ]\}}t	|	|| qW |	|| d< d S )Nr   zcommon.config)packageZcustomz	config.pyzcustom.configZconfigr   c             s   s   | ]}|r|V  qd S )Nr	   ).0vr	   r	   r
   	<genexpr>5   s    z1ImportTable.make_import_config.<locals>.<genexpr>z.config)	importlibimport_moduler   r   existsr   r   __dict__itemssetattrsplitcopy)
r   r   r    Zconfig_moduleZcustom_config_moduleZcustom_import_modulekr'   Zmodule_pathZglobal_configr	   r	   r
   r   *   s&    zImportTable.make_import_configN)r   r   r   r   r   r$   r   r	   r	   r	   r
   r   	   s   r   )	metaclassN)typer   objectr   r	   r	   r	   r
   <module>   s   