-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapply_data.py
More file actions
102 lines (91 loc) · 3.59 KB
/
apply_data.py
File metadata and controls
102 lines (91 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from pymongo import Connection
from bson.objectid import ObjectId
from bson.json_util import dumps
from ivs_base import ivs
def apply_data(db_name,data,root_path):
commits_list=data["commits"]
patches_list=data["patches"]
branches_list=data["branches"]
files_list=data["files"]
param_entry=data["params"]
mongo_conn=Connection()
db=mongo_conn[db_name]
for commit in commits_list:
db.commits.update({"uid":commit["uid"]},
{
"$set":{
"uid":commit["uid"],
"patch_ids": commit["patch_ids"],
"ts": commit["ts"],
"msg": commit["msg"],
"added": commit["added"],
"deleted": commit["deleted"],
"parent_id": commit["parent_id"],
"branch": commit["branch"],
"num": commit["num"],
"level": commit["level"]
},
"$addToSet": { "child_ids" :{"$each": commit["child_ids"]}},
},
upsert=True
)
for patch in patches_list:
db.patches.insert(patch)
for branch in branches_list:
db.branches.update({"name":branch["name"]},
{
"name": branch["name"],
"commit_ids": branch["commit_ids"],
"head": branch["head"],
"tail": branch["tail"],
"parent_branches": branch["parent_branches"],
},
upsert=True
)
for entity in files_list:
db.files.update({"path":entity["path"]},
{
"$set":{
"name": entity["name"],
"path": entity["path"],
"staged": entity["staged"],
"staged_ts": entity["staged_ts"],
"is_present": entity["is_present"],
"to_remove": entity["to_remove"],
"to_add": entity["to_add"],
"added_cids": entity["added_cids"],
},
"$addToSet":{
"patch_ids": {"$each":entity["patch_ids"]},
"deleted_cids":{"$each": entity["deleted_cids"]}
}
},
upsert=True
)
if len(commits_list)>0:
print("Generating code")
repo=ivs()
repo.set_path(root_path)
repo.set_dbname(db_name)
repo.load_params()
if repo.cur_branch == None:
repo.cur_branch="master"
if param_entry!=None:
db.params.update({"path":root_path},
{
"path": root_path,
"dbname": db_name,
"first_cid": param_entry["first_cid"],
"cur_com_num": param_entry["cur_com_num"],
"last_cid": db.branches.find_one({"name":repo.cur_branch})["head"],
"cur_com_level": param_entry["cur_com_level"],
"cur_branch": repo.cur_branch,
"cur_patch_num": param_entry["cur_patch_num"],
},
upsert=True
)
param = repo.params.find_one({"path": root_path})
cur_branch_obj=db.branches.find_one({"name":repo.cur_branch})
if cur_branch_obj !=None:
head_commit_id=cur_branch_obj["head"]
repo.rollback(head_commit_id)