Ticket #10637: add_sws2rst.patch
File add_sws2rst.patch, 4.4 KB (added by , 10 years ago) |
---|
-
sage-sage
# HG changeset patch # User Pablo Angulo <pablo.angulo@uam.es> # Date 1295454069 -3600 # Node ID c537b10238fb2cb459fa94cbaaafe43b064782b4 # Parent afec3d7d46feb80352aef4ff7f5d4211f015b66c [mq]: add_sws2rst.patch diff -r afec3d7d46fe -r c537b10238fb sage-sage
a b 144 144 echo " -fixdoctests <file.py> -- create <file.py>.out that would pass the doctests" 145 145 echo " and output a patch" 146 146 echo " -startuptime -- display how long each component of Sage takes to" 147 echo " -sws2rst <sws document> Generates a rst file from the given document" 147 148 echo " start up" 148 149 echo " -t [options] <files|dir>" 149 150 echo " -- test examples in .py, .pyx, .sage or .tex files" … … 700 701 echo -n " Do you want to proceed? [y/n] " 701 702 read CHOICE 702 703 while [ "$CHOICE" != "y" -a "$CHOICE" != "n" ]; do 703 704 704 echo -n " Choose one of y, n: " 705 read CHOICE 705 706 done 706 707 if [ $CHOICE = 'n' ]; then 707 708 exit 0 708 709 fi 709 710 build_sage -b "$@" 710 711 exit $? … … 804 805 PKG_NAME=`echo "$PKG" | sed -e "s/\.spkg$//"` 805 806 PKG_NAME=`basename "$PKG_NAME"` 806 807 case $PKG in 807 808 809 810 811 812 808 /*) 809 sage-spkg $OPT "$PKG" 2>&1 | (trap "" SIGINT; tee -a ../install.log "$SAGE_LOGS/$PKG_NAME".log) 810 ;; 811 *) 812 sage-spkg $OPT "$CUR/$PKG" 2>&1 | (trap "" SIGINT; tee -a ../install.log "$SAGE_LOGS/$PKG_NAME".log) 813 ;; 813 814 esac 814 815 815 816 if [ $? -ne 0 ]; then … … 1008 1009 python "$SAGE_LOCAL"/bin/sage-startuptime.py 1009 1010 exit $? 1010 1011 fi 1012 1013 if [ "$1" = '-sws2rst' -o "$1" = '--sws2rst' ]; then 1014 cd "$CUR" 1015 echo hola, "$CUR" 1016 shift 1017 sage-sws2rst "$@" 1018 exit $? 1019 fi 1020 1011 1021 if [ "$1" = '-gthread' -o "$1" = '-qthread' -o "$1" = '-q4thread' -o "$1" = '-wthread' -o "$1" = '-pylab' ]; then 1012 1022 sage "$1" 1013 1023 exit $? -
new file sage-sws2rst
diff -r afec3d7d46fe -r c537b10238fb sage-sws2rst
- + 1 #!/usr/bin/python 2 # -*- coding: utf-8 -*- 3 4 import sys 5 import tarfile 6 import os 7 import shutil 8 import codecs 9 from sagenb.misc.worksheet2rst import parse 10 11 if __name__=='__main__': 12 if len(sys.argv)<=1: 13 print 'First argument should be a sws file' 14 sys.exit() 15 16 # retcode = call(['tar','jxf', sys.argv[1], '-o',path2]) 17 18 fichero_sws = tarfile.open(sys.argv[1], mode='r:bz2') 19 #TODO: python complains about using tempnam, but I don't 20 #know hot to fix it or see any danger 21 tempname = os.tempnam('.') 22 fichero_sws.extractall(tempname) 23 nombre_base = os.path.splitext(sys.argv[1])[0] 24 25 #Imagenes 26 images_dir = nombre_base + '_media' 27 if not os.path.exists(images_dir): 28 os.mkdir(images_dir) 29 30 #"data" dir 31 data_path = os.path.join(tempname,'sage_worksheet','data') 32 if os.path.exists(data_path): 33 for image in os.listdir(data_path): 34 try: 35 shutil.move(os.path.join(data_path, image), images_dir) 36 except shutil.Error: 37 pass 38 39 #cells 40 cells_path = os.path.join(tempname,'sage_worksheet','cells') 41 for cell in os.listdir(cells_path): 42 cell_path = os.path.join(cells_path, cell) 43 for image in os.listdir(cell_path): 44 shutil.copy2(os.path.join(cell_path, image), images_dir) 45 shutil.move(os.path.join(images_dir, image), 46 os.path.join(images_dir, 'cell_%s_%s'%(cell,image))) 47 48 #Fichero rst 49 fichero = codecs.open(os.path.join('.',tempname,'sage_worksheet','worksheet.html'), 50 mode='r', 51 encoding='utf-8') 52 html_text = fichero.read() 53 fichero.close() 54 rst_text = parse(html_text, images_dir = images_dir) 55 fichero_rst = nombre_base + '.rst' 56 fichero_out = codecs.open(fichero_rst, mode='w', 57 encoding='utf-8') 58 fichero_out.write(rst_text) 59 fichero_out.close() 60 61 shutil.rmtree(tempname)