B
    T[                 @   s0   d Z ddlmZ ddlmZ G dd deZdS )z'
Created on May 2, 2014

@author: sean
    )jencode)BinstarErrorc               @   sH   e Zd Zdd Zdd ZdddZddd	Zd
d Zdd Zdd Z	dS )ChannelsMixinc             C   s0   d| j |f }| j|}| |dg | S )zcList the channels for owner
        If owner is none, the currently logged in user is used
        z%s/channels/%s   )domainsessionget_check_responsejson)selfownerurlres r   ]lib/python3.7/site-packages/anaconda_client-1.7.2-py3.7.egg/binstar_client/mixins/channels.pylist_channels   s    zChannelsMixin.list_channelsc             C   s2   d| j ||f }| j|}| |dg | S )zcList the channels for owner
        If owner is none, the currently logged in user is used
        z%s/channels/%s/%sr   )r   r   r   r	   r
   )r   channelr   r   r   r   r   r   show_channel   s    zChannelsMixin.show_channelNc       
      C   sF   d| j ||f }t|||d\}}| jj|||d}	| |	dg dS )a  
        Add a channel to the specified files
        
        :param channel: channel to add
        :param owner: The user to add the channel to (all files of all packages for this user)
        :param package: The package to add the channel to (all files in this package)
        :param version: The version to add the channel to (all files in this version of the package)
        :param filename: The exact file to add the channel to
        
        z%s/channels/%s/%s)packageversionbasename)dataheaders   N)r   r   r   postr	   )
r   r   r   r   r   filenamer   r   r   r   r   r   r   add_channel    s    zChannelsMixin.add_channelc       
      C   sF   d| j ||f }t|||d\}}| jj|||d}	| |	dg dS )a  
        Remove a channel from the specified files
        
        :param channel: channel to remove
        :param owner: The user to remove the channel from (all files of all packages for this user)
        :param package: The package to remove the channel from (all files in this package)
        :param version: The version to remove the channel to (all files in this version of the package)
        :param filename: The exact file to remove the channel from
        
        z%s/channels/%s/%s)r   r   r   )r   r   r   N)r   r   r   deleter	   )
r   r   r   r   r   r   r   r   r   r   r   r   r   remove_channel1   s    zChannelsMixin.remove_channelc             C   s0   d| j |||f }| j|}| |dg dS )a)  
        Tag all files in channel <channel> also as channel <to_channel> 
        
        :param channel: channel to copy
        :param owner: Perform this operation on all packages of this user
        :param to_channel: Destination name (may be a channel that already exists)
        
        z%s/channels/%s/%s/copy/%sr   N)r   r   r   r	   )r   r   r   Z
to_channelr   r   r   r   r   copy_channelB   s    	zChannelsMixin.copy_channelc             C   s.   d| j ||f }| j|}| |dg dS )a)  
        Tag all files in channel <channel> also as channel <to_channel> 
        
        :param channel: channel to copy
        :param owner: Perform this operation on all packages of this user
        :param to_channel: Destination name (may be a channel that already exists)
        
        z%s/channels/%s/%s/lockr   N)r   r   r   r	   )r   r   r   r   r   r   r   r   lock_channelO   s    	zChannelsMixin.lock_channelc             C   s.   d| j ||f }| j|}| |dg dS )a)  
        Tag all files in channel <channel> also as channel <to_channel> 
        
        :param channel: channel to copy
        :param owner: Perform this operation on all packages of this user
        :param to_channel: Destination name (may be a channel that already exists)
        
        z%s/channels/%s/%s/lockr   N)r   r   r   r	   )r   r   r   r   r   r   r   r   unlock_channel\   s    	zChannelsMixin.unlock_channel)NNN)NNN)
__name__
__module____qualname__r   r   r   r   r   r    r!   r   r   r   r   r   
   s   



r   N)__doc__Zbinstar_client.utilsr   Zbinstar_client.errorsr   objectr   r   r   r   r   <module>   s   