Ejemplo n.º 1
0
 def deleteFromPublishedAlbum(self):
   """ grab the album main.json file and update the snap that appears within it """
   tm = time.time()
   alb = self.album
   aurl = "http://s3.imagediver.org"+constants.topicDir+alb+"/main.json"
   albs = urllib2.urlopen(aurl).read()
   albd = json.loads(albs)
   rs = []
   sns = albd["snaps"]
   mxo = 0
   myt = self.topic
   isDelete = False
   for sn in sns:
     tp = sn["topic"]
     if tp==myt:
       isDelete = True
     else:
       rs.append(sn)
   if not isDelete:
     return
   s3path = constants.topicDir+alb+"/main.json" #the path where the page will finally end up
   albd["snaps"]= rs
   js = json.dumps(albd)
   s3.s3SetContents(s3path,contents=js,relativeTo="",contentType="application/json")
   etm = time.time() - tm
   vprint("deleteFromPublishedAlbum ",self.topic," took ",etm,"seconds")
Ejemplo n.º 2
0
 def publish(self,includeImages=True,pageStore=None):
   #vprint("PUBLISHING ",self.__dict__)
   """ the snap images appear under the image directory (/imagowner/imagename). pageOnly means don't bother with generating json"""
   alb = self.album
   tpo = misc.topicOb(alb)
   imtopic = tpo.imageTopic()
   imdir = tpo.imageOwner + "/" + tpo.imageName
   vprint("PUBLISH SNAP",self.topic," with IMAGE ",imtopic,"imdir",imdir)
   js = self.compute_json(False)
   tp = self.topic
   #topicdir = "/topicd/" if constants.publishToS3Dev else "/topic/"
   s3path = constants.topicDir+tp+"/main.json" #the path where the page will finally end up
   s3.s3SetContents(s3path,contents=js,relativeTo="",contentType="application/json")
   self.genPage(True)
   if not includeImages:
     return
   imageD = image.loadImageD(imtopic,getattr(self,"pageStore",None))
   """
   public = getattr(imageD,"isPublic",None)
   if not public:
     imageD.isPublic = 1
     imageD.dynsave(False)
   """
   crid = self.cropid;
   fls = [imdir+"/snap/"+str(crid)+".jpg",imdir+"/snapthumb/"+str(crid)+".jpg"]
   for fl in fls:
     vprint("about to save "+fl)
     s3.s3SaveFile(fl,relativeTo="images",contentType="image/jpeg")
Ejemplo n.º 3
0
 def publishInAlbum(self):
   """ grab the album main.json file and update the snap that appears within it """
   tm = time.time()
   alb = self.album
   aurl = "http://s3.imagediver.org"+constants.topicDir+alb+"/main.json"
   albs = urllib2.urlopen(aurl).read()
   albd = json.loads(albs)
   byt = {}
   sns = albd["snaps"]
   mxo = 0
   for sn in sns:
     tp = sn["topic"]
     o = int(sn.get("ordinal",0))
     #print "TP ",tp,"ORD",o
     if o > mxo: mxo = o
     byt[tp] = sn
   exv = self.externalize()
   cv = byt.get(self.topic,None)
   #print "CV",cv," mxo ",mxo
   if cv:
     nord = cv.get("ordinal",mxo+1)
   else:
     nord = mxo+1
   exv["ordinal"] = nord
   byt[self.topic] = exv
   s3path = constants.topicDir+alb+"/main.json" #the path where the page will finally end up
   nsns = []
   for sn in byt.itervalues():
     nsns.append(sn)
   albd["snaps"]= nsns
   js = json.dumps(albd)
   s3.s3SetContents(s3path,contents=js,relativeTo="",contentType="application/json")
   etm = time.time() - tm
   vprint("publishInAlbum ",self.topic," took ",etm,"seconds")
Ejemplo n.º 4
0
 def genPage(self,sendToS3=True,compressJs=True):
   #vprint("CONSTANTS.COMPRESS",constants.compressJs)
   pagetext = "" # LATER fix this; pagetext is for custom pages
   pg0= gen.pageHeader("","ImageDiver") + "<body>"
   svdv = constants.devVersion
   if sendToS3: constants.devVersion = 0
   if  (sendToS3 or constants.compressJs):
     pg0 += constants.jsPreamble + constants.cjsForPage("common") +  constants.cjsForPage("snap")
   else:
     pg0 +=  constants.jsPreamble + constants.toJsIncludes(constants.commonJsFiles) + constants.toJsIncludes(constants.jsFiles['snap'])
   constants.devVersion = svdv
   pg1 = """
   <script>
   page.initialize();
   </script>
   <div class="outerDiv">
     <div class="topDiv">
         <div class="topDivTop"></div>
        <div class="titleDiv"></div>
     </div>
   </div>
   </body>
   </html>
   """
   pg =  pg0 + pg1
   #fl = "/mnt/ebs1/imagediver/temp/snap.html"
   tp = self.topic
   #topicdir = "/topicd" if constants.publishToS3Dev else "/topic"
   s3path = constants.topicDir+tp+"/index.html" #the path where the page will finally end up
   #models.writeFile(fl,pg)
   #print "publishing to ",s3path
   #return pg
   if sendToS3:
     s3.s3SetContents(s3path,contents=pg,relativeTo="",contentType="text/html")
   return pg
Ejemplo n.º 5
0
    def genPage(self, sendToS3=True):
        txt = "<script>page.initialize();</script>"

        headLines = []
        styleSheets = ["/css/faq.css"]

        jsFiles = '<script type="text/javascript" src="/ncjs/composite.js"></script>\n'

        headerTitle = "Composite: " + self.name
        pageTitle = headerTitle

        pg = gen.genHtmlPage(None,
                             jsFiles,
                             headerTitle,
                             headLines,
                             txt,
                             pageTitle=pageTitle)
        #fl = "/mnt/ebs1/imagediver/temp/snap.html"
        name = self.name
        #topicdir = "/topicd" if constants.publishToS3Dev else "/topic"
        s3path = constants.compositeDir + "/" + name + "/index.html"  #the path where the page will finally end up
        if sendToS3:
            s3.s3SetContents(s3path,
                             contents=pg,
                             relativeTo="",
                             contentType="text/html")
        return pg
Ejemplo n.º 6
0
def sendFile(fl, contentType, versioned=True):
    if versioned: fl = versionedFilename(fl)
    path = fl
    srcFile = js_srcdir + fl
    print "sending ", srcFile, "to", path
    s3.s3SetContents(path, srcFile, relativeTo="/", contentType=contentType)
    print "sent "
Ejemplo n.º 7
0
def sendFile(fl, contentType):
    srcDir = "/mnt/ebs0/imagediverdev/www"
    dstDir = "/devjs7921"
    path = dstDir + fl
    srcFile = srcDir + fl
    print "sending ", srcFile, "to", path
    s3.s3SetContents(path, srcFile, relativeTo="/", contentType=contentType)
    print "sent "
Ejemplo n.º 8
0
    def publish(self):
        #vprint("PUBLISHING ",self.__dict__)
        """ the snap images appear under the image directory (/imagowner/imagename). pageOnly means don't bother with generating json"""

        js = self.compute_json()
        name = self.name
        #topicdir = "/topicd/" if constants.publishToS3Dev else "/topic/"
        s3path = constants.compositeDir + "/" + name + "/main.json"  #the path where the page will finally end up
        s3.s3SetContents(s3path,
                         contents=js,
                         relativeTo="",
                         contentType="application/json")
        self.genPage()
Ejemplo n.º 9
0
 def updateS3(self):
   """ grab the album main.json file and update the snap that appears within it """
   tm = time.time()
   tp = self.topic
   aurl = "http://s3.imagediver.org"+constants.topicDir+tp+"/main.json"
   albs = urllib2.urlopen(aurl).read()
   albd = json.loads(albs)
   exv = self.externalize()
   exv["snaps"] = albd["snaps"]
   s3path = constants.topicDir+tp+"/main.json" #the path where the page will finally end up
   js = json.dumps(exv)
   s3.s3SetContents(s3path,contents=js,relativeTo="",contentType="application/json")
   etm = time.time() - tm
   vprint("publishInAlbum ",self.topic," took ",etm,"seconds")
Ejemplo n.º 10
0
def exportJsForDev():
    cjs = constants.commonJsFiles
    sjs = constants.jsFiles['snap']
    ajs = constants.jsFiles['album']
    ss = set(cjs + sjs + ajs)
    for s in ss:
        srcFile = js_srcdir + s
        print "saving ", s
        #print s,srcFile
        #continue
        s3.s3SetContents(s,
                         srcFile,
                         relativeTo="/",
                         contentType="application/javascript")
    print "FILES ", ss
Ejemplo n.º 11
0
def sendFile(fl,contentType):
  global fromDev,toDev
  if fromDev:
    srcDir = "/mnt/ebs0/imagediverdev/www"
  else:
    srcDir = "/mnt/ebs0/imagediver/www"
  if toDev:
    dstDir ="/devjs7921"
  else:
    dstDir = "/"
  path = dstDir + fl;
  srcFile = srcDir + fl 
  print "sending ",srcFile,"to",path
  s3.s3SetContents(path,srcFile,relativeTo="/",contentType=contentType)
  print "sent "
Ejemplo n.º 12
0
def exportJs():
    for fl in s3fls + jsfls:
        copyFile(fl, js_srcdir, js_dstdir)
    for fl in s3flsNotVersioned + jsflsNotVersioned:
        copyFile(fl, js_srcdir, js_dstdir, False)

    for fl in s3fls:
        sendFile(fl, "application/javascript")
    for fl in s3flsNotVersioned:
        sendFile(fl, "application/javascript", False)

    sendFile("/css/imagestyle.css", "text/css")
    sendFile("/hx/canvas.swf", "application/x-shockwave-flash")
    sendFile("/minus.png", "image/png")
    sendFile("/plus.png", "image/png")
    s3.s3SetContents("/widget.js",
                     js_srcdir + "/ncjs/widget.0_11.js",
                     relativeTo="/",
                     contentType="application/javascript")
Ejemplo n.º 13
0
def sendFile(fl,contentType):
  path = fl;
  srcFile = js_srcdir + fl 
  print "sending ",srcFile,"to",path
  s3.s3SetContents(path,srcFile,relativeTo="/",contentType=contentType)
  print "sent "
Ejemplo n.º 14
0
  mv2archive(dir)

def copyDirFromDev(dr):
  print "Copying "+dr+" from DEV"
  shutil.copytree(srcdir+dr,dstdir+dr)

for dir in dirs:
  copyDirFromDev(dir)


for fl in files:
  mv2archive(fl)
  

def copyFileFromDev(dr):
  print "Copying "+dr+" from DEV"
  shutil.copyfile(srcdir+dr,dstdir+dr)



for fl in files:
  copyFileFromDev(fl)
  
s3.s3SetContents("/album/cg/The_Dutch_Proverbs/1/main.json",
                 srcFile="/mnt/ebs1/imagediver/topic/album/4294b0e/the_dutch_proverbs/1/main.json",relativeTo="topic",contentType="application/json")


s3.s3SetContents("/album/cg/The_Dutch_Proverbs/1/index.html",
                 srcFile="/mnt/ebs1/imagediver/topic/album/4294b0e/the_dutch_proverbs/1/index.html",relativeTo="topic",contentType="text/html")

  
Ejemplo n.º 15
0
 def publishJson(self,cn):
   tp = self.topic
   s3path = constants.topicDir+tp+"/main.json" #the path where the page will finally end up
   s3.s3SetContents(s3path,contents=cn,relativeTo="",contentType="application/json")    
Ejemplo n.º 16
0
 def publishHtml(self,cn):
   tp = self.topic
   s3path = constants.topicDir+tp+"/index.html" #the path where the page will finally end up
   vprint("PUBLISH HTML TO ",s3path)
   s3.s3SetContents(s3path,contents=cn,relativeTo="",contentType="text/html")    
Ejemplo n.º 17
0
 def sendPageToS3(self,srcFile=None):
   s3p = self.s3path()
   if srcFile:
     s3.s3SetContents(s3p,srcFile,relativeTo="topic",contentType="text/html")
   else:
     s3.s3SaveFile(s3p,relativeTo="topic",contentType="text/html")
Ejemplo n.º 18
0
def sendJs():
  srcFile = "/mnt/ebs0/imagediverdev/www/pages/composite.js"
  path = "/ncjs/composite.js"
  print "sending ",srcFile,"to",path
  s3.s3SetContents(path,srcFile,relativeTo="/",contentType="application/x-javascript")