Dear Jeff Anderson,

Thank you for your email.

It sounds very interesting to me.   I must confess that I am not a
programmer, and have no experience with Django.  But I have a project
in hand to do such a work.

Have you ever tried to use feedback.py to fire off another Python
script (external script)?  The external script may run for 2 - 3
minutes.

Perhaps you can show me how to use feedback.py to fire off a zip.py.

Your assistance will be deeply appreciated.

Sincerely,

David

2008/11/21 Jeff Anderson <[EMAIL PROTECTED]>:
> Shao wrote:
>> Dear ALL,
>>
>> I am very much interested in using a HTML to fire off a data
>> processing script to run over the internet.
>>
>> I will be very grateful if you can advise me on passing parameters
>> from an HTML form to a script and fire the script off to carry out
>> full execution, monitor its progress and return an innerHTML with link
>> (a name string of) the file generated back to allow user to download
>> the result.
>>
>> The script run over a period of 2 to 3 minutes.
>>
> I designed a system to do something similar, but never implemented it fully.
>
> Basically, a Django view would fire off a Python thread that would run
> the script, and report its progress. I chose to use a Django model that
> the Python thread would store its progress in. The progress was
> monitored by the end user via AJAX. It queried the progress of the job
> once a second or so until it was completed. I only implemented a proof
> of concept, where the script would only count to 100. Unfortunately, I
> didn't save the code. The project I was doing it for was scrapped. The
> proof of concept code was fairly easy to implement. I think it'd fit
> your bill.
>
> If you aren't familiar with AJAX, I suggest reading a tutorial about how
> AJAX works, and then consider using an AJAX library.
>
> Hopefully this gives you a good starting point.
>
>
> Jeff Anderson
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" 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/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Title: Shao Shi - call AJAX

Sending a Form with Ajax

  • Please fill out the entire form:
  • Name
  • Email
  • Adress
  • Type of Message
  • Comment
  • Complain
  • Your Message
  • hello world

Ajax - Python Response

#!/usr/bin/python
import cgi, os, sys, string

def gush(data):
    print "Content-type: text/html\n"
    print "<h3>Thanks, %(name)s!</h3>" % vars(data)
    print "Our customer's comments are always appreciated."
    print "They drive our business directions, as well as"
    print "help us with our karma."
    print "<p>Thanks again for the feedback!<p>"
    print "And feel free to enter more comments if you wish."
    print "<p>"+10*"&nbsp;"+"--Joe."

def whimper(data):
    print "Content-type: text/html\n"
    print "<h3>Sorry, %(name)s!</h3>" % vars(data)
    print "We're very sorry to read that you had a complaint"
    print "regarding our product__We'll read your comments"
    print "carefully and will be in touch with you."
    print "<p>Nevertheless, thanks for the feedback.<p>"
    print "<p>"+10*"&nbsp;"+"--Joe."

def bail():
    print "Content-type: text/html\n"
    print "<H3>Error filling out form</H3>"
    print "Please fill in all the fields in the form.<P>"
    print '<a href="http://localhost/comment.html";>'
    print 'Go back to the form</a>'
    sys.exit()

class FormData:
    """ A repository for information gleaned from a CGI form """
    def __init__(self, form):
        for fieldname in self.fieldnames:
            if not form.has_key(fieldname) or form[fieldname].value == "":
                bail()
            else:
                setattr(self, fieldname, form[fieldname].value)
        
class FeedbackData(FormData):
    """ A FormData generated by the comment.html form. """
    fieldnames = ('name', 'address', 'email', 'type', 'text')
    def __repr__(self):
        return "%(type)s from %(name)s on %(time)s" % vars(self)

DIRECTORY = '/home/brooks/public_html/cgi-bin/feedbackDir'

if __name__ == '__main__':
    sys.stderr = sys.stdout 
    form = cgi.FieldStorage()
    data = FeedbackData(form)
    if data.type == 'comment':
        gush(data)
    else:
        whimper(data)
#**********************************************************************
# Description:
#    Zips the contents of a folder.
# Parameters:
#   0 - Input folder.
#   1 - Output zip file. It is assumed that the user added the .zip 
#       extension.  
#**********************************************************************

# Import modules and create the geoprocessor
#
import sys, zipfile, arcgisscripting, os, traceback
gp = arcgisscripting.create()

# Function for zipping files.  If keep is true, the folder, along with 
#  all its contents, will be written to the zip file.  If false, only 
#  the contents of the input folder will be written to the zip file - 
#  the input folder name will not appear in the zip file.
#
def zipws(path, zip, keep):
    path = os.path.normpath(path)
    # os.walk visits every subdirectory, returning a 3-tuple
    #  of directory name, subdirectories in it, and filenames
    #  in it.
    #
    for (dirpath, dirnames, filenames) in os.walk(path):
        # Iterate over every filename
        #
        for file in filenames:
            # Ignore .lock files
            #
            if not file.endswith('.lock'):
                gp.AddMessage("Adding %s..." % os.path.join(path, dirpath, 
file))
                try:
                    if keep:
                        zip.write(os.path.join(dirpath, file),
                        os.path.join(os.path.basename(path), 
os.path.join(dirpath, file)[len(path)+len(os.sep):]))
                    else:
                        zip.write(os.path.join(dirpath, file),            
                        os.path.join(dirpath[len(path):], file)) 

                except Exception, e:
                    gp.AddWarning("    Error adding %s: %s" % (file, e))

    return None

if __name__ == '__main__':
    try:
        # Get the tool parameter values
        #
        infolder = gp.GetParameterAsText(0)
        outfile = gp.GetParameterAsText(1)      

        # Create the zip file for writing compressed data. In some rare
        #  instances, the ZIP_DEFLATED constant may be unavailable and
        #  the ZIP_STORED constant is used instead.  When ZIP_STORED is
        #  used, the zip file does not contain compressed data, resulting
        #  in large zip files. 
        #
        try:
                zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_DEFLATED)
                zipws(infolder, zip, True)
                zip.close()
        except RuntimeError:
                # Delete zip file if exists
                #
                if os.path.exists(outfile):
                        os.unlink(outfile)
                zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_STORED)
                zipws(infolder, zip, True)
                zip.close()
                gp.AddWarning("    Unable to compress zip file contents.")

        gp.AddMessage("Zip file created successfully")

    except:
        # Return any python specific errors as well as any errors from the 
geoprocessor
        #
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
        pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n 
   " +                 str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"
        gp.AddError(pymsg)

        msgs = "GP ERRORS:\n" + gp.GetMessages(2) + "\n"
        gp.AddError(msgs)
#**********************************************************************
# Description:
#    Zips the contents of a folder.
# Parameters:
#   0 - Input folder.
#   1 - Output zip file. It is assumed that the user added the .zip 
#       extension.  
#**********************************************************************

# Import modules and create the geoprocessor
#
import sys, zipfile, arcgisscripting, os, traceback
gp = arcgisscripting.create()

# Function for zipping files.  If keep is true, the folder, along with 
#  all its contents, will be written to the zip file.  If false, only 
#  the contents of the input folder will be written to the zip file - 
#  the input folder name will not appear in the zip file.
#
def zipws(path, zip, keep):
    path = os.path.normpath(path)
    # os.walk visits every subdirectory, returning a 3-tuple
    #  of directory name, subdirectories in it, and filenames
    #  in it.
    #
    for (dirpath, dirnames, filenames) in os.walk(path):
        # Iterate over every filename
        #
        for file in filenames:
            # Ignore .lock files
            #
            if not file.endswith('.lock'):
                gp.AddMessage("Adding %s..." % os.path.join(path, dirpath, 
file))
                try:
                    if keep:
                        zip.write(os.path.join(dirpath, file),
                        os.path.join(os.path.basename(path), 
os.path.join(dirpath, file)[len(path)+len(os.sep):]))
                    else:
                        zip.write(os.path.join(dirpath, file),            
                        os.path.join(dirpath[len(path):], file)) 

                except Exception, e:
                    gp.AddWarning("    Error adding %s: %s" % (file, e))

    return None

if __name__ == '__main__':
    try:
        # Get the tool parameter values
        #
        infolder = gp.GetParameterAsText(0)
        outfile = gp.GetParameterAsText(1)      

        # Create the zip file for writing compressed data. In some rare
        #  instances, the ZIP_DEFLATED constant may be unavailable and
        #  the ZIP_STORED constant is used instead.  When ZIP_STORED is
        #  used, the zip file does not contain compressed data, resulting
        #  in large zip files. 
        #
        try:
                zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_DEFLATED)
                zipws(infolder, zip, True)
                zip.close()
        except RuntimeError:
                # Delete zip file if exists
                #
                if os.path.exists(outfile):
                        os.unlink(outfile)
                zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_STORED)
                zipws(infolder, zip, True)
                zip.close()
                gp.AddWarning("    Unable to compress zip file contents.")

        gp.AddMessage("Zip file created successfully")

    except:
        # Return any python specific errors as well as any errors from the 
geoprocessor
        #
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
        pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n 
   " +                 str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"
        gp.AddError(pymsg)

        msgs = "GP ERRORS:\n" + gp.GetMessages(2) + "\n"
        gp.AddError(msgs)

Reply via email to