Back to index

nordugrid-arc-nox  1.1.0~rc6
Functions | Variables
storage.shepherd.slave Namespace Reference

Functions

def fbuffer
def handler

Variables

int CHUNK_SIZE = 2

Function Documentation

def storage.shepherd.slave.fbuffer (   f,
  chunk_size = 10000 
)

Definition at line 7 of file slave.py.

00007 
00008 def fbuffer(f, chunk_size=10000):
00009    while True:
00010       chunk = f.read(chunk_size)
00011       if not chunk: break
00012       yield chunk
00013 

Here is the caller graph for this function:

Function handling apache slave mode
Checks if requested hardlink exists, opens file, deletes
hardlink from server and PUTs or GETs requested file

Definition at line 14 of file slave.py.

00014 
00015 def handler(req):
00016     """
00017     Function handling apache slave mode
00018     Checks if requested hardlink exists, opens file, deletes
00019     hardlink from server and PUTs or GETs requested file
00020     """
00021 
00022     req.allow_methods(['M_PUT','M_GET'])
00023 
00024     if req.filename.endswith('.transfering'):
00025         raise apache.SERVER_RETURN, apache.HTTP_FORBIDDEN
00026 
00027     if os.path.isfile(req.filename) and not req.filename.endswith('.py'):
00028 
00029         req_method = req.the_request[:3]
00030 
00031         tmp_filename=req.filename+'.transfering'
00032 
00033         if req_method == 'GET':
00034             f = open(req.filename, 'rb', CHUNK_SIZE)
00035         elif req_method == 'PUT':
00036             f = open(req.filename, 'ab', CHUNK_SIZE)
00037 
00038         os.rename(req.filename, tmp_filename)
00039 
00040         if req_method == 'GET':
00041             for chunk in fbuffer(f):
00042                 req.write(chunk)
00043 
00044         elif req_method == 'PUT':
00045             for chunk in fbuffer(req):
00046                 f.write(chunk)
00047 
00048         
00049         if req_method == 'GET':
00050            if req.headers_in.get("range", "").startswith("bytes=%ld"%f.tell()):
00051               os.remove(tmp_filename)
00052            else:
00053               os.rename(tmp_filename, req.filename)
00054         elif req_method == 'PUT':
00055            if req.headers_in.get("Content-Range", "").endswith(str(f.tell())):
00056               os.remove(tmp_filename)
00057            else:
00058               os.rename(tmp_filename, req.filename)
00059         f.close()
00060         return apache.OK
00061         
00062 
00063     else:
00064         raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 4 of file slave.py.