diff did not help since excel files are considered binary format.
the copies are bigger than the original.xls. I also tried to copy the
copy and the 2nd copy is again bigger in size than the 1st copy.
interesting is that shutil.copyfileobj() and .write(read()) generate
identical files, both corrupt for excel and bigger than the original.

Massimo, I sent you an email with a web2py mini app and small .xls
sample files.
can you reproduce the problem?

thanks,
hans

my test environment:
web2py 1.61.4
WinXP Pro SP3
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)]

On May 13, 10:37 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> from what I understood something was being removed, not added. Am I
> wrong?
>
> On May 13, 3:24 pm, Kacper Krupa <pageno...@gmail.com> wrote:
>
> > You should try with smaller files and create diff (to check what is
> > added). It seams to be something between uploading <-> saving.
>
> > On May 13, 9:57 pm, Hans <johann.scheibelho...@easytouch-edv.com>
> > wrote:
>
> > > web2py 1.61.4
> > > WinXP Pro SP3
> > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
> > > (Intel)]
>
> > > If there is anything I can do to mail it down on my side then let me
> > > know!
>
> > > Thanks,
> > > Hans
>
> > > On May 13, 9:40 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > The problem is not so much to solve it but to reproduce it.
>
> > > > what version of web2py are you running? which os? which python
> > > > version?
>
> > > > Massimo
>
> > > > On May 13, 2:32 pm, Hans <johann.scheibelho...@easytouch-edv.com>
> > > > wrote:
>
> > > > > bumping this one since I still could not fix that. Has anyone managed
> > > > > to solve this yet?
>
> > > > > On May 9, 1:09 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > > > My bad. This was correct:
> > > > > >  shutil.copyfileobj(request.vars.filename.file,open(path,'w'))
>
> > > > > > I am surprised you still get a corruptedfile. let me run some tests.
>
> > > > > > Massimo
>
> > > > > > On May 8, 5:05 pm, Hans <johann.scheibelho...@easytouch-edv.com>
> > > > > > wrote:
>
> > > > > > > > shutil.copyfileobj(request.vars.filename,open(path,'w'))
>
> > > > > > > raises exception: (<type 'exceptions.AttributeError'>, 
> > > > > > > AttributeError
> > > > > > > ('read',), <traceback object at 0x03FC0CB0>)
>
> > > > > > > tried also
> > > > > > >    shutil.copyfileobj(request.vars.filename.file,open(path,'w'))
> > > > > > > which creates a copy, but again a corrupt copy.
>
> > > > > > > This tests now were done just on windows xp.
>
> > > > > > > Any other ideas how to solve this?
>
> > > > > > > Hans
>
> > > > > > > On May 8, 10:29 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > > > > > It may be an issue with buffer size. Try
>
> > > > > > > > import shutil
> > > > > > > > shutil.copyfileobj(request.vars.filename,open(path,'w'))
>
> > > > > > > > Massimo
>
> > > > > > > > On May 8, 2:56 pm, Hans <johann.scheibelho...@easytouch-edv.com>
> > > > > > > > wrote:
>
> > > > > > > > > There is a problem with the following code line
>
> > > > > > > > > >             
> > > > > > > > > > open(path,'w').write(request.vars.filename.file.read())
>
> > > > > > > > > It creates thefile'a_dummy_file_name.xls' but it is not the 
> > > > > > > > > same
> > > > > > > > > size as the originalfile, for example:
> > > > > > > > > 6790KB original.xls
> > > > > > > > > 6862KB a_dummy_file_name.xls
>
> > > > > > > > > If I try to open the dummyfilewith excel or open office it 
> > > > > > > > > says the
> > > > > > > > >fileis corrupt.
> > > > > > > > > I've tried to copy thefilemanually right after this code line 
> > > > > > > > > and
> > > > > > > > > continued execution from there onward...rest works nicely.
>
> > > > > > > > > I tried on windows and on ubuntu, seems the same problem.
>
> > > > > > > > > Any idea how to solve that issue with the 
> > > > > > > > > corruptfile(=getting a
> > > > > > > > > exact copy) ?
>
> > > > > > > > > thanks,
> > > > > > > > > hans
>
> > > > > > > > > On May 7, 10:56 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > > > > > > > This should do
>
> > > > > > > > > >  def excel_read():
> > > > > > > > > >     result={}
> > > > > > > > > >     if request.vars.filename != None:
> > > > > > > > > >         try:
> > > > > > > > > >             import xlrd
> > > > > > > > > >             path=os.path.join
> > > > > > > > > > (request.folder,'private','a_dummy_file_name.xls')
> > > > > > > > > >             
> > > > > > > > > > open(path,'w').write(request.vars.filename.file.read())
> > > > > > > > > >             book = xlrd.open_workbook(path)
> > > > > > > > > >             result['The number of worksheets 
> > > > > > > > > > is']=book.nsheets
> > > > > > > > > >             result["Worksheet name(s)"]= book.sheet_names()
> > > > > > > > > >             sh = book.sheet_by_index(0)
> > > > > > > > > >             result['sh.name']=sh.name
> > > > > > > > > >             result['sh.nrows']=sh.nrows
> > > > > > > > > >             result['sh.ncols']=sh.ncols
> > > > > > > > > >             result['Cell D30 is']=sh.cell_value(rowx=29, 
> > > > > > > > > > colx=3)
> > > > > > > > > >             for rx in range(sh.nrows):
> > > > > > > > > >                 result['row ' + str(rx)]=sh.row(rx)
> > > > > > > > > >         except:
> > > > > > > > > >             response.flash = T('excel_read exception')
> > > > > > > > > >     return dict(result=result)
>
> > > > > > > > > > for you request.vars.filename is a cgi.FieldStorage object. 
> > > > > > > > > > It is not
> > > > > > > > > > a namedfile.
> > > > > > > > > > It containes
> > > > > > > > > > - request.vars.filename.file(a buffered input stream)
> > > > > > > > > > - request.vars.filename.filename (the original filename)
> > > > > > > > > > For you to access it you should read the stream and save it 
> > > > > > > > > > with a
> > > > > > > > > > name. Do not use the original filename to avoid directory 
> > > > > > > > > > traversal
> > > > > > > > > > attacks.
>
> > > > > > > > > > Massimo
>
> > > > > > > > > > On May 7, 2:58 pm, Hans 
> > > > > > > > > > <johann.scheibelho...@easytouch-edv.com>
> > > > > > > > > > wrote:
>
> > > > > > > > > > > I'm trying to import some content directly from an 
> > > > > > > > > > > excelfilewhich
> > > > > > > > > > > the user selects from itslocalfiles. I've taken and 
> > > > > > > > > > > modified code
> > > > > > > > > > > from the admin controller for retrieving the 
> > > > > > > > > > > path/filename thru a nice
> > > > > > > > > > >fileselectionwindow.
>
> > > > > > > > > > > The problem: I get only the filename of a locked 
> > > > > > > > > > > temporaryfile, not
> > > > > > > > > > > the original filename. If I close the temporaryfile, to 
> > > > > > > > > > > remove the
> > > > > > > > > > > lock, thefileis automatically deleted...
>
> > > > > > > > > > > I would not mind to work with a temporary copy of the 
> > > > > > > > > > > originalfile,
> > > > > > > > > > > but retrieving the original path/filename thru a 
> > > > > > > > > > > similarfile
> > > > > > > > > > >selectionwindow would be prefered. How can this be 
> > > > > > > > > > >achieved?
>
> > > > > > > > > > > Hans
> > > > > > > > > > > P.S. I'm using the xlrd module 
> > > > > > > > > > > fromhttp://pypi.python.org/pypi/xlrd
>
> > > > > > > > > > > ### viewer ###
> > > > > > > > > > > {{extend 'layout.html'}}
> > > > > > > > > > > <h1>excel_read.html template</h1>
>
> > > > > > > > > > > <div class='frame'>
> > > > > > > > > > > <h2>{{=t2.T('SelectFile')}}</h2>
> > > > > > > > > > > {{=FORM('File: 
> > > > > > > > > > > ',INPUT(_type='file',_name='filename'),INPUT
> > > > > > > > > > > (_type='submit', _value='submit'))}}
> > > > > > > > > > > </div>
>
> > > > > > > > > > > <div class='frame'>
> > > > > > > > > > > {{=BEAUTIFY(response._vars)}}
> > > > > > > > > > > </div>
>
> > > > > > > > > > > ### controller ###
> > > > > > > > > > > def excel_read():
> > > > > > > > > > >     result={}
> > > > > > > > > > >     if request.vars.filename != None:
> > > > > > > > > > >         try:
> > > > > > > > > > >             import xlrd
>
> > > > > > > > > > > # >>> can't locate the originally selected path/filename 
> > > > > > > > > > > in
> > > > > > > > > > > request.vars.filename <<<
> > > > > > > > > > >             book = 
> > > > > > > > > > > xlrd.open_workbook(request.vars.filename.file.name)
> > > > > > > > > > > # >>> with a valid path/filename it works <<<
> > > > > > > > > > >             book = xlrd.open_workbook('F:/Documents and 
> > > > > > > > > > > Settings/Hans/
> > > > > > > > > > > Desktop/test.xls')
>
> > > > > > > > > > >             result['The number of worksheets 
> > > > > > > > > > > is']=book.nsheets
> > > > > > > > > > >             result["Worksheet name(s)"]= 
> > > > > > > > > > > book.sheet_names()
> > > > > > > > > > >             sh = book.sheet_by_index(0)
> > > > > > > > > > >             result['sh.name']=sh.name
> > > > > > > > > > >             result['sh.nrows']=sh.nrows
> > > > > > > > > > >             result['sh.ncols']=sh.ncols
> > > > > > > > > > >             result['Cell D30 is']=sh.cell_value(rowx=29, 
> > > > > > > > > > > colx=3)
> > > > > > > > > > >             for rx in range(sh.nrows):
> > > > > > > > > > >                 result['row ' + str(rx)]=sh.row(rx)
> > > > > > > > > > >         except:
> > > > > > > > > > >             response.flash = T('excel_read exception')
> > > > > > > > > > >     return dict(result=result)
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to