''' scilo - A scientific workflow and efficiency library Copyright (C) 2012 Joseph Hunkeler This file is part of scilo. scilo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. scilo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with scilo. If not, see . ''' import numpy import os import glob import npy class scilo: def __init__(self, path): self.mtimedb = None self.path = os.path.abspath(path) self.name = os.path.basename(self.path) self.settings = npy.settings(self.path) print("Loading dataset: %s" % (self.name)) if not os.path.exists(path): os.mkdir(os.path.abspath(self.settings.path)) for key in self.settings.directories.iterkeys(): d = os.path.join(self.settings.path, key) self.settings.directories[key] = d print("\tCreating directory: '%s'" % (self.settings.directories[key])) os.mkdir(self.settings.directories[key]) else: for key in self.settings.directories.iterkeys(): d = os.path.join(self.path, key) self.settings.directories[key] = d self.cache = npy.cache(**self.settings.directories) def __getitem__(self, key): return self.settings.directories[key] def aggregate(self, globular, move=True): sources = glob.glob(globular) if not sources: return False for src in sources: dest = os.path.join(self.settings.directories['data'], os.path.basename(src)) src = os.path.abspath(src) if move: if os.rename(src, dest) == False: continue else: # It is text and the metadata barely matters. import shutil shutil.copy2(src, dest) self.mtimedb = npy.mtimedb(**self.settings.directories) self.cache.populate() return True