4 common_curves
= os
.path
.join(os
.getcwd(), 'src', 'common')
7 from sqlite3
import connect
9 if 'SAGE_SHARE' not in os
.environ
:
10 raise RuntimeError("SAGE_SHARE undefined, maybe run `sage -sh`?")
12 cremona_root
= os
.path
.join(os
.environ
['SAGE_SHARE'], 'cremona')
13 if not os
.path
.exists(cremona_root
):
14 os
.makedirs(cremona_root
)
16 target
= os
.path
.join(cremona_root
, 'cremona_mini.db')
18 if os
.path
.exists(target
):
23 con
.execute('CREATE TABLE t_class(rank INTEGER, class TEXT PRIMARY KEY,'
24 ' conductor INTEGER)')
25 con
.execute('CREATE TABLE t_curve(curve TEXT PRIMARY KEY, class TEXT, tors'
26 ' INTEGER, eqn TEXT UNIQUE)')
27 con
.execute('CREATE INDEX i_t_class_conductor ON t_class(conductor)')
28 con
.execute('CREATE INDEX i_t_curve_class ON t_curve(class)')
33 for line
in open(os
.path
.join(common_curves
, 'allcurves.00000-09999')):
34 N
, iso
, num
, eqn
, r
, tors
= line
.split()
38 class_data
.append((N
, cls
, r
))
39 curve_data
.append((cur
, cls
, eqn
, tors
))
41 con
.executemany('INSERT INTO t_class(conductor,class,rank) VALUES'
42 ' (?,?,?)', class_data
)
43 con
.executemany('INSERT INTO t_curve(curve,class,eqn,tors) VALUES'
44 ' (?,?,?,?)', curve_data
)
48 def install_ellcurves():
49 import shutil
, tempfile
51 if 'SAGE_SHARE' not in os
.environ
:
52 raise RuntimeError("SAGE_SHARE undefined, maybe run `sage -sh`?")
54 target
= os
.path
.join(os
.environ
['SAGE_SHARE'], 'ellcurves')
55 if os
.path
.exists(target
):
61 shutil
.move(os
.path
.join('src', 'ellcurves'), target
)
63 for line
in open(os
.path
.join(common_curves
, 'allcurves.00000-09999')):
66 rank
[r
] = open(tempfile
.mkstemp()[1], 'w')
69 for r
, f
in rank
.items():
71 endpath
= os
.path
.join(target
, 'rank' + r
)
72 if os
.path
.exists(endpath
):
73 old
= tempfile
.mkstemp()[1]
74 shutil
.move(endpath
, old
)
75 shutil
.move(f
.name
, endpath
)
76 f
= open(endpath
, 'a')
83 shutil
.move(f
.name
, endpath
)
84 os
.chmod(endpath
, 0o644)
86 if __name__
== '__main__':