def draw_progress_bar(param, current, total): """Draws a text based progress report. """ pct = 100 - ((total - current) * 100) / (total) clear_progress_bar(out=out) reset_progress_bar(out=out) out.write("Uploaded %s out of %s bytes [%s%%]" % ( localize(current), localize(total), pct)) reset_progress_bar(out=out)
"message": "The resource couldn't be created"}} try: args.update({os.path.basename(file_name): open(file_name, "rb")}) except IOError: sys.exit("Error: cannot read training set") if progress_bar: body, headers = multipart_encode(args, cb=draw_progress_bar) else: body, headers = multipart_encode(args) request = urllib2.Request(self.source_url + self.auth, body, headers) try: response = urllib2.urlopen(request) clear_progress_bar(out=out) reset_progress_bar(out=out) code = response.getcode() if code == HTTP_CREATED: location = response.headers['location'] content = response.read() resource = json.loads(content, 'utf-8') resource_id = resource['resource'] error = {} except ValueError: LOGGER.error("Malformed response") except urllib2.HTTPError, exception: LOGGER.error("Error %s", exception.code) code = exception.code if code in [HTTP_BAD_REQUEST, HTTP_UNAUTHORIZED,