File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -2855,7 +2855,7 @@ def parent(self, codebase=None):
2855
2855
"""
2856
2856
parent_path = self .parent_path ()
2857
2857
return parent_path and self .project .codebaseresources .get (path = parent_path )
2858
-
2858
+
2859
2859
def siblings (self , codebase = None ):
2860
2860
"""
2861
2861
Return a sequence of sibling Resource objects for this Resource
@@ -3078,6 +3078,18 @@ def as_spdx(self):
3078
3078
types = self .get_spdx_types (),
3079
3079
)
3080
3080
3081
+ def serialize (self ):
3082
+ """
3083
+ Return a mapping of represting this CodebaseResource and it's data in a form
3084
+ that can be serialized to JSON, YAML, etc. it can be used to reconstruct
3085
+ the resource
3086
+ """
3087
+ serializable = defaultdict (dict )
3088
+ serializable ["name" ] = self .name
3089
+ serializable ["type" ] = self .type .value
3090
+ if self .location :
3091
+ serializable ["location" ] = self .location
3092
+ return dict (serializable )
3081
3093
3082
3094
class CodebaseRelation (
3083
3095
UUIDPKModel ,
Original file line number Diff line number Diff line change @@ -1917,6 +1917,24 @@ def test_scanpipe_codebase_resource_ancestors(self):
1917
1917
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref" ,
1918
1918
]
1919
1919
self .assertEqual (expected , [resource .path for resource in ancestors ])
1920
+
1921
+ def test_scanpipe_codebase_resource_serialize (self ):
1922
+ resource1 = make_resource_file (self .project1 , path = "pathtoresource/resource1" )
1923
+ expected = {
1924
+ "location" : resource1 .location ,
1925
+ "type" : "file" ,
1926
+ "name" : "resource1" ,
1927
+ }
1928
+ self .assertEqual (expected , resource1 .serialize ())
1929
+
1930
+ resource2 = make_resource_directory (self .project1 , path = "pathtodir/resource2" )
1931
+ expected = {
1932
+ "location" : resource2 .location ,
1933
+ "type" : "directory" ,
1934
+ "name" : "resource2" ,
1935
+ }
1936
+ self .assertEqual (expected , resource2 .serialize ())
1937
+
1920
1938
1921
1939
def test_scanpipe_codebase_resource_children (self ):
1922
1940
path = "asgiref-3.3.0-py3-none-any.whl-extract"
You can’t perform that action at this time.
0 commit comments