def submit_for_build(self, username, package, fd, instructions, test_only=False, callback=None): url = '%s/build/%s/%s/stage' % (self.domain, username, package) data = jencode(instructions=instructions, test_only=test_only) res = self.session.post(url, data=data) self._check_response(res) obj = res.json() s3url = obj['s3_url'] s3data = obj['s3form_data'] _hexmd5, b64md5, size = compute_hash(fd) s3data['Content-Length'] = size s3data['Content-MD5'] = b64md5 data_stream, headers = stream_multipart(s3data, files={'file':(obj['basename'], fd)}, callback=callback) s3res = requests.post(s3url, data=data_stream, verify=True, timeout=10 * 60 * 60, headers=headers) if s3res.status_code != 201: raise BinstarError('Error uploading to s3', s3res.status_code) url = '%s/build/%s/%s/commit/%s' % (self.domain, username, package, obj['build_id']) res = self.session.post(url, verify=True) self._check_response(res, [201]) return obj['build_no']
def submit_for_build(self, username, package, fd, instructions, test_only=False, channels=None, queue=None, queue_tags=None, callback=None): url = '%s/build/%s/%s/stage' % (self.domain, username, package) data, headers = jencode(instructions=instructions, test_only=test_only, channels=channels, queue_name=queue, queue_tags=queue_tags) res = self.session.post(url, data=data, headers=headers) self._check_response(res) obj = res.json() s3url = obj['post_url'] s3data = obj['form_data'] _hexmd5, b64md5, size = compute_hash(fd) s3data['Content-Length'] = size s3data['Content-MD5'] = b64md5 data_stream, headers = stream_multipart(s3data, files={'file':(obj['basename'], fd)}, callback=callback) s3res = requests.post(s3url, data=data_stream, verify=True, timeout=10 * 60 * 60, headers=headers) if s3res.status_code != 201: raise BinstarError('Error uploading build', s3res.status_code) url = '%s/build/%s/%s/commit/%s' % (self.domain, username, package, obj['build_id']) res = self.session.post(url, verify=True) self._check_response(res, [201]) return obj
def upload(self, login, package_name, release, basename, fd, distribution_type, description='', md5=None, size=None, attrs=None, callback=None): ''' Upload a new distribution to a package release. :param login: the login of the package owner :param package_name: the name of the package :param version: the version string of the release :param basename: the basename of the distribution to download :param fd: a file like object to upload :param description: (optional) a short description about the file :param attrs: any extra attributes about the file (eg. build=1, pyversion='2.7', os='osx') ''' url = '%s/stage/%s/%s/%s/%s' % (self.domain, login, package_name, release, basename) if attrs is None: attrs = {} if not isinstance(attrs, dict): raise TypeError('argument attrs must be a dictionary') payload = dict(distribution_type=distribution_type, description=description, attrs=attrs) data = jencode(payload) res = self.session.post(url, data=data, verify=True) self._check_response(res) obj = res.json() s3url = obj['s3_url'] s3data = obj['s3form_data'] if md5 is None: _hexmd5, b64md5, size = compute_hash(fd, size=size) elif size is None: spos = fd.tell() fd.seek(0, os.SEEK_END) size = fd.tell() - spos fd.seek(spos) s3data['Content-Length'] = size s3data['Content-MD5'] = b64md5 data_stream, headers = stream_multipart(s3data, files={'file':(basename, fd)}, callback=callback) s3res = requests.post(s3url, data=data_stream, verify=True, timeout=10 * 60 * 60, headers=headers) if s3res.status_code != 201: print s3res.text print print raise BinstarError('Error uploading to s3', s3res.status_code) url = '%s/commit/%s/%s/%s/%s' % (self.domain, login, package_name, release, basename) payload = dict(dist_id=obj['dist_id']) data = jencode(payload) res = self.session.post(url, data=data, verify=True) self._check_response(res) return res.json()
def _put_on_s3(self, archive_filename, uploaded_basename, url, s3data): with open(archive_filename, 'rb') as f: _hexmd5, b64md5, size = binstar_utils.compute_hash(f, size=os.path.getsize(archive_filename)) s3data = s3data.copy() # don't modify our parameters s3data['Content-Length'] = size s3data['Content-MD5'] = b64md5 with open(archive_filename, 'rb') as archive_file_object: data_stream, headers = binstar_requests_ext.stream_multipart( s3data, files={'file': (uploaded_basename, archive_file_object)}) res = requests.post(url, data=data_stream, verify=self._api.session.verify, timeout=10 * 60 * 60, headers=headers) self._check_response(res) return res
def file_upload(self, url, obj): _hexmd5, b64md5, size = compute_hash( self.project.tar, size=self.project.size) s3data = obj['form_data'] s3data['Content-Length'] = size s3data['Content-MD5'] = b64md5 data_stream, headers = stream_multipart( s3data, files={'file': (self.project.basename, self.project.tar)}) s3res = requests.post( url, data=data_stream, verify=self.session.verify, timeout=10 * 60 * 60, headers=headers) if s3res.status_code != 201: raise binstar_client.errors.BinstarError( 'Error uploading package', s3res.status_code) return s3res