Rename db.loadJson to db.updateJson

This commit is contained in:
shortcutme 2017-02-09 01:53:31 +01:00
parent 90c9adc8dc
commit 38d330da1a
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE
2 changed files with 6 additions and 6 deletions

View file

@ -217,9 +217,9 @@ class Db(object):
return changed_tables return changed_tables
# Load json file to db # Update json file to db
# Return: True if matched # Return: True if matched
def loadJson(self, file_path, file=None, cur=None): def updateJson(self, file_path, file=None, cur=None):
if not file_path.startswith(self.db_dir): if not file_path.startswith(self.db_dir):
return False # Not from the db dir: Skipping return False # Not from the db dir: Skipping
relative_path = re.sub("^%s" % self.db_dir, "", file_path) # File path realative to db file relative_path = re.sub("^%s" % self.db_dir, "", file_path) # File path realative to db file
@ -378,10 +378,10 @@ if __name__ == "__main__":
cur = dbjson.getCursor() cur = dbjson.getCursor()
cur.execute("BEGIN") cur.execute("BEGIN")
cur.logging = False cur.logging = False
dbjson.loadJson("data/users/content.json", cur=cur) dbjson.updateJson("data/users/content.json", cur=cur)
for user_dir in os.listdir("data/users"): for user_dir in os.listdir("data/users"):
if os.path.isdir("data/users/%s" % user_dir): if os.path.isdir("data/users/%s" % user_dir):
dbjson.loadJson("data/users/%s/data.json" % user_dir, cur=cur) dbjson.updateJson("data/users/%s/data.json" % user_dir, cur=cur)
# print ".", # print ".",
cur.logging = True cur.logging = True
cur.execute("COMMIT") cur.execute("COMMIT")

View file

@ -59,7 +59,7 @@ class TestDb:
{"test_id": 1, "titlelike": "Test%"} {"test_id": 1, "titlelike": "Test%"}
).fetchone()["num"] == 1 ).fetchone()["num"] == 1
def testLoadJson(self, db): def testUpdateJson(self, db):
f = StringIO.StringIO() f = StringIO.StringIO()
f.write(""" f.write("""
{ {
@ -69,6 +69,6 @@ class TestDb:
} }
""") """)
f.seek(0) f.seek(0)
assert db.loadJson(db.db_dir + "data.json", f) == True assert db.updateJson(db.db_dir + "data.json", f) == True
assert db.execute("SELECT COUNT(*) AS num FROM test_importfilter").fetchone()["num"] == 1 assert db.execute("SELECT COUNT(*) AS num FROM test_importfilter").fetchone()["num"] == 1
assert db.execute("SELECT COUNT(*) AS num FROM test").fetchone()["num"] == 1 assert db.execute("SELECT COUNT(*) AS num FROM test").fetchone()["num"] == 1