@@ -268,6 +268,7 @@ def _base_model(self, path):
268
268
model ["mimetype" ] = None
269
269
model ["size" ] = size
270
270
model ["writable" ] = self .is_writable (path )
271
+ model ["md5" ] = None
271
272
272
273
return model
273
274
@@ -335,7 +336,7 @@ def _dir_model(self, path, content=True):
335
336
336
337
return model
337
338
338
- def _file_model (self , path , content = True , format = None ):
339
+ def _file_model (self , path , content = True , format = None , md5 = False ):
339
340
"""Build a model for a file
340
341
341
342
if content is requested, include the file contents.
@@ -364,10 +365,13 @@ def _file_model(self, path, content=True, format=None):
364
365
content = content ,
365
366
format = format ,
366
367
)
368
+ if md5 :
369
+ md5 = self ._get_md5 (os_path )
370
+ model .update (md5 = md5 )
367
371
368
372
return model
369
373
370
- def _notebook_model (self , path , content = True ):
374
+ def _notebook_model (self , path , content = True , md5 = False ):
371
375
"""Build a notebook model
372
376
373
377
if content is requested, the notebook content will be populated
@@ -386,10 +390,12 @@ def _notebook_model(self, path, content=True):
386
390
model ["content" ] = nb
387
391
model ["format" ] = "json"
388
392
self .validate_notebook_model (model , validation_error )
393
+ if md5 :
394
+ model ["md5" ] = self ._get_md5 (os_path )
389
395
390
396
return model
391
397
392
- def get (self , path , content = True , type = None , format = None ):
398
+ def get (self , path , content = True , type = None , format = None , md5 = None ):
393
399
"""Takes a path for an entity and returns its model
394
400
395
401
Parameters
@@ -404,6 +410,8 @@ def get(self, path, content=True, type=None, format=None):
404
410
format : str, optional
405
411
The requested format for file contents. 'text' or 'base64'.
406
412
Ignored if this returns a notebook or directory model.
413
+ md5: bool, optional
414
+ Whether to include the md5 of the file contents.
407
415
408
416
Returns
409
417
-------
@@ -431,11 +439,11 @@ def get(self, path, content=True, type=None, format=None):
431
439
)
432
440
model = self ._dir_model (path , content = content )
433
441
elif type == "notebook" or (type is None and path .endswith (".ipynb" )):
434
- model = self ._notebook_model (path , content = content )
442
+ model = self ._notebook_model (path , content = content , md5 = md5 )
435
443
else :
436
444
if type == "directory" :
437
445
raise web .HTTPError (400 , "%s is not a directory" % path , reason = "bad type" )
438
- model = self ._file_model (path , content = content , format = format )
446
+ model = self ._file_model (path , content = content , format = format , md5 = md5 )
439
447
self .emit (data = {"action" : "get" , "path" : path })
440
448
return model
441
449
@@ -686,7 +694,9 @@ def _get_dir_size(self, path="."):
686
694
).stdout .split ()
687
695
else :
688
696
result = subprocess .run (
689
- ["du" , "-s" , "--block-size=1" , path ], capture_output = True , check = True
697
+ ["du" , "-s" , "--block-size=1" , path ],
698
+ capture_output = True ,
699
+ check = True ,
690
700
).stdout .split ()
691
701
692
702
self .log .info (f"current status of du command { result } " )
@@ -784,7 +794,7 @@ async def _dir_model(self, path, content=True):
784
794
785
795
return model
786
796
787
- async def _file_model (self , path , content = True , format = None ):
797
+ async def _file_model (self , path , content = True , format = None , md5 = False ):
788
798
"""Build a model for a file
789
799
790
800
if content is requested, include the file contents.
@@ -813,10 +823,13 @@ async def _file_model(self, path, content=True, format=None):
813
823
content = content ,
814
824
format = format ,
815
825
)
826
+ if md5 :
827
+ md5 = await self ._get_md5 (os_path )
828
+ model .update (md5 = md5 )
816
829
817
830
return model
818
831
819
- async def _notebook_model (self , path , content = True ):
832
+ async def _notebook_model (self , path , content = True , md5 = False ):
820
833
"""Build a notebook model
821
834
822
835
if content is requested, the notebook content will be populated
@@ -835,10 +848,12 @@ async def _notebook_model(self, path, content=True):
835
848
model ["content" ] = nb
836
849
model ["format" ] = "json"
837
850
self .validate_notebook_model (model , validation_error )
851
+ if md5 :
852
+ model ["md5" ] = await self ._get_md5 (os_path )
838
853
839
854
return model
840
855
841
- async def get (self , path , content = True , type = None , format = None ):
856
+ async def get (self , path , content = True , type = None , format = None , md5 = False ):
842
857
"""Takes a path for an entity and returns its model
843
858
844
859
Parameters
@@ -853,6 +868,8 @@ async def get(self, path, content=True, type=None, format=None):
853
868
format : str, optional
854
869
The requested format for file contents. 'text' or 'base64'.
855
870
Ignored if this returns a notebook or directory model.
871
+ md5: bool, optional
872
+ Whether to include the md5 of the file contents.
856
873
857
874
Returns
858
875
-------
@@ -875,11 +892,11 @@ async def get(self, path, content=True, type=None, format=None):
875
892
)
876
893
model = await self ._dir_model (path , content = content )
877
894
elif type == "notebook" or (type is None and path .endswith (".ipynb" )):
878
- model = await self ._notebook_model (path , content = content )
895
+ model = await self ._notebook_model (path , content = content , md5 = md5 )
879
896
else :
880
897
if type == "directory" :
881
898
raise web .HTTPError (400 , "%s is not a directory" % path , reason = "bad type" )
882
- model = await self ._file_model (path , content = content , format = format )
899
+ model = await self ._file_model (path , content = content , format = format , md5 = md5 )
883
900
self .emit (data = {"action" : "get" , "path" : path })
884
901
return model
885
902
@@ -1147,7 +1164,9 @@ async def _get_dir_size(self, path: str = ".") -> str:
1147
1164
).stdout .split ()
1148
1165
else :
1149
1166
result = subprocess .run (
1150
- ["du" , "-s" , "--block-size=1" , path ], capture_output = True , check = True
1167
+ ["du" , "-s" , "--block-size=1" , path ],
1168
+ capture_output = True ,
1169
+ check = True ,
1151
1170
).stdout .split ()
1152
1171
1153
1172
self .log .info (f"current status of du command { result } " )
0 commit comments