def print_obj(datafile, check_etag=True, swift_dir='/etc/swift', policy_name=''):
 if (not os.path.exists(datafile)):
  print("Data file doesn't exist")
  raise InfoSystemExit()
 if (not datafile.startswith(('/', './'))):
  datafile = ('./' + datafile)
 policy_index = None
 ring = None
 datadir = DATADIR_BASE
 fullpath = os.path.abspath(datafile)
 policy_index = int((extract_policy(fullpath) or POLICIES.legacy))
 try:
  if policy_index:
   datadir += ('-' + str(policy_index))
   ring = Ring(swift_dir, ring_name=('object-' + str(policy_index)))
  elif (policy_index == 0):
   ring = Ring(swift_dir, ring_name='object')
 except IOError:
  pass
 if policy_name:
  policy = POLICIES.get_by_name(policy_name)
  if policy:
   policy_index_for_name = policy.idx
   if ((policy_index is not None) and (policy_index_for_name is not None) and (policy_index != policy_index_for_name)):
    print('Warning: Ring does not match policy!')
    print('Double check your policy name!')
   if ((not ring) and policy_index_for_name):
    ring = POLICIES.get_object_ring(policy_index_for_name, swift_dir)
    datadir = get_data_dir(policy_index_for_name)
 with open(datafile, 'rb') as fp:
  try:
   metadata = read_metadata(fp)
  except EOFError:
   print('Invalid metadata')
   raise InfoSystemExit()
  etag = metadata.pop('ETag', '')
  length = metadata.pop('Content-Length', '')
  path = metadata.get('name', '')
  print_obj_metadata(metadata)
  file_len = None
  if check_etag:
   h = md5()
   file_len = 0
   while True:
    data = fp.read((64 * 1024))
    if (not data):
     break
    h.update(data)
    file_len += len(data)
   h = h.hexdigest()
   if etag:
    if (h == etag):
     print(('ETag: %s (valid)' % etag))
    else:
     print(("ETag: %s doesn't match file hash of %s!" % (etag, h)))
   else:
    print('ETag: Not found in metadata')
  else:
   print(('ETag: %s (not checked)' % etag))
   file_len = os.fstat(fp.fileno()).st_size
  if length:
   if (file_len == int(length)):
    print(('Content-Length: %s (valid)' % length))
   else:
    print(("Content-Length: %s doesn't match file length of %s" % (length, file_len)))
  else:
   print('Content-Length: Not found in metadata')
  (account, container, obj) = path.split('/', 3)[1:]
  if ring:
   print_ring_locations(ring, datadir, account, container, obj, policy_index=policy_index)

def print_obj ( datafile , check_etag = True , swift_dir = '/etc/swift' , policy_name = '' ) : if ( not os . path . exists ( datafile ) ) : print ( "Data file doesn't exist" ) raise InfoSystemExit ( ) if ( not datafile . startswith ( ( '/' , './' ) ) ) : datafile = ( './' + datafile ) policy_index = None ring = None datadir = DATADIR_BASE fullpath = os . path . abspath ( datafile ) policy_index = int ( ( extract_policy ( fullpath ) or POLICIES . legacy ) ) try : if policy_index : datadir += ( '-' + str ( policy_index ) ) ring = Ring ( swift_dir , ring_name = ( 'object-' + str ( policy_index ) ) ) elif ( policy_index == 0 ) : ring = Ring ( swift_dir , ring_name = 'object' ) except IOError : pass if policy_name : policy = POLICIES . get_by_name ( policy_name ) if policy : policy_index_for_name = policy . idx if ( ( policy_index is not None ) and ( policy_index_for_name is not None ) and ( policy_index != policy_index_for_name ) ) : print ( 'Warning: Ring does not match policy!' ) print ( 'Double check your policy name!' ) if ( ( not ring ) and policy_index_for_name ) : ring = POLICIES . get_object_ring ( policy_index_for_name , swift_dir ) datadir = get_data_dir ( policy_index_for_name ) with open ( datafile , 'rb' ) as fp : try : metadata = read_metadata ( fp ) except EOFError : print ( 'Invalid metadata' ) raise InfoSystemExit ( ) etag = metadata . pop ( 'ETag' , '' ) length = metadata . pop ( 'Content-Length' , '' ) path = metadata . get ( 'name' , '' ) print_obj_metadata ( metadata ) file_len = None if check_etag : h = md5 ( ) file_len = 0 while True : data = fp . read ( ( 64 * 1024 ) ) if ( not data ) : break h . update ( data ) file_len += len ( data ) h = h . hexdigest ( ) if etag : if ( h == etag ) : print ( ( 'ETag: %s (valid)' % etag ) ) else : print ( ( "ETag: %s doesn't match file hash of %s!" % ( etag , h ) ) ) else : print ( 'ETag: Not found in metadata' ) else : print ( ( 'ETag: %s (not checked)' % etag ) ) file_len = os . fstat ( fp . fileno ( ) ) . st_size if length : if ( file_len == int ( length ) ) : print ( ( 'Content-Length: %s (valid)' % length ) ) else : print ( ( "Content-Length: %s doesn't match file length of %s" % ( length , file_len ) ) ) else : print ( 'Content-Length: Not found in metadata' ) ( account , container , obj ) = path . split ( '/' , 3 ) [ 1 : ] if ring : print_ring_locations ( ring , datadir , account , container , obj , policy_index = policy_index )
print an album or item object .