[Tutor] Checking for file completion.
d at davea.name
Tue Feb 21 19:30:53 CET 2012
On 02/21/2012 01:10 PM, Tony Pelletier wrote:
> I'm struggling with what I think seems to be a problem. I've created a
> program that does numerous SOAP calls. In short, I create a report on a
> report server, pull that file down then parse that file that's been written
> locally for data to make more SOAP calls. My problem is I'm grabbing the
> filename then losing it somewhere along the way. The only thing I can
> think of is that it's still open/being written and causing me a problem.
> Main starts like such.
> def main():
> service = Service()
> reportId = createReport(service)
> filename = getReport(service,reportId)
> getEventAttachments(service, filename)
> Here are the results from a test run.
> Deleting "files" directory...
> "files" directory successfully created...
> Report in Processing state...
> WeeklyDeliveriesReport_2012-02-21.csv report succesfully written out...
> File still being written out...
> getReport() returns a filename and you actually see it twice up in the
> def getReport(service, reportId):
> reportIds = service.client.factory.create('ArrayOfstring')
> result = service.client.service.ReportQueryById(reportIds, 'True')
> if result.Report.ReportStatus == 'Processing':
> print 'Report in Processing state...'
> filename = result.Report.ReportFileArgs.ReportFileArg.UserFileName
> print filename
> encodedfile = result.Report.ReportFileArgs.ReportFileArg.EncodedValue
> encodedstring = encodedfile.encode('utf-8')
> str_list = 
> for line in encodedstring:
> line = line.rstrip()
> string = ''.join(str_list)
> data = base64.b64decode(string)
> outfile = open(filename, 'w')
> shutil.copyfile(filename, os.path.join('files', filename))
> print filename + ' report succesfully written out...'
> logging.info(filename + ' report succesfully written out...')
> return filename
> except suds.WebFault as e:
> print e.fault.detail
> then from main, I'm using filename to then make the call to
> getEventAttachments and passing in filename. The None you see is a result
> of my "print filename" statement.
> Now, if I uncomment that time.sleep(3), it runs flawlessly which I think
> tells me that the file is still being written to. I *think*...
> Two questions.
> 1. Is that not it and if so, am I missing something obvious?
> 2. If it is it, is there a way to check to see if the file I'm trying to
> read from is done being written to?
Please post your message again, as a text message rather than an html
one. Reading non-trivial python code that's lost all its indentation is
impossible. You've done it before, but that case was simple enough to
not matter much.
More information about the Tutor