示例#1
0
 def __search( self, did ):
   path = self.decodePath( did )
   cond = self.decodeMetadataQuery()
   result = yield self.threadTask( self.rpc.findDirectoriesByMetadata, cond, path )
   if not result[ 'OK' ]:
     raise WErr.fromError( result )
   data = self.__filterChildrenOf( path, result[ 'Value' ] )
   result = yield self.threadTask( self.rpc.getDirectorySize, data, False, False )
   if not result[ 'OK' ]:
     raise WErr.fromError( result )
   tree = self.__buildDirTree( path, result[ 'Value' ][ 'Successful' ] )
   self.finish( self.sanitizeForJSON( tree ) )
示例#2
0
 def __getCompatibleMetadata( self, did ):
   path = self.decodePath( did )
   cond = self.decodeMetadataQuery()
   result = yield self.threadTask( self.rpc.getCompatibleMetadata, cond, path )
   if not result[ "OK" ] :
     raise WErr.fromError( result )
   self.finish( self.sanitizeForJSON( result[ 'Value' ] ) )
示例#3
0
 def __deleteDir( self, did ):
   path = self.decodePath( did )
   result = yield self.threadTask( self.rpc.removeDirectory, path )
   if not result[ 'OK' ]:
     if result[ 'Message' ].lower().find( "not exist" ) > -1:
       raise WErr( 404, result[ 'Message' ] )
     else:
       raise WErr.fromError( result )
   self.finish( { path: True } )
示例#4
0
 def get( self ):
   cond = self.decodeMetadataQuery()
   result = yield self.threadTask( self.rpc.getMetadataFields )
   if not result[ "OK" ] :
     raise WErr.fromError( result )
   data = result["Value"]
   fields = {}
   for k in data[ 'DirectoryMetaFields' ]:
     fields[ k ] = data[ 'DirectoryMetaFields' ][k].lower()
   result = yield self.threadTask( self.rpc.getCompatibleMetadata, cond, "/" )
   if not result[ "OK" ] :
     raise WErr.fromError( result )
   values = result[ 'Value' ]
   data = {}
   for k in fields:
     if k not in values:
       continue
     data[ k ] = { 'type' : fields[k], 'values': values[k] }
   self.finish( data )
示例#5
0
 def __createDir( self, did ):
   path = self.decodePath( did )
   result = yield self.threadTask( self.rpc.createDirectory, path )
   if not result[ 'OK' ]:
     raise WErr.fromError( result )
   data = result[ 'Value' ]
   if path in data[ 'Successful' ]:
     self.finish( data[ 'Successful' ][ path ] )
   else:
     raise WErr( 404, data[ 'Failed' ][ path ] )
示例#6
0
 def __listDir( self, did ):
   path = self.decodePath( did )
   try:
     pageSize = max( 0, int( self.request.arguments[ 'page_size' ][-1] ) )
   except ( ValueError, KeyError ):
     pageSize = 0
   try:
     verbose = bool( self.request.arguments[ 'extra' ][-1] )
   except KeyError:
     verbose = False
   result = yield self.threadTask( self.rpc.listDirectory, path, verbose )
   if not result[ 'OK' ]:
     self.log.error( "Cannot list directory for %s:%s" % ( path, result[ 'Message' ] ) )
     raise WErr.fromError( result )
   data = result[ 'Value' ]
   if not path in data[ 'Successful' ]:
     raise WErr( 404, data[ 'Failed' ][ path ] )
   contents = data[ 'Successful' ][ path ]
   ch = {}
   for kind in contents:
     ch[ kind ] = {}
     for sp in contents[ kind ]:
       ch[ kind ][ sp[ len( path ) + 1: ] ] = contents[ kind ][ sp ]
   self.finish( self.sanitizeForJSON( ch ) )
示例#7
0
 def __getMetadata( self, fid ):
   path = self.decodePath( fid )
   result = yield self.threadTask( self.rpc.getFileUserMetadata, path )
   if not result[ "OK" ] :
     raise WErr.fromError( result )
   self.finish( self.sanitizeForJSON( result[ 'Value' ] ) )
示例#8
0
 def __getAttributes( self, fid ):
   path = self.decodePath( fid )
   result = yield self.threadTask( self.rpc.getFileMetadata, path )
   if not result[ "OK" ] or path not in result[ 'Value' ][ 'Successful' ]:
     raise WErr.fromError( result )
   self.finish( self.sanitizeForJSON( result[ 'Value' ][ 'Successful' ][ path ] ) )