aboutsummaryrefslogtreecommitdiff
path: root/scilo
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunk@stsci.edu>2013-01-30 17:41:35 -0500
committerJoseph Hunkeler <jhunk@stsci.edu>2013-01-30 17:41:35 -0500
commit44be06c7b2d7e48a11288422eb1d433634eb975b (patch)
tree6959d57bf38888e3e8deb94963d095f0dd4ef68c /scilo
parent44889eca8d00d17a72ebbae684c0c9b763261b01 (diff)
downloadscilo-44be06c7b2d7e48a11288422eb1d433634eb975b.tar.gz
sqlite database creation is now segregated from population. Will not populate on instantiation.
Diffstat (limited to 'scilo')
-rw-r--r--scilo/npz.py36
1 files changed, 19 insertions, 17 deletions
diff --git a/scilo/npz.py b/scilo/npz.py
index 795badc..b09fde6 100644
--- a/scilo/npz.py
+++ b/scilo/npz.py
@@ -41,21 +41,20 @@ class mtimedb:
self.settings = kwargs
self._path_database = os.path.join(self.settings['npz'], 'npz_mtime.db')
self.db = database.s3(self._path_database)
- self.populate()
-
+
+ def create(self):
+ try:
+ self.db.cursor.execute("CREATE TABLE npz(file, mtime)")
+ except:
+ return False
+ return True
+
def populate(self):
- #if not os.path.exists(self._path_database):
- if os.path.getsize(self._path_database) == 0:
- print("Creating file tracking database...")
- try:
- self.db.cursor.execute("CREATE TABLE npz(file, mtime)")
- for f in glob.glob(os.path.join(self.settings['data'], "*.*")):
- print("File: %s\tmtime: %f" % (os.path.basename(f), os.path.getmtime(f)))
- self.insert(f, os.path.getmtime(f))
- self.db.connection.commit()
- except:
- raise
- return
+ for f in glob.glob(os.path.join(self.settings['data'], "*.*")):
+ print("File: %s\tmtime: %f" % (os.path.basename(f), os.path.getmtime(f)))
+ self.insert(f, os.path.getmtime(f))
+ self.db.connection.commit()
+ return True
def insert(self, path, mtime):
values = (path, mtime,)
@@ -112,8 +111,10 @@ class cache:
def build(self, path):
''' Generate 'path' npz file in npz directory'''
- temp = numpy.loadtxt(path)
- if numpy.savez(os.path.join(self.settings['npz'], os.path.basename(path)), temp) == False:
+ try:
+ temp = numpy.loadtxt(path)
+ numpy.savez(os.path.join(self.settings['npz'], os.path.basename(path)), temp)
+ except:
return False
return True
@@ -143,5 +144,6 @@ class cache:
print("NPZ %d of %d: '%s'" % (file_current, file_total, os.path.basename(f))),
if not self.build(f):
print("... FAIL")
- print("")
+ else:
+ print('')
file_current += 1