Revision: 1409
Author: sebastien.lelong
Date: Sat Oct 24 03:15:44 2009
Log: JAPP: use config file for both shell/python scripts, improve  
multiparts in emails, fix title extraction from HTML
http://code.google.com/p/jallib/source/detail?r=1409

Modified:
  /trunk/tools/japp/htmlizer.py
  /trunk/tools/japp/japp.sh
  /trunk/tools/japp/publish.py

=======================================
--- /trunk/tools/japp/htmlizer.py       Thu Oct 22 22:57:34 2009
+++ /trunk/tools/japp/htmlizer.py       Sat Oct 24 03:15:44 2009
@@ -101,13 +101,14 @@

  # remove title, because title will be put in mail's subject. So leaving it  
here would
  # produce twice title
-h1s = body.findAll("h1")
+h1s = body.findAll("h1",)
  if not h1s:
      print >> sys.stderr, "No <h1> element found, title will correspond to  
filename '%s'" % basen
      title = basen
  else:
      # there should be only one element, but anyway remove first one
-    title = h1s[0].renderContents()
+       # only keep text content, not potential inner elements
+    title = h1s[0].findAll(text=True)[0]
      h1s[0].replaceWith("")

  # we're done
=======================================
--- /trunk/tools/japp/japp.sh   Thu Oct 22 22:57:34 2009
+++ /trunk/tools/japp/japp.sh   Sat Oct 24 03:15:44 2009
@@ -14,6 +14,7 @@
  #  3. format and send an email with content & attachements

  source japp_config.py
+
  if [ "$?" != "0" ]
  then
     echo "Unable to source configuration file 'japp_config.py'"
@@ -34,12 +35,6 @@
     exit 255
  fi

-if [ "$JAPP_EMAIL" = "" ]
-then
-   echo "Please set JAPP_EMAIL env. variable to an account monitored by  
the website (mailhandler)"
-   exit 255
-fi
-
  if [ "$JAPP_TMP" = "" ]
  then
     JAPP_TMP=/tmp/japptmp
@@ -47,9 +42,11 @@

  while read DITAFILE
  do
+   [[ $DITAFILE == \#* ]] && continue
     echo "Processing file '$DITAFILE'..."
     ext=`echo $DITAFILE | sed "s#.*\.\(.*\)\\$#\1#"`
-   noext=`echo $DITAFILE | sed "s#\(.*\)\..*\\$#\1#"`
+   basen=`basename $DITAFILE`
+   noext=`echo $basen | sed "s#\(.*\)\..*\\$#\1#"`

     if [ "$ext" = "ditamap" ]
     then
=======================================
--- /trunk/tools/japp/publish.py        Thu Oct 22 22:57:34 2009
+++ /trunk/tools/japp/publish.py        Sat Oct 24 03:15:44 2009
@@ -1,4 +1,4 @@
-import smtplib, sys
+import smtplib, sys, os

  from email.mime.text import MIMEText
  from email.mime.image import MIMEImage
@@ -19,7 +19,7 @@
  path = file("%s/path" % topublish).read()

  # Create the container (outer) email message.
-msg = MIMEMultipart()
+msg = MIMEMultipart('related')
  msg['Subject'] = title
  # me == the sender's email address
  me = japp_config.FROM_ADDRESS
@@ -27,9 +27,9 @@
  msg['From'] = me
  msg['To'] = dest

-commands = """
-pass: %s
+commands = """pass: %s
  path: content/%s
+uid: 3

  """ % (japp_config.FROM_PASSWD,path)

@@ -37,14 +37,15 @@
  msg.attach(txt)

  # Assume we know that the image files are all in PNG format
-pngfiles =  
["/tmp/japptmp/topublish/i2c_connector.jpg","/tmp/japptmp/topublish/i2c_crimescene.jpg","/tmp/japptmp/topublish/i2c_details.jpg","/tmp/japptmp/topublish/i2c_pseudoecho.png","/tmp/japptmp/topublish/i2c_seb_mainboard_facade.jpg","/tmp/japptmp/topublish/i2c_seb_mainboard_up.jpg"]
-for file in pngfiles:
+imgfiles = map(lambda x: os.path.join(topublish,x),[f for f in  
os.listdir(topublish) if not f in ['title','content','path']])
+for img in imgfiles:
      # Open the files in binary mode.  Let the MIMEImage class automatically
      # guess the specific image type.
-    fp = open(file, 'rb')
-    img = MIMEImage(fp.read())
+    fp = open(img, 'rb')
+    imgm = MIMEImage(fp.read())
+    imgm['Content-Disposition'] = 'attachment; filename="%s"' %  
os.path.basename(img)
      fp.close()
-    msg.attach(img)
+    msg.attach(imgm)

  # Send the email via our own SMTP server.
  s = smtplib.SMTP()

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to