Module XALT_Rmap
[hide private]
[frames] | no frames]

Source Code for Module XALT_Rmap

 1  #----------------------------------------------------------------------- 
 2  # XALT: A tool that tracks users jobs and environments on a cluster. 
 3  # Copyright (C) 2013-2014 University of Texas at Austin 
 4  # Copyright (C) 2013-2014 University of Tennessee 
 5  #  
 6  # This library is free software; you can redistribute it and/or modify 
 7  # it under the terms of the GNU Lesser General Public License as 
 8  # published by the Free Software Foundation; either version 2.1 of  
 9  # the License, or (at your option) any later version.  
10  # 
11  # This library is distributed in the hope that it will be useful, 
12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
14  # Lesser  General Public License for more details.  
15  # 
16  # You should have received a copy of the GNU Lesser General Public 
17  # License along with this library; if not, write to the Free 
18  # Software Foundation, Inc., 59 Temple Place, Suite 330, 
19  # Boston, MA 02111-1307 USA 
20  #----------------------------------------------------------------------- 
21  # 
22  # Git Version: @git@ 
23   
24  from __future__  import print_function 
25  import os, sys, re, json, time, argparse 
26  dirNm, execName = os.path.split(os.path.realpath(sys.argv[0])) 
27  sys.path.append(os.path.realpath(os.path.join(dirNm, "../libexec"))) 
28  sys.path.append(os.path.realpath(os.path.join(dirNm, "../site"))) 
29   
30 -class Rmap(object):
31 """ This class files the reverseMap File from the reverse map directory"""
32 - def __init__(self, rmapD):
33 """ 34 This ctor opens the reverse map directory. It looks for a file named 35 "jsonReverseMapT.json". If that file is not found it looks for 36 "jsonReverseMapT.old.json". The file is read in and converted to a 37 python table. The contents contain a timestampfn key value pair. 38 39 The reverse map table is return in all cases except when the timestamp 40 file exists and is newer than the reverseMap file. 41 42 @param rmapD: The reverse map directory 43 """ 44 self.__rmapT = {} 45 if (not rmapD): 46 return 47 rmapA = rmapD.split(':') 48 searchA = [ ".json", ".old.json"] 49 rmapFn = None 50 for dir in rmapA: 51 for ext in searchA: 52 rmapFn = os.path.join(dir, "jsonReverseMapT" + ext) 53 if (os.access(rmapFn, os.R_OK)): 54 break 55 if (rmapFn): 56 rmpMtime = os.stat(rmapFn).st_mtime 57 f = open(rmapFn,"r") 58 t = json.loads(f.read()) 59 f.close() 60 tsFn = t.get('timestampFn') 61 if (tsFn): 62 tsMtime = os.stat(tsFn).st_mtime 63 if (rmpMtime >= tsMtime): 64 self.__rmapT = t['reverseMapT'] 65 else: 66 self.__rmapT = t['reverseMapT']
67 68
69 - def reverseMapT(self):
70 """ 71 return the reverse map table found by the ctor. 72 73 @return reverseMapT 74 """ 75 return self.__rmapT
76