[Zope] one time downloads

Ed Colmar ed@greengraphics.net
Mon, 23 Jun 2003 11:24:24 -0700 (PDT)


Thanks for all the responses.

Here is what I ended up doing, for those of you that would like to do
something similar.

I love the zope community.  You all rock!

-ed-


    def genfoldername(self):
        """ generate a random folder name """
        chars = string.letters + string.digits
        foldername = ''
        for i in range(23):
            foldername = foldername + choice(chars)
        return foldername

    def make_download_folder(self, filename, useridref):
        """ make a temporary download location """
        f_base = "/somestoragefolder/" # file storage
        d_base = "/sometempfolder/" # temporary download location
        ## First, Generate a random string
        foldername = self.genfoldername()
        ## Make a download folder
        tempdlpath = d_base + foldername
        os.mkdir(tempdlpath)
        ## Make a symbolic link to the temporary folder
        filepath = f_base + filename
        tempfilepath = tempdlpath + '/' + filename
        os.symlink(filepath, tempfilepath)
        ## Check DB for other items matching this useridref
        result = self.SQL_get_downloads_by_useridref(useridref=useridref)
        ## Delete all outstanding downloads
        for download in result:
            this_downloadid = download['downloadid']
            this_filename = download['filename']
            this_folder = download['foldername']
            this_file_location = d_base + this_folder + '/' +
this_filename
            this_folder_location = d_base + this_folder
            os.remove(this_file_location)
            os.rmdir(this_folder_location)
            self.SQL_mark_file_downloaded(downloadid=this_downloadid)
        ## Insert download record into DB
        self.SQL_add_download(foldername=foldername, filename=filename,
useridref=useridref)
        return foldername + '/' + filename




-- 
Green Graphics   :::   Print and Web Design   :::   510.923.0000