aboutsummaryrefslogtreecommitdiff
path: root/scilo/scilo.py
blob: 8e594bdd6f6c45a132fe8cb67c5d940a900a1de1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'''
scilo - A scientific workflow and efficiency library 
Copyright (C) 2012  Joseph Hunkeler <jhunkeler@gmail.com>

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 <http://www.gnu.org/licenses/>.
'''
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