diff options
-rw-r--r-- | scilo/npy.py | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/scilo/npy.py b/scilo/npy.py index 74f9367..80ea765 100644 --- a/scilo/npy.py +++ b/scilo/npy.py @@ -22,7 +22,7 @@ import numpy import glob import os -class settings: +class settings(object): def __init__(self, path_start): # Define generic directory structure self.path = path_start @@ -37,9 +37,9 @@ class settings: class mtimedb: - def __init__(self, **subdirs): - self.subdirs = subdirs - self._path_database = os.path.join(self.subdirs['npy'], 'npy_mtime.db') + def __init__(self, **kwargs): + self.settings = kwargs + self._path_database = os.path.join(self.settings['npy'], 'npy_mtime.db') self.db = database.s3(self._path_database) self.populate() @@ -49,7 +49,7 @@ class mtimedb: print("Creating modification tracking database...") try: self.db.cursor.execute("CREATE TABLE npy(file, mtime)") - for f in glob.glob(os.path.join(self.subdirs['data'], "*.*")): + for f in glob.glob(os.path.join(self.settings['data'], "*.*")): print("\tFile: %s\tmtime: %f" % (os.path.basename(f), os.path.getmtime(f))) self.insert(f, os.path.getmtime(f)) self.db.connection.commit() @@ -79,7 +79,7 @@ class mtimedb: mtime_stored = [] mtime_current = [] self.db.cursor.execute("SELECT file, mtime FROM npy") - files = glob.glob(os.path.join(self.subdirs['data'], '*.*')) + files = glob.glob(os.path.join(self.settings['data'], '*.*')) for f in files: mtime_current.append([f, os.path.getmtime(f)]) @@ -104,13 +104,15 @@ class mtimedb: return class cache: - def __init__(self): + def __init__(self, **kwargs): + self.settings = kwargs + self.files = [] pass def build(self, path): ''' Generate 'path' npy file in npy directory''' temp = numpy.loadtxt(path) - if numpy.save(os.path.join(self.subdirs['npy'], os.path.basename(path)), temp) == False: + if numpy.save(os.path.join(self.settings['npy'], os.path.basename(path)), temp) == False: return False return True @@ -123,23 +125,23 @@ class cache: def drop_all(self): ''' Remove all npy files ''' - files = glob.glob(os.path.join(self.subdirs['npy'], '*.npy')) + files = glob.glob(os.path.join(self.settings['npy'], '*.npy')) if files: [os.unlink(f) for f in files] def populate(self): - files = glob.glob(os.path.join(self.subdirs['data'], '*.*')) + files = glob.glob(os.path.join(self.settings['data'], '*.*')) file_total = len(files) file_current = 1 - + for f in files: - if os.path.exists(os.path.join(self.subdirs['npy'], os.path.basename(f) + '.npy')): + exists = os.path.exists(os.path.join(self.settings['npy'], os.path.basename(f) + '.npy')) + if exists: file_total -= 1 continue - print("\tBuilding cache %d of %d: '%s'..." % (file_current, file_total, os.path.basename(f))), + print("Building cache %d of %d: '%s'..." % (file_current, file_total, os.path.basename(f))), if not self.build(f): print("failure") print("success") file_current += 1 - self.populate() #self.check() |