Delete file's database entries if file paramter is False
This commit is contained in:
parent
55cc496c2e
commit
0ddc1e47ba
1 changed files with 16 additions and 3 deletions
19
src/Db/Db.py
19
src/Db/Db.py
|
@ -200,9 +200,17 @@ class Db(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Load the json file
|
# Load the json file
|
||||||
if not file:
|
try:
|
||||||
file = open(file_path)
|
if file is None: # Open file is not file object passed
|
||||||
data = json.load(file)
|
file = open(file_path)
|
||||||
|
|
||||||
|
if file is False: # File deleted
|
||||||
|
data = {}
|
||||||
|
else:
|
||||||
|
data = json.load(file)
|
||||||
|
except Exception, err:
|
||||||
|
self.log.debug("Json file %s load error: %s" % (file_path, err))
|
||||||
|
data = {}
|
||||||
|
|
||||||
# No cursor specificed
|
# No cursor specificed
|
||||||
if not cur:
|
if not cur:
|
||||||
|
@ -301,6 +309,11 @@ class Db(object):
|
||||||
row["json_id"] = json_row["json_id"]
|
row["json_id"] = json_row["json_id"]
|
||||||
cur.execute("INSERT OR REPLACE INTO %s ?" % table_name, row)
|
cur.execute("INSERT OR REPLACE INTO %s ?" % table_name, row)
|
||||||
|
|
||||||
|
# Cleanup json row
|
||||||
|
if not data:
|
||||||
|
self.log.debug("Cleanup json row for %s" % file_path)
|
||||||
|
cur.execute("DELETE FROM json WHERE json_id = %s" % json_row["json_id"])
|
||||||
|
|
||||||
if commit_after_done:
|
if commit_after_done:
|
||||||
cur.execute("COMMIT")
|
cur.execute("COMMIT")
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in a new issue