#!/usr/bin/env python
import os
import cgi
cur = os.path.abspath(os.curdir)
archive = os.path.abspath(os.path.expanduser("~/files-old/spkg/archive"))
style = """
"""
def archive_directories():
for F in os.listdir('.'):
if os.path.isdir(F):
cmd = "mv -v %s %s" % (F, archive)
print cmd
os.system(cmd)
def package_name(F):
i = F.find("-")
if i == -1:
return F
return F[:i]
def archive_all_but_newest(F, D):
if not os.path.exists(F):
return
if not os.path.exists(archive):
os.makedirs(archive)
name = package_name(F)
versions = [(os.path.getmtime(m), m) for m in D if os.path.exists(m) and package_name(m) == name]
versions.sort()
for G in versions[:-1]:
print "Archiving %s..."%G[1]
cmd = "mv %s.* %s"%(G[1][:-5], archive)
print cmd
os.system(cmd)
def extract_spkg_txt(F):
print("Extracting SPKG.txt from %s"%F)
cmd = 'tar xvf %s.spkg %s/SPKG.txt; mv -v %s/SPKG.txt %s.txt; rm -rf %s; chmod a+r %s.txt'%(F,F,F,F,F,F)
#print(cmd)
os.system(cmd)
if not os.path.exists('%s.txt'%F):
print("** Unable to create %s.txt. Making placeholder. **"%F)
open('%s.txt'%F,'w').write('= %s ='%F)
def index(dir):
os.chdir(dir)
#if dir != archive:
# archive_directories()
s = '
Sage %s Packages%s\n\n\n'%(dir.capitalize(), style, dir.capitalize())
if dir == 'experimental':
s += "These are EXPERIMENTAL! They probably won't work at all for you! Use at your own risk! Many of these have *never* been successfully built on any platform! (But still, if you can figure out how to build them, I'd like to know about it.) These also may not be available under a GPL-compatible license.
"
s += "\n"
if dir != 'standard':
s += "To install one of these packages, type e.g., the following at the UNIX shell prompt:"
s += " sage -i db-jones-2005-11-02 "
s += "Note that the package name contains the version number, and it "
s += "will be downloaded automatically if necessary."
else:
s += "To upgrade to the latest versions of all these packages, at the UNIX shell prompt type:"
s += " sage -upgrade "
s += "\n |
\n"
# google analytics event tracking, init code
s += """\
"""
s += '\n'
D = [F for F in os.listdir('.') if F.endswith(".spkg")]
D.sort(key = lambda _:_.lower())
for F in D:
if dir != archive:
archive_all_but_newest(F, D)
if not os.path.exists(F):
print "F = '%s' mysteriously vanished!"%F
continue
txt = "%s.txt"%F[:-5]
if not os.path.exists(txt):
extract_spkg_txt(F[:-5])
if os.path.exists(txt):
print txt
O = open(txt).read()
i = O.find('==\n')
if i != -1:
O = O[i+3:].lstrip()
i = O.find('=')
if i != -1:
desc = O[:i]
print desc
details = O[i+1:]
else:
desc = O
details = ""
else:
desc = ''
desc = cgi.escape(desc) # escape <...> and similar characters
s += '| %(n)s.spkg | SPKG.txt: %(d)s |
\n'%{"fn":F,"n":F[:-5],"d":desc,"dir":dir}
s += '\n
\n'
if os.path.exists('deps'):
s += '
Dependency File\n'
s += '\n\n'
open('index.html','w').write(s)
# FIXED re-search for all .spkg files in order to avoid listing the moved ones
D = [F for F in os.listdir('.') if F.endswith(".spkg")]
D.sort(key = lambda _:_.lower())
open('list','w').write('\n'.join([F[:-5] for F in D]))
os.chdir(cur)
index('standard')
index('optional')
index('experimental')
index('huge')
index(archive)
## new: extracting the SPKG information for the git upstream files
#index_upstream()
# update mirror
#print
#print "now indexing+updating the master mirror"
#os.system('/www-data/sagemath-org/mirror')