Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
241782 views
1
#################################################################################
2
#
3
# (c) Copyright 2010 William Stein
4
#
5
# This file is part of PSAGE
6
#
7
# PSAGE is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# PSAGE is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#
20
#################################################################################
21
22
23
"""
24
This module implements the ModularFormsDataBase (MFDB) class.
25
26
The MFDB class represents a connection to an MongoDB modular forms
27
database running on a local or remote server. It is instantianted
28
with a hostname and port, and just makes a MongoDB connection with
29
that port, then grabs a reference to the mfdb database there.
30
31
The newforms method returns a Python object that can be used to query
32
the database about classical GL2 newforms over QQ, and compute new
33
data about such newforms.
34
35
The backup method backs up the whole mfdb database.
36
"""
37
38
class MFDB:
39
def __init__(self, host='localhost', port=29000):
40
# Open conection to the MongoDB
41
from pymongo import Connection
42
self.connection = Connection(host, port)
43
self.db = self.connection.mfdb
44
self.port = port
45
self.host = host
46
from objectdb import ObjectDB
47
self.objectdb = ObjectDB(self.db)
48
49
def __repr__(self):
50
return "Modular Forms Database\n%s"%self.connection
51
52
def newforms(self):
53
"""Returns object that can be used for querying about GL2
54
newforms over QQ and populating the database with them."""
55
from newforms import NewformCollection
56
return NewformCollection(self.db.newforms, self)
57
58
def backup(self, outdir=None):
59
"""Dump the whole database to outdir. If outdir is None,
60
dumps to backup/year-month-day-hour-minute."""
61
import os
62
if outdir is None:
63
import time
64
outdir = os.path.join('backup',time.strftime('%Y%m%d-%H%M'))
65
cmd = 'time mongodump -h %s:%s -d mfdb -o "%s"'%(
66
self.host, self.port, outdir)
67
print cmd
68
os.system(cmd)
69
70
71
72
73