Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:46

0001 #!/usr/bin/env python
0002 #
0003 # Copyright (c) 2019 Opticks Team. All Rights Reserved.
0004 #
0005 # This file is part of Opticks
0006 # (see https://bitbucket.org/simoncblyth/opticks).
0007 #
0008 # Licensed under the Apache License, Version 2.0 (the "License"); 
0009 # you may not use this file except in compliance with the License.  
0010 # You may obtain a copy of the License at
0011 #
0012 #   http://www.apache.org/licenses/LICENSE-2.0
0013 #
0014 # Unless required by applicable law or agreed to in writing, software 
0015 # distributed under the License is distributed on an "AS IS" BASIS, 
0016 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
0017 # See the License for the specific language governing permissions and 
0018 # limitations under the License.
0019 #
0020 
0021 
0022 import os, sys
0023 
0024 class BPath(object):
0025     """
0026     Python version of brap/BPath for juicing the idpath
0027     allowing the srcpath, srcdigest and layout to be
0028     extracted 
0029     """
0030     def __init__(self, idpath):
0031 
0032         elem = idpath.split("/")
0033         last = elem[-1]
0034         bits = last.split(".") 
0035 
0036         is_triple = len(bits) == 3
0037 
0038         if is_triple:
0039             layout = 0 
0040             idfile = ".".join([bits[0], bits[2]])
0041             srcdigest = bits[1]
0042             assert len(srcdigest) == 32, srcdigest
0043             idname = elem[-2]
0044             geobase = os.path.sep + os.path.join( *elem[0:-2] )
0045             prefix = os.path.sep + os.path.join( *elem[0:-4] )
0046         else:
0047             layout = int(last)
0048             assert layout > 0, layout
0049             srcdigest = elem[-2]
0050             idfile = elem[-3]
0051             idname = elem[-4]
0052             geobase = os.path.sep + os.path.join( *elem[0:-4] )
0053             prefix = os.path.sep + os.path.join( *elem[0:-5] )
0054         pass
0055   
0056         self.idpath = idpath 
0057         self.layout = layout 
0058         self.srcpath = os.path.join( prefix, "opticksdata", "export", idname, idfile )
0059         self.srcdigest = srcdigest
0060 
0061     def __repr__(self):
0062         return "\n".join(["BPath layout %d" % self.layout, self.idpath, self.srcpath, self.srcdigest])  
0063       
0064 
0065 
0066 if __name__ == '__main__':
0067 
0068     keys = filter(lambda k:k.startswith("IDPATH"), os.environ.keys() )
0069     for key in keys:
0070         idpath = os.environ.get(key, None)
0071         idp = BPath(idpath)
0072         print()
0073         print(key) 
0074         print(idp)
0075 
0076         if not os.path.isdir(idp.idpath):
0077            print(" missing idpath ")
0078         if not os.path.isfile(idp.srcpath):
0079            print(" missing srcpath ")
0080 
0081 
0082