#################################################################################1#2# (c) Copyright 2010 William Stein3#4# This file is part of PSAGE5#6# PSAGE is free software: you can redistribute it and/or modify7# it under the terms of the GNU General Public License as published by8# the Free Software Foundation, either version 3 of the License, or9# (at your option) any later version.10#11# PSAGE is distributed in the hope that it will be useful,12# but WITHOUT ANY WARRANTY; without even the implied warranty of13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14# GNU General Public License for more details.15#16# You should have received a copy of the GNU General Public License17# along with this program. If not, see <http://www.gnu.org/licenses/>.18#19#################################################################################202122"""23This module defines a light wrapper around a MongoDB collection in the24MFDB database.25"""2627class Collection:28def __init__(self, collection, db):29self.collection = collection30self.db = db3132def backup(self, outdir=None):33"""Dump this collection to outdir. If outdir is None,34dumps to backup/year-month-day-hour-minute."""35import os36if outdir is None:37import time38outdir = os.path.join('backup',time.strftime('%Y%m%d-%H%M'))39cmd = 'time mongodump -c "%s" -h %s:%s -d mfdb -o "%s"'%(40self.collection.name, self.db.host, self.db.port, outdir)41print cmd42os.system(cmd)4344def find(self, *args, **kwds):45"""Perform a query on the collection. See the help for self.collection.find."""46return self.collection.find(*args, **kwds)47484950