Package rhnpush :: Module rhnpush_v2
[hide private]
[frames] | no frames]

Source Code for Module rhnpush.rhnpush_v2

 1  # 
 2  # Copyright (c) 2008--2016 Red Hat, Inc. 
 3  # 
 4  # This software is licensed to you under the GNU General Public License, 
 5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 8  # along with this software; if not, see 
 9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
10  # 
11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
12  # granted to use or replicate Red Hat trademarks that are incorporated 
13  # in this software or its documentation. 
14  # 
15   
16  # 
17  # Package uploading tool 
18  # 
19   
20  import base64 
21   
22  from rhnpush import connection 
23 24 25 -class PackageUpload(connection.PackageUpload):
26 user_agent = "rhnpush" 27
28 - def set_auth(self, username, password):
29 auth_vals = self.encode_values([username, password]) 30 self.headers["%s-%s" % (self.header_prefix, "Auth")] = auth_vals
31
32 - def set_session(self, session_string):
33 self.headers["%s-%s" % (self.header_prefix, "Auth-Session")] = session_string
34
35 - def set_force(self, force):
36 if force: 37 force = 1 38 else: 39 force = 0 40 self.headers["%s-%s" % (self.header_prefix, "Force")] = str(force)
41
42 - def set_null_org(self, null_org):
43 if null_org: 44 self.headers["%s-%s" % (self.header_prefix, "Null-Org")] = "1"
45
46 - def set_timeout(self, timeout):
47 self.connection.set_timeout(timeout)
48 49 # Encodes an array of variables into Base64 (column-separated) 50 @staticmethod
51 - def encode_values(arr):
52 val = ':'.join([x.strip() for x in map(base64.encodestring, arr)]) 53 # Get rid of the newlines 54 val = val.replace('\n', '') 55 # And split the result into lines of fixed size 56 line_len = 80 57 result = [] 58 start = 0 59 while 1: 60 if start >= len(val): 61 break 62 result.append(val[start:start + line_len]) 63 start = start + line_len 64 return result
65
66 67 -class PingPackageUpload(connection.PackageUpload):
68 user_agent = "rhnpush-ping" 69
70 - def ping(self):
71 self.send_http("GET") 72 # return the header info as well to check for capabilities. 73 return self._response.status, self._response.reason, self._response.msg
74