Ticket #637: sage-637-part2.patch

File sage-637-part2.patch, 3.7 KB (added by was, 13 years ago)
  • sage/server/notebook/notebook.py

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1210813811 25200
    # Node ID feb0c046a6282033252a99f50fa13eac5b8ca034
    # Parent  8f33be1ff9deca798dd476138d2c8aa80d98902f
    trac #637 -- followup to referee's report; fix the issue he points out and also improve some other error robustness related to emptying the trash.
    
    diff -r 8f33be1ff9de -r feb0c046a628 sage/server/notebook/notebook.py
    a b class Notebook(SageObject): 
    382382                # 2. copy them over
    383383                # 3. update worksheet text
    384384                if os.path.exists(X.data_directory()):
    385                     shutil.rmtree(X.data_directory())
     385                    shutil.rmtree(X.data_directory(), ignore_errors=True)
    386386                if os.path.exists(X.cells_directory()):
    387                     shutil.rmtree(X.cells_directory())
     387                    shutil.rmtree(X.cells_directory(), ignore_errors=True)
    388388                self._initialize_worksheet(worksheet, X)
    389389                X.set_worksheet_that_was_published(worksheet)
    390390                X.move_to_archive(username)
    class Notebook(SageObject): 
    457457            raise KeyError, "Attempt to delete missing worksheet '%s'"%filename
    458458        W = self.__worksheets[filename]
    459459        W.quit()
    460         shutil.rmtree(W.directory())
     460        shutil.rmtree(W.directory(), ignore_errors=True)
    461461        self.deleted_worksheets()[filename] = W
    462462        del self.__worksheets[filename]
    463463
    class Notebook(SageObject): 
    795795
    796796        # Figure out the file extension
    797797        ext = os.path.splitext(filename)[1]
    798         if ext == '.txt':
     798        if ext.lower() == '.txt':
    799799            # A plain text file with {{{'s that defines a worksheet (not graphics).
    800800            return self._import_worksheet_txt(filename, owner)
    801         elif ext == '.sws':
     801        elif ext.lower() == '.sws':
    802802            # An sws file (really a tar.bz2) which defines a worksheet with graphics,
    803803            # revisions, etc.
    804804            return self._import_worksheet_sws(filename, owner)
    class Notebook(SageObject): 
    923923
    924924        worksheet.edit_save(worksheet_txt)
    925925       
    926         shutil.rmtree(tmp)
     926        shutil.rmtree(tmp, ignore_errors=True)
    927927
    928928        return worksheet
    929929
  • sage/server/notebook/twist.py

    diff -r 8f33be1ff9de -r feb0c046a628 sage/server/notebook/twist.py
    a b class UploadWorksheet(resource.PostableR 
    323323            f.close()
    324324
    325325        try:
    326             W = notebook.import_worksheet(filename, self.username)
    327             os.unlink(filename)
    328             # if a temp directory was created, we delete it now.
    329             if dir:
    330                 shutil.rmtree(dir)
     326            try:
     327                W = notebook.import_worksheet(filename, self.username)
     328            except IOError, msg:
     329                print msg
     330                raise ValueError, "Unfortunately, there was an error uploading the worksheet.  It could be an old unsupported format or worse.  If you desparately need its contents contact the Google group sage-support and post a link to your worksheet.  Alternatively, an sws file is just a bzip2'd tarball; take a look inside!"
     331            finally:
     332                # Clean up the temporarily uploaded filename.
     333                os.unlink(filename)
     334                # if a temp directory was created, we delete it now.
     335                if dir:
     336                    shutil.rmtree(dir)
    331337
    332338        except ValueError, msg:
    333339            s = "Error uploading worksheet '%s'."%msg