From 44be06c7b2d7e48a11288422eb1d433634eb975b Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 30 Jan 2013 17:41:35 -0500 Subject: sqlite database creation is now segregated from population. Will not populate on instantiation. --- scilo/npz.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'scilo/npz.py') 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 -- cgit