diff --git a/pandora_client/__init__.py b/pandora_client/__init__.py index 23cd8ef..530a371 100755 --- a/pandora_client/__init__.py +++ b/pandora_client/__init__.py @@ -216,6 +216,7 @@ class Client(object): for i in db: c.execute(i) conn.commit() + conn.close() def load_plugins(self, base=os.path.join(utils.basedir(), 'client.d')): global parse_path, example_path, ignore_file, encode @@ -248,14 +249,18 @@ class Client(object): def get(self, key, default=None): conn, c = self._conn() c.execute(u'SELECT value FROM setting WHERE key = ?', (key, )) + value = default for row in c: - return row[0] - return default + value = row[0] + break + conn.close() + return value def set(self, key, value): conn, c = self._conn() c.execute(u'INSERT OR REPLACE INTO setting values (?, ?)', (key, str(value))) conn.commit() + conn.close() def info(self, oshash): conn, c = self._conn() @@ -264,6 +269,7 @@ class Client(object): for row in c: info = json.loads(row[0]) break + conn.close() return info def get_info(self, oshash, prefix=None): @@ -300,6 +306,7 @@ class Client(object): for row in c: path = row[0] paths.append(path) + conn.close() return paths def online(self): @@ -334,6 +341,7 @@ class Client(object): conn, c = self._conn() c.execute(u'DELETE FROM encode WHERE site = ?', (site, )) conn.commit() + conn.close() self.add_encodes(site, files) def get_encodes(self, site, status=''): @@ -341,13 +349,16 @@ class Client(object): sql = u'SELECT oshash FROM encode WHERE site = ? AND status = ?' args = [site, status] c.execute(sql, tuple(args)) - return [row[0] for row in c] + encodes = [row[0] for row in c] + conn.close() + return encodes def add_encodes(self, site, files): conn, c = self._conn() for oshash in files: c.execute(u'INSERT INTO encode VALUES (?, ?, ?, 0)', (oshash, site, '')) conn.commit() + conn.close() def update_encodes(self, add=False): # send empty list to get updated list of requested info/files/data @@ -361,6 +372,7 @@ class Client(object): c.execute(sql, (site, )) known = [row[0] for row in c] files = list(set(files) - set(known)) + conn.close() self.add_encodes(site, files) else: self.set_encodes(site, files) @@ -395,6 +407,7 @@ class Client(object): c.execute(u'INSERT OR REPLACE INTO file values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', t) conn.commit() + conn.close() return 'error' not in info def get_resolution(self, info): @@ -508,6 +521,7 @@ class Client(object): conn, c = self._conn() c.execute(u'SELECT path FROM file WHERE path LIKE ? AND deleted < 0', [u"%s%%" % path]) known_files = [r[0] for r in c.fetchall()] + conn.close() files = [] unknown = [] @@ -554,6 +568,7 @@ class Client(object): for f in deleted_files: c.execute(u'UPDATE file SET deleted=? WHERE path=?', (deleted, f)) conn.commit() + conn.close() ''' print("scanned volume %s: %s files, %s new, %s deleted, %s ignored, %s unsupported" % ( @@ -563,7 +578,6 @@ class Client(object): name, len(files), len(new_files), len(deleted_files), len(ignored))) def extract(self, args): - conn, c = self._conn() if args: if args[0] == 'offline': files = self.get_encodes(self._config['url']) @@ -650,7 +664,6 @@ class Client(object): if not self.user: print("you need to login") return - conn, c = self._conn() documents = [] if args: data = [] @@ -748,7 +761,6 @@ class Client(object): if not self.user: print("you need to login") return - conn, c = self._conn() for oshash in args: info = self.info(oshash) if info and 'error' not in info: @@ -820,7 +832,6 @@ class Client(object): if not self.user: print("you need to login") return - conn, c = self._conn() for f in args: r = self._add_document(f) if not r: @@ -853,6 +864,7 @@ class Client(object): 'ctime': row[4], 'mtime': row[5], }) + conn.close() return files def clean(self, args):