cpg2py 1.0.3__py3-none-any.whl → 1.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cpg2py/__init__.py +15 -25
- {cpg2py-1.0.3.dist-info → cpg2py-1.0.4.dist-info}/METADATA +1 -1
- {cpg2py-1.0.3.dist-info → cpg2py-1.0.4.dist-info}/RECORD +6 -6
- {cpg2py-1.0.3.dist-info → cpg2py-1.0.4.dist-info}/LICENSE +0 -0
- {cpg2py-1.0.3.dist-info → cpg2py-1.0.4.dist-info}/WHEEL +0 -0
- {cpg2py-1.0.3.dist-info → cpg2py-1.0.4.dist-info}/top_level.txt +0 -0
cpg2py/__init__.py
CHANGED
|
@@ -1,35 +1,20 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from pathlib import Path
|
|
3
1
|
from csv import DictReader
|
|
2
|
+
from pathlib import Path
|
|
4
3
|
from .cpg import _Graph
|
|
5
4
|
from .abc import *
|
|
6
5
|
|
|
7
|
-
def
|
|
8
|
-
"""Create a new clean file without NULL bytes and return its path."""
|
|
9
|
-
clean_path = file_path.with_suffix(".clean.csv") # Create a temp clean file
|
|
10
|
-
if clean_path.exists(): os.remove(clean_path)
|
|
11
|
-
with open(file_path, "rb") as f:
|
|
12
|
-
content = f.read().replace(b"\x00", b"") # Remove NULL bytes
|
|
13
|
-
with open(clean_path, "wb") as f:
|
|
14
|
-
f.write(content)
|
|
15
|
-
return clean_path
|
|
16
|
-
|
|
17
|
-
def cpg_graph(node_csv: Path, edge_csv: Path) -> _Graph:
|
|
18
|
-
# Clean files before reading
|
|
19
|
-
tmp_node_csv = __remove_null_bytes(node_csv)
|
|
6
|
+
def cpg_graph(node_csv: Path, edge_csv: Path) -> "_Graph":
|
|
20
7
|
storage = Storage()
|
|
21
|
-
with open(
|
|
8
|
+
with open(node_csv, 'r') as n_file:
|
|
22
9
|
reader = DictReader(n_file, delimiter='\t')
|
|
23
10
|
for node_props in reader:
|
|
24
11
|
nid = node_props.get("id:int", None)
|
|
25
12
|
if nid is None: node_props.get("id")
|
|
26
13
|
if not storage.add_node(nid):
|
|
27
|
-
print(f"Node {nid} already exists in the graph")
|
|
14
|
+
print(f"WARN: Node {nid} already exists in the graph")
|
|
28
15
|
if not storage.set_node_props(nid, node_props):
|
|
29
|
-
print(f"Failed to set properties for node {nid}")
|
|
30
|
-
|
|
31
|
-
tmp_edge_csv = __remove_null_bytes(edge_csv)
|
|
32
|
-
with open(tmp_edge_csv, 'r') as f:
|
|
16
|
+
print(f"WARN: Failed to set properties for node {nid}")
|
|
17
|
+
with open(edge_csv, 'r') as f:
|
|
33
18
|
reader = DictReader(f, delimiter='\t')
|
|
34
19
|
for edge_props in reader:
|
|
35
20
|
f_nid = str(edge_props.get("start", None) )
|
|
@@ -39,12 +24,17 @@ def cpg_graph(node_csv: Path, edge_csv: Path) -> _Graph:
|
|
|
39
24
|
e_type = str(edge_props.get("type", None))
|
|
40
25
|
if e_type is None: e_type = str(edge_props.get("type:str"))
|
|
41
26
|
edge_id = (f_nid, t_nid, e_type)
|
|
27
|
+
if not storage.contains_node(edge_id[0]):
|
|
28
|
+
storage.add_node(edge_id[0])
|
|
29
|
+
print(f"WARN: node {edge_id[0]} does not exists")
|
|
30
|
+
if not storage.contains_node(edge_id[1]):
|
|
31
|
+
storage.add_node(edge_id[1])
|
|
32
|
+
print(f"WARN: node {edge_id[1]} does not exists")
|
|
42
33
|
if not storage.add_edge(edge_id):
|
|
43
|
-
print(f"Edge {f_nid} -> {t_nid} already exists in the graph")
|
|
34
|
+
print(f"WARN: Edge {f_nid} -> {t_nid} already exists in the graph")
|
|
44
35
|
if not storage.set_edge_props(edge_id, edge_props):
|
|
45
|
-
print(f"Failed to set properties for edge {edge_id}")
|
|
46
|
-
|
|
47
|
-
return _Graph(storage)
|
|
36
|
+
print(f"WARN: Failed to set properties for edge {edge_id}")
|
|
37
|
+
return _Graph(storage)
|
|
48
38
|
|
|
49
39
|
|
|
50
40
|
__all__ = ['cpg_graph', 'AbcGraphQuerier', 'AbcNodeQuerier', 'AbcEdgeQuerier', 'Storage']
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
cpg2py/__init__.py,sha256=
|
|
1
|
+
cpg2py/__init__.py,sha256=4GXaMrMxlqWKpjrwAZlSwBCG-9_osMeChuFS-WRqtKg,1918
|
|
2
2
|
cpg2py/abc/__init__.py,sha256=HgDXsJkGcPQvr6ac3hMrUU9TuQibMaP7-oXbXLs_iLI,207
|
|
3
3
|
cpg2py/abc/edge.py,sha256=zLlRebDKT2qK5XOJq23_UUCESgGsvgalbXdx_uUcKks,1240
|
|
4
4
|
cpg2py/abc/graph.py,sha256=DbeHN6qsNaqcqL9cUquJWC16BihDxy1MEhyuL-qVMBI,3902
|
|
@@ -8,8 +8,8 @@ cpg2py/cpg/__init__.py,sha256=fO59Yd7OISyxdjdZDJ5zFM41r4cYKawOsvpqV4gWrGM,48
|
|
|
8
8
|
cpg2py/cpg/edge.py,sha256=brG7cQl7tjihbUCBYyjNUnMLsKIif-XQc_TFdGz8ZYo,1007
|
|
9
9
|
cpg2py/cpg/graph.py,sha256=n4EjAhhjzl0XRJBwlAmK5AcSrECiqhjA6dXt2Ucf7IM,3448
|
|
10
10
|
cpg2py/cpg/node.py,sha256=-2xl8c-eSbe4Kv4xPAEf6POlCYOV4j0voxJAKDZj3Cc,2037
|
|
11
|
-
cpg2py-1.0.
|
|
12
|
-
cpg2py-1.0.
|
|
13
|
-
cpg2py-1.0.
|
|
14
|
-
cpg2py-1.0.
|
|
15
|
-
cpg2py-1.0.
|
|
11
|
+
cpg2py-1.0.4.dist-info/LICENSE,sha256=vTjbt7iL1hUilI8E87FoQerEDa9nbpeip26iA6bguHI,1066
|
|
12
|
+
cpg2py-1.0.4.dist-info/METADATA,sha256=Xhx-JFz1RECxW-aLxPhfy4elJgFoaTjxxiXR28YD-c8,7077
|
|
13
|
+
cpg2py-1.0.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
14
|
+
cpg2py-1.0.4.dist-info/top_level.txt,sha256=xDY8faKh5Rczvsqb5Jt9Sq-Y7EOImh7jh-m1oVTnH5k,7
|
|
15
|
+
cpg2py-1.0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|