Recovering a .sws file from the home directory on sagenb

26 views
Skip to first unread message

Thierry

unread,
Sep 25, 2015, 9:17:47 AM9/25/15
to sage-n...@googlegroups.com
Hi,

i volonteered to help people with an account on the former sagenb.org to
get their data back. I usually send the users a copy of their home
directory. However, this is not very handy and it could be better to send
them a set of .sws files they could use directly. Is there a way to do
that, automatically or not. In heir home directory, there are some
directories withe the following structure:

./data
./data/some_file1.sage
./data/some_file2.sage
./snapshots
./snapshots/123456789.bz2
./snapshots/987654321.bz2
./cells
./worksheet.html
./worksheet_conf.pickle

I tried to just "tar cjf" each directory, but it does not work (on a
recent Sage install).

Note that sagenb.org is running sage 5.0. I can use it if needed (as well
as Sage 6.8 on my computer if the format did not change).

Ciao,
Thierry

kcrisman

unread,
Sep 26, 2015, 8:24:56 AM9/26/15
to sage-notebook

i volonteered to help people with an account on the former sagenb.org to
get their data back. I usually send the users a copy of their home
directory. However, this is not very handy and it could be better to send
them a set of .sws files they could use directly. Is there a way to do
that, automatically or not. In heir home directory, there are some
directories withe the following structure:

./data
./data/some_file1.sage
./data/some_file2.sage
./snapshots
./snapshots/123456789.bz2
./snapshots/987654321.bz2
./cells
./worksheet.html
./worksheet_conf.pickle

I tried to just "tar cjf" each directory, but it does not work (on a
recent Sage install).

It's true that there may be an upgrade process from 5.0 to 6.x.  But in general I am pretty sure that a .sws is just the directory for the thing and zipped.  I don't think you have to separately zip any of the directories.  You can also check out the exact structure by just unzipping an existing .sws file - in fact, my computer volunteers to do this for me and I have to ask NOT to do it!

or


import zipfile
zip = zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_STORED)
for worksheet in worksheets:
sws_filename = tmp_filename() + '.sws'
g.notebook.export_worksheet(worksheet.filename(), sws_filename)
entry_name = worksheet.name()
if entry_name in worksheet_names:
i = 2
while ("%s_%s" % (entry_name, i)) in worksheet_names:
i += 1
entry_name = "%s_%s" % (entry_name, i)
zip.write(sws_filename, entry_name + ".sws")
os.unlink(sws_filename)
 
def export_worksheet(self, username, id_number, filename, title):
"""
Export the worksheet with given username and id_number to the
given filename (e.g., 'worksheet.sws').
INPUT:
- ``title`` - title to use for the exported worksheet (if
None, just use current title)
"""
T = tarfile.open(filename, 'w:bz2')
worksheet = self.load_worksheet(username, id_number)
basic = copy.deepcopy(self._worksheet_to_basic(worksheet))
if title:
# change the title
basic['name'] = title
basic['name'] = encoded_str(basic['name'])
# Remove metainformation that perhaps shouldn't be distributed
for k in ['owner', 'ratings', 'worksheet_that_was_published', 'viewers', 'tags', 'published_id_number',
'collaborators', 'auto_publish']:
if basic.has_key(k):
del basic[k]
self._save(basic, self._worksheet_conf_filename(username, id_number) + '2')
tmp = self._abspath(self._worksheet_conf_filename(username, id_number) + '2')
T.add(tmp, os.path.join('sage_worksheet','worksheet_conf.pickle'))
os.unlink(tmp)
worksheet_html = self._abspath(self._worksheet_html_filename(username, id_number))
T.add(worksheet_html, os.path.join('sage_worksheet','worksheet.html'))
# The following is purely for backwards compatibility with old
# notebook servers prior to sage-4.1.2.
fd, worksheet_txt = tempfile.mkstemp()
old_heading = "%s\nsystem:%s\n"%(basic['name'], basic['system'])
with open(worksheet_txt,'w') as f:
with open(worksheet_html) as g:
f.write(old_heading + g.read())
T.add(worksheet_txt,
os.path.join('sage_worksheet','worksheet.txt'))
os.unlink(worksheet_txt)
# important, so we don't leave an open file handle!
os.close(fd)
# end backwards compat block.
# Add the contents of the DATA directory
path = self._abspath(self._worksheet_pathname(username, id_number))
data = os.path.join(path, 'data')
if os.path.exists(data):
for X in os.listdir(data):
T.add(os.path.join(data, X), os.path.join('sage_worksheet','data',X))
# Add the contents of each of the cell directories.
cells = os.path.join(path, 'cells')
if os.path.exists(cells):
for X in os.listdir(cells):
T.add(os.path.join(cells, X), os.path.join('sage_worksheet','cells',X))
# NOTE: We do not export the snapshot/undo data. People
# frequently *complain* about Sage exporting a record of their
# mistakes anyways.
T.close()
Reply all
Reply to author
Forward
0 new messages