Rename db.loadJson to db.updateJson
This commit is contained in:
parent
90c9adc8dc
commit
38d330da1a
2 changed files with 6 additions and 6 deletions
|
@ -217,9 +217,9 @@ class Db(object):
|
|||
|
||||
return changed_tables
|
||||
|
||||
# Load json file to db
|
||||
# Update json file to db
|
||||
# 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):
|
||||
return False # Not from the db dir: Skipping
|
||||
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.execute("BEGIN")
|
||||
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"):
|
||||
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 ".",
|
||||
cur.logging = True
|
||||
cur.execute("COMMIT")
|
||||
|
|
|
@ -59,7 +59,7 @@ class TestDb:
|
|||
{"test_id": 1, "titlelike": "Test%"}
|
||||
).fetchone()["num"] == 1
|
||||
|
||||
def testLoadJson(self, db):
|
||||
def testUpdateJson(self, db):
|
||||
f = StringIO.StringIO()
|
||||
f.write("""
|
||||
{
|
||||
|
@ -69,6 +69,6 @@ class TestDb:
|
|||
}
|
||||
""")
|
||||
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").fetchone()["num"] == 1
|
||||
|
|
Loading…
Reference in a new issue