Пример #1
0
    def savePicture(self, path):
        """Saves the picture blob to disk."""

        buf = StringIO(self.picture)
        with open(path, 'w') as fd:
            buf.seek(0)
            shutil.copyfileobj(buf, fd)

        return buf
Пример #2
0
 def write_xls(file_name, sheet_name, headings, data, heading_xf, data_xfs, kinds):
     book = xlwt.Workbook(encoding='utf8')
     sheet = book.add_sheet(sheet_name)
     rowx = 0
     for colx, value in enumerate(headings):
         sheet.write(rowx, colx, value, heading_xf)
     sheet.set_panes_frozen(True) # frozen headings instead of split panes
     sheet.set_horz_split_pos(rowx+1) # in general, freeze after last heading row
     sheet.set_remove_splits(True) # if user does unfreeze, don't leave a split there
     sheet.set_col_default_width(True)
     color_charts = {}
     for state, color in state_color_map.iteritems() :
         color_charts[state] = xlwt.easyxf("""font:
                      height 180,
                      name Times New Roman,
                      colour_index %s,
                      bold on;
                  align:
                      wrap on,
                      vert centre,
                      horiz center
                  """ % color)
     
     for row in data:
         rowx += 1
         for colx, value in enumerate(row) :
             style = data_xfs[colx]
             if file_name == "requisitions" and kinds[colx] != 'money' :
                 state = row[-1]
                 style = color_charts[state]
             sheet.write(rowx, colx, (value not in ('None', '0.00') and value) or '', style)
     # book.save(file_name)
     
     # ene hesgiig huulav
     from StringIO import StringIO
     result = StringIO()
     book.save(result)
     result.seek(0)
     
     response = HttpResponse(result.read(), mimetype='application/ms-excel')
     if file_name:
         response['Content-Disposition'] = 'attachment; filename='+file_name+".xls"
     else:
         response['Content-Disposition'] = 'attachment; filename=export.xls' 
     return response
Пример #3
0
 def docker_pull(self, namespace, repos):
     # Test pull
     # Docker -> Index
     resp = requests.get('{0}/v1/repositories/{1}/{2}/images'.format(
         self.index_endpoint, namespace, repos),
         auth=tuple(self.user_credentials),
         headers={'X-Docker-Token': 'true'})
     self.assertEqual(resp.status_code, 200)
     token = resp.headers.get('x-docker-token')
     # Here we should use the 'X-Endpoints' returned in a real environment
     # Docker -> Registry
     resp = requests.get('{0}/v1/repositories/{1}/{2}/tags/latest'.format(
                         self.registry_endpoint, namespace, repos),
                         headers={'Authorization': 'Token ' + token})
     self.assertEqual(resp.status_code, 200, resp.text)
     self.cookies = resp.cookies
     # Docker -> Registry
     image_id = json.loads(resp.text)
     resp = requests.get('{0}/v1/images/{1}/ancestry'.format(
         self.registry_endpoint, image_id),
         cookies=self.cookies)
     self.update_cookies(resp)
     self.assertEqual(resp.status_code, 200, resp.text)
     ancestry = json.loads(resp.text)
     # We got the ancestry, let's fetch all the images there
     for image_id in ancestry:
         json_data, checksum, blob = self.fetch_image(image_id)
         # check queried checksum and local computed checksum from the image
         # are the same
         tmpfile = StringIO()
         tmpfile.write(blob)
         tmpfile.seek(0)
         computed_checksum = checksums.compute_simple(tmpfile, json_data)
         tmpfile.close()
         self.assertEqual(checksum, computed_checksum)
     # Remove image tags
     resp = requests.delete('{0}/v1/repositories/{1}/{2}/tags'.format(
         self.registry_endpoint, namespace, repos), cookies=self.cookies)
     self.assertEqual(resp.status_code, 200, resp.text)
     self.update_cookies(resp)
     # Remove image_id, then parent_id
     store = storage.load()
     store.remove(os.path.join(store.images, self.image_id))
     store.remove(os.path.join(store.images, self.parent_id))