Example #1
0
 def post(self):
   upload_files = self.get_uploads('file')  # 'file' is file upload field in the form
   blob_info = upload_files[0]
   page = SvgPage()
   page.name = self.request.get('name',"")
   page.summary = self.request.get('summary',"")
   page.svgBlob=blob_info.key()
   page.svgid = svgcounter.one()
   hash = page.getHash('both')
   logging.info(" id %s hash '%s'" % (page.svgid,hash))
   page.put()
   self.redirect('/s/%s' % newbase60.numtosxg(page.svgid))
   taskqueue.add(url='/makepingfromsvg/%s' % newbase60.numtosxg(page.svgid))
   taskqueue.add(url='/sendsvgtoarchive/%s' % newbase60.numtosxg(page.svgid))
Example #2
0
 def get(self, filename):
   pages= []
   if filename:
       bits= filename.split('.')
       key = bits[0]
       resource = int(newbase60.sxgtonum(urllib.unquote(key)))
       qry = SvgPage.query(SvgPage.svgid == resource)
       pages = qry.fetch(1)
       svgStr = newbase60.numtosxg(resource)
   if pages:
       etag = pages[0].getHash('both').encode('utf8')
       self.response.headers["Etag"] = '%s' % etag
       template = JINJA_ENVIRONMENT.get_template('svgpage.html')
       svgVals = { 'name':pages[0].name,
                   'summary':pages[0].summary,
                   'published':pages[0].published,
                   'url':'/i/'+ svgStr+'.svg',
                   'rawurl':'/raw/'+ str(pages[0].svgBlob),
                   }
       for kind in ('image','iframe','direct','png','hash'):
           svgVals[kind+"_link"] = pages[0].getLink(kind)
           svgVals["old_link"] = pages[0].getLink('image',site=oldSiteName)
       self.response.headers["Link"] = '<https://webmention.herokuapp.com/api/webmention>; rel="webmention"'
   else:
       template = JINJA_ENVIRONMENT.get_template('errorpage.html')
       svgVals = { 'error':"No such image as %s" % filename }
       self.response.set_status(404)
   self.response.write(template.render(svgVals))
Example #3
0
 def get(self):
   upload_url = blobstore.create_upload_url('/upload')
   template = JINJA_ENVIRONMENT.get_template('homepage.html')
   qry = SvgPage.query().order(-SvgPage.published)
   recentpix=qry.fetch(100)
   
   pix = [ {"name":"%s" % page.name, "svgid":newbase60.numtosxg(page.svgid),"published":page.published} for page in recentpix if page.nipsa !=True ][:60]
   self.response.write(template.render({'upload_url':upload_url, 'pix':pix, 'admin':users.is_current_user_admin()}))
Example #4
0
 def getLink(self, kind="image",absolute=True,site=siteName):
     svgStr = newbase60.numtosxg(self.svgid)
     if kind=='hash':
         link ="/getbyhash/%s" % (self.getHash())
     else:
         pattern = {'iframe':'/f/%s', 'direct':'/i/%s.svg', 'png':'/p/%s.png'}.get(kind,'/s/%s')
         link = pattern % (svgStr)
     if absolute:
         link = site+link
     return link
Example #5
0
 def post(self, filename):
   status="pending"
   bits= filename.split('.')
   key = bits[0]
   extension = '.png'
   if len(bits)>1:
       extension = bits[1] #awaiting conditional code for png/jpg
   resource = int(newbase60.sxgtonum(urllib.unquote(key)))
   qry = SvgPage.query(SvgPage.svgid == resource)
   width = str(self.request.get('width', "0"))
   force = self.request.get('force')
   pages = qry.fetch(1)
   page=None
   if len(pages)>0:
       page = pages[0]
   if not page:
       status="no such svg"
   elif not force and page.pngFile:
       status="file exists"
   else:
       urlbits= list(urlparse.urlsplit(self.request.uri))
       urlbits[2] = '/f/'+key
       urlbits[3] = ''
       svgurl= urlparse.urlunsplit(urlbits)
       url = "https://savageping.herokuapp.com/u?" + urllib.urlencode({"url":svgurl,"width":1024})
       urlfetch.set_default_fetch_deadline(180)
       result = urlfetch.fetch(url)
       rawpng=None
       if result.status_code == 200:
         rawpng= result.content
       else:
           status="error from service: %s" %(result.status_code)
       if (rawpng):
           logging.info(" png %s" % rawpng[0:256])
           bucket_name = os.environ.get('BUCKET_NAME',
                                        app_identity.get_default_gcs_bucket_name())
           filename = '/' + bucket_name + '/p/%s.png' % newbase60.numtosxg(page.svgid)
           gcs_file = gcs.open(filename, 'w', content_type='image/png')
           gcs_file.write(rawpng)
           gcs_file.close()
           # Get the file's blob key
           #page.pngBlob = blobstore.create_gs_key("/gs"+ filename)
           page.pngFile =  blobstore.create_gs_key("/gs"+ filename)
           status="file created"
           page.put()
   logging.info("PngFromSvgHandler "+ key +" status: " + status)
   self.response.write("svg to png "+ key +" status: " + status) 
Example #6
0
 def get(self, filename):
   bits= filename.split('.')
   key = bits[0]
   extension = '.svg'
   if len(bits)>1:
       extension = bits[1] #awaiting conditional code for png/jpg
   resource = int(newbase60.sxgtonum(urllib.unquote(key)))
   qry = SvgPage.query(SvgPage.svgid == resource)
   pages = qry.fetch(1)
   svgStr = newbase60.numtosxg(resource)
   blob_info = blobstore.BlobInfo.get(pages[0].svgBlob)
   template = JINJA_ENVIRONMENT.get_template('iframe.html')
   reader = blobstore.BlobReader(blob_info)
   rawsvg = reader.read().decode('utf-8')
   svgVals = { 'name':pages[0].name,
               'svg': rawsvg,
               'image_link':siteName+'/s/'+svgStr,
               'url':'/i/'+ svgStr+'.svg',
               }
   self.response.write(template.render(svgVals))    
Example #7
0
 def test_check0(self):
     self.assertEqual(newbase60.numtosxg(0), '0')
Example #8
0
 def test_roundtrip(self):
     '''sxgtonum(numtosxg(n))==n for all n'''
     for integer in range(0, 6000):
         sxg = newbase60.numtosxg(integer)
         result = newbase60.sxgtonum(sxg)
         self.assertEqual(integer, result)
Example #9
0
 def test_check60(self):
     self.assertEqual(newbase60.numtosxg(60), '10')
Example #10
0
 def test_check1(self):
     self.assertEqual(newbase60.numtosxg(1), '1')