325def file_name(fname):
326 """take a file name, return the pair (protocol, 'real' file name)
327 """
328 fname = os.path.expanduser(os.path.expandvars(fname))
329
330 def _normalize_uri(uri):
331 if uri.startswith('/'):
332 return 'file:'+uri
333 return uri
334
335 from urllib.parse import urlsplit
336 url = urlsplit(_normalize_uri(fname))
337 protocol = url.scheme
338 def _normalize(fname):
339 from posixpath import normpath
340 fname = normpath(fname)
341 if fname.startswith('//'): fname = fname[1:]
342 return fname
343
344 if protocol in ('', 'file', 'pfn'):
345 protocol = ''
346 fname = _normalize(url.path)
347
348
349 if fname.startswith('/castor/'):
350 protocol = 'rfio'
351 fname = protocol + ':' + fname
352
353 elif protocol in ('rfio', 'castor'):
354 protocol = 'rfio'
355 fname = _normalize(url.path)
356 fname = protocol+':'+fname
357
358 elif protocol in ('root','dcap', 'dcache', 'http', 'https', 'dav', 'davs'):
359 pass
360
361 elif protocol in ('gsidcap',):
362 protocol = 'gfal:gsidcap'
363 pass
364
365 elif protocol in ('lfn','fid',):
366
367 from PyUtils.PoolFile import PoolFileCatalog as pfc
368 fname = pfc().pfn(protocol+':'+url.path)
369 pass
370
371 elif protocol in ('ami',):
372
373 for token in ('ami:', '//', '/'):
374 if fname.startswith(token):
375 fname = fname[len(token):]
376 fname = 'ami://' + fname
377 pass
378
379 else:
380 print(f
'## warning: unknown protocol [{protocol}]. we will just return our input')
381 pass
382
383 return (protocol, fname)
384