How to modify output to url address not file path

06-28-2012 05:56 AM
New Contributor III
Currently I have GP on an arcgis server that is taking the results from a gp tool and packaging them into a zip file. The gp will give the output as a link to the resulting zipfile which can be easily downloaded while on a computer that is on the same network as the server machine.

the output links to http://services/arcgisjobs/clipandshiptest/spreadmodel2_gpserver/etc.... I want it to link to http://services.geog.blah/arcgisjobs/clipandshiptest/spreadmodel2_gpserver/etc.....

If I directly copy and paste the output link and modify services to services.geog.blah it downloads fine. How can I get the output link to give the services.geog.blah link instead of the services link?

Below is the zip file code which I found on this site.
# 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))
                    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):]))
                        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__':
        # 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. 
                zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_DEFLATED)
                zipws(infolder, zip, True)
        except RuntimeError:
                # Delete zip file if exists
                if os.path.exists(outfile):
                zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_STORED)
                zipws(infolder, zip, True)
                gp.AddWarning("    Unable to compress zip file contents.")

        gp.AddMessage("Zip file created successfully")

        # 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"

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

I tried taking the output file from the zip file and modifying the path
import os, arcpy
from os.path import normpath,abspath
path = arcpy.GetParameterAsText(0)
path = abspath(path)
file_name = path.split('\\')[-6]+'\\'+path.split('\\')[-5]+'\\'+ path.split('\\')[-4]+'\\'+ path.split('\\')[-3]+'\\'+ path.split('\\')[-2]+'\\'+ path.split('\\')[-1]
file_name = file_name.replace(' ','_')
file_directory = 'services.geog.blah\\'
path = r'http:\\'+file_directory+file_name

print path

arcpy.SetParameterAsText( 1, path)

Where Parameter 0 is the zip file and Parameter 1 is suppose to be the modified link.

When I run the above I get Parameter 1 = none which I cannot figure out why.
0 Kudos
0 Replies