ChannelsMixin   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 94
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A unlock_channel() 0 12 1
A show_channel() 0 9 1
A copy_channel() 0 12 1
A list_channels() 0 9 1
A remove_channel() 0 16 1
A add_channel() 0 16 1
A lock_channel() 0 12 1
1
'''
2
Created on May 2, 2014
3
4
@author: sean
5
'''
6
7
from binstar_client.utils import jencode
8
from binstar_client.errors import BinstarError
9
10
class ChannelsMixin(object):
11
12
    def list_channels(self, owner):
13
        '''List the channels for owner
14
        If owner is none, the currently logged in user is used
15
        '''
16
        url = '%s/channels/%s' % (self.domain, owner)
17
18
        res = self.session.get(url)
19
        self._check_response(res, [200])
20
        return res.json()
21
22
    def show_channel(self, channel, owner):
23
        '''List the channels for owner
24
        If owner is none, the currently logged in user is used
25
        '''
26
        url = '%s/channels/%s/%s' % (self.domain, owner, channel)
27
28
        res = self.session.get(url)
29
        self._check_response(res, [200])
30
        return res.json()
31
32
    def add_channel(self, channel, owner, package=None, version=None, filename=None):
33
        '''
34
        Add a channel to the specified files
35
        
36
        :param channel: channel to add
37
        :param owner: The user to add the channel to (all files of all packages for this user)
38
        :param package: The package to add the channel to (all files in this package)
39
        :param version: The version to add the channel to (all files in this version of the package)
40
        :param filename: The exact file to add the channel to
41
        
42
        '''
43
        url = '%s/channels/%s/%s' % (self.domain, owner, channel)
44
        data, headers = jencode(package=package, version=version, basename=filename)
45
46
        res = self.session.post(url, data=data, headers=headers)
47
        self._check_response(res, [201])
48
49
    def remove_channel(self, channel, owner, package=None, version=None, filename=None):
50
        '''
51
        Remove a channel from the specified files
52
        
53
        :param channel: channel to remove
54
        :param owner: The user to remove the channel from (all files of all packages for this user)
55
        :param package: The package to remove the channel from (all files in this package)
56
        :param version: The version to remove the channel to (all files in this version of the package)
57
        :param filename: The exact file to remove the channel from
58
        
59
        '''
60
        url = '%s/channels/%s/%s' % (self.domain, owner, channel)
61
        data, headers = jencode(package=package, version=version, basename=filename)
62
63
        res = self.session.delete(url, data=data, headers=headers)
64
        self._check_response(res, [201])
65
66
    def copy_channel(self, channel, owner, to_channel):
67
        '''
68
        Tag all files in channel <channel> also as channel <to_channel> 
69
        
70
        :param channel: channel to copy
71
        :param owner: Perform this operation on all packages of this user
72
        :param to_channel: Destination name (may be a channel that already exists)
73
        
74
        '''
75
        url = '%s/channels/%s/%s/copy/%s' % (self.domain, owner, channel, to_channel)
76
        res = self.session.post(url)
77
        self._check_response(res, [201])
78
79
    def lock_channel(self, channel, owner):
80
        '''
81
        Tag all files in channel <channel> also as channel <to_channel> 
82
        
83
        :param channel: channel to copy
84
        :param owner: Perform this operation on all packages of this user
85
        :param to_channel: Destination name (may be a channel that already exists)
86
        
87
        '''
88
        url = '%s/channels/%s/%s/lock' % (self.domain, owner, channel)
89
        res = self.session.post(url)
90
        self._check_response(res, [201])
91
92
    def unlock_channel(self, channel, owner):
93
        '''
94
        Tag all files in channel <channel> also as channel <to_channel> 
95
        
96
        :param channel: channel to copy
97
        :param owner: Perform this operation on all packages of this user
98
        :param to_channel: Destination name (may be a channel that already exists)
99
        
100
        '''
101
        url = '%s/channels/%s/%s/lock' % (self.domain, owner, channel)
102
        res = self.session.delete(url)
103
        self._check_response(res, [201])
104
105