If tree imports successfully, add supporting file.

This copies the input text (whether an uploaded file or pasted into a
form field) to a new file in the supporting-files area for this study,
so that it can be reviewed, downloaded, and deleted from within the
curation app. Fixes #418.

NOTE that this is in addition to the saving of input data to peyotl's
scratch folders. The latter is for diagnostic purposes.
yes. that one should be changed too. I changed the first one while testing
your previous PR.

I agree that we should be using os for most of those operations. I mainly
use shutil for copying files along with their permissions bits.

Mark

On Mon, Oct 6, 2014 at 3:51 PM, Jim Allman <notifications@github.com> wrote:

> In curator/controllers/default.py:
>
> > +            # mimic the expected upload file field by coercing pasted text to a file-like object
> > +            import StringIO
> > +            file_data = StringIO.StringIO()
> > +            file_data.write( request.vars.content )
> > +        file_data.seek(0)
> > +        id = db.supporting_files.insert(doc = db.supporting_files.doc.store(file_data, str(read_filename)))
> > +        # N.B. read_filename must be passed as a str! Unicode filename will
> > +        # throw an error during insert() below, due to a bug in web2py (dal > _attempt_upload)
> > +
> > +        # Compute size of the file and update the record
> > +        record = db.supporting_files[id]
> > +        path_list = []
> > +        path_list.append(request.folder)
> > +        path_list.append('uploads')
> > +        path_list.append(record['doc'])
> > +        size = shutil.os.path.getsize(shutil.os.path.join(*path_list))
>
> On Oct 6, 2014, at 4:09 AM, Mark T. Holder <notifications@github.com>
> wrote: This should probably be: size =
> os.path.getsize(os.path.join(*path_list)) to be on the safe side. What is
> here works as long as the standard lib shutil includes the line "import
> os". That will probably continue to be true, but I don't think there is a
> commitment to that in the shutil docs
> Ah, good to know. I assume I should make the same change in the
> supporting-files controller as well, yes?
> https://github.com/OpenTreeOfLife/opentree/blob/70244c3f8a37da91a3249accf00ea089a60806be/curator/controllers/supporting_files.py#L20-L27
> Now I don’t recall why shutils was here in the first place, as it seems
> we're using the `os` module normally. =jimA==
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/OpenTreeOfLife/opentree/pull/475/files#r18457179>.
>



-- 
Mark Holder

mtholder@gmail.com
mtholder@ku.edu
http://phylo.bio.ku.edu/mark-holder

==============================================
Department of Ecology and Evolutionary Biology
University of Kansas
6031 Haworth Hall
1200 Sunnyside Avenue
Lawrence, Kansas 66045

lab phone:  785.864.5789
fax (shared): 785.864.5860
==============================================