def getISCSites(): import glob, os.path from com.raytheon.uf.common.localization import PathManagerFactory from com.raytheon.uf.common.localization import LocalizationContext LocalizationType = LocalizationContext.LocalizationType LocalizationLevel = LocalizationContext.LocalizationLevel pathMgr = PathManagerFactory.getPathManager() commonStaticCfg = pathMgr.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.CONFIGURED) commonStaticCfg.setContextName(siteConfig.GFESUITE_SITEID) eaDir = pathMgr.getFile(commonStaticCfg, "gfe/editAreas").getCanonicalPath() files = glob.glob(eaDir + "/ISC_???.xml") sites = [] WFOSites = BackupDict.keys() for f in files: fb = os.path.basename(f) if len(fb) == 11 and fb[0:4] == "ISC_": site = fb[4:7] #ensure it is a known WFO site if site in WFOSites: sites.append(site) #remove our own site if siteConfig.GFESUITE_SITEID in sites: del sites[sites.index(siteConfig.GFESUITE_SITEID)] return sites
def getEditArea(name, siteID): pathMgr = PathManagerFactory.getPathManager() commonStaticConfig = pathMgr.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.SITE) commonStaticConfig.setContextName(siteID) file = pathMgr.getFile(commonStaticConfig, "gfe/editAreas" + File.separator + name + ".xml") if not os.path.exists(file.getPath()): commonStaticConfig = pathMgr.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.CONFIGURED) commonStaticConfig.setContextName(siteID) file = pathMgr.getFile( commonStaticConfig, "gfe/editAreas" + File.separator + name + ".xml") refData = None try: if os.path.exists(file.getPath()): refData = ReferenceData.getJAXBManager().unmarshalFromXmlFile( file.getPath()) else: LogStream.logProblem("EDIT AREA NOT FOUND: ", name, " for site ", siteID) except: LogStream.logProblem("Unable to unmarshal " + name + " in iscExtract") return refData
def outputFiles(self, filename, attachLogo=False, logoText=None): rendered = self.getTarget().screenshot() if attachLogo: from java.awt.image import BufferedImage from com.raytheon.uf.common.localization import PathManagerFactory noaa = 'pyViz/logos/noaalogo2.png' nws = 'pyViz/logos/nwslogo.png' pathMgr = PathManagerFactory.getPathManager() noaa = pathMgr.getStaticFile(noaa) nws = pathMgr.getStaticFile(nws) noaaImage = ImageIO.read(noaa) nwsImage = ImageIO.read(nws) height = rendered.getHeight() + noaaImage.getHeight() finalBuf = BufferedImage(rendered.getWidth(), height, BufferedImage.TYPE_INT_ARGB) graphics = finalBuf.createGraphics() graphics.drawImage(rendered, 0, 0, None) graphics.drawImage(noaaImage, 0, rendered.getHeight(), None) graphics.fillRect(noaaImage.getWidth(), rendered.getHeight(), rendered.getWidth() - noaaImage.getWidth() - nwsImage.getWidth(), rendered.getHeight()) if logoText is not None: from java.awt import Color from com.raytheon.uf.viz.core.font import FontAdapter graphics.setColor(Color.BLACK) graphics.setFont(FontAdapter.getAWTFont(self.getTarget().getDefaultFont())) fm = graphics.getFontMetrics() textBounds = fm.getStringBounds(logoText, graphics) graphics.drawString(logoText, int((rendered.getWidth() - textBounds.getWidth()) / 2), \ int(rendered.getHeight() + (noaaImage.getHeight() / 2) + textBounds.getHeight() / 2)) graphics.drawImage(nwsImage, finalBuf.getWidth() - nwsImage.getWidth(), rendered.getHeight(), None) finalBuf.flush() self.outputImage(finalBuf, filename) else: self.outputImage(rendered, filename)
def deleteEditArea(name, siteID): pathMgr = PathManagerFactory.getPathManager() commonStaticConfig = pathMgr.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.CONFIGURED) commonStaticConfig.setContextName(siteID) file = pathMgr.getFile(commonStaticConfig, "gfe/editAreas" + File.separator + name + ".xml") file.delete()
def _getFileContents(self, loctype, loclevel, locname, filename): pathManager = PathManagerFactory.getPathManager() context = pathManager.getContext(loctype, loclevel) context.setContextName(locname) localizationFile = pathManager.getLocalizationFile(context, filename) with File(localizationFile.getFile(), filename, 'r') as pythonFile: fileContents = pythonFile.read() return fileContents
def saveEditAreaGrid(maskName, iscMask, siteID): iscMask.getPolygons(CoordinateType.LATLON); pathMgr = PathManagerFactory.getPathManager(); commonStaticConfig = pathMgr.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.CONFIGURED) commonStaticConfig.setContextName(siteID) sitePath = pathMgr.getFile(commonStaticConfig,"gfe/editAreas").getPath() editAreaPath = str(sitePath) + "/" + maskName + ".xml" SerializationUtil.jaxbMarshalToXmlFile(iscMask, editAreaPath)
def saveEditAreaGrid(maskName, iscMask, siteID): iscMask.getPolygons(CoordinateType.LATLON) pathMgr = PathManagerFactory.getPathManager() commonStaticConfig = pathMgr.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.CONFIGURED) commonStaticConfig.setContextName(siteID) sitePath = pathMgr.getFile(commonStaticConfig, "gfe/editAreas").getPath() editAreaPath = str(sitePath) + "/" + maskName + ".xml" ReferenceData.getJAXBManager().marshalToXmlFile(iscMask, editAreaPath)
def __getTemplateFiles(self, srcDir): """Get a list of all template files @return: a list of all template files @rtype: list """ pathMgr = PathManagerFactory.getPathManager() edexStaticBase = pathMgr.getContext(LocalizationType.EDEX_STATIC, LocalizationLevel.BASE) templateFiles = pathMgr.listFiles(edexStaticBase, srcDir, None, False, True) return templateFiles
def __init__(self, activeTableMode, logger=None): self._time = time.time() self._logger = logger # create a dummy name to simplify the file access code in VTECTableUtil pathMgr = PathManagerFactory.getPathManager() siteCx = pathMgr.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.SITE) filePath = pathMgr.getFile(siteCx, "vtec").getPath() VTECTableUtil.VTECTableUtil.__init__( self, os.path.join(filePath, activeTableMode + ".tbl"))
def getWclDir(self): # get the path manager from com.raytheon.uf.common.localization import PathManagerFactory pathManager = PathManagerFactory.getPathManager() # get the proper localization context from com.raytheon.uf.common.localization import LocalizationContext from com.raytheon.uf.common.localization import LocalizationContext_LocalizationType as LocalizationType CAVE_STATIC = LocalizationType.valueOf("CAVE_STATIC") from com.raytheon.uf.common.localization import LocalizationContext_LocalizationLevel as LocalizationLevel SITE = LocalizationLevel.valueOf("SITE") ctx = pathManager.getContext(CAVE_STATIC, SITE) # use localization to get the full path wclName = os.path.join("gfe", "wcl") wclDir = pathManager.getFile(ctx, wclName) return wclDir.getAbsolutePath()
def getWclDir(self): # get the path manager from com.raytheon.uf.common.localization import PathManagerFactory pathManager = PathManagerFactory.getPathManager() # get the proper localization context from com.raytheon.uf.common.localization import LocalizationContext LocalizationType = LocalizationContext.LocalizationType CAVE_STATIC = LocalizationType.valueOf("CAVE_STATIC") LocalizationLevel = LocalizationContext.LocalizationLevel SITE = LocalizationLevel.valueOf("SITE") ctx = pathManager.getContext(CAVE_STATIC, SITE) # use localization to get the full path wclName = os.path.join("gfe", "wcl") wclDir = pathManager.getFile(ctx, wclName) return wclDir.getAbsolutePath()
def getISCSites(): import glob, os.path from com.raytheon.uf.common.localization import PathManagerFactory from com.raytheon.uf.common.localization import LocalizationContext from com.raytheon.uf.common.localization import LocalizationContext_LocalizationType as LocalizationType from com.raytheon.uf.common.localization import LocalizationContext_LocalizationLevel as LocalizationLevel pathMgr = PathManagerFactory.getPathManager() commonStaticSite = pathMgr.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.SITE) commonStaticSite.setContextName(siteConfig.GFESUITE_SITEID) eaDir = pathMgr.getFile(commonStaticSite, "gfe/editAreas").getCanonicalPath() files = glob.glob(eaDir + "/ISC_???.xml") sites = [] WFOSites = BackupDict.keys() for f in files: fb = os.path.basename(f) if len(fb) == 11 and fb[0:4] == "ISC_": site = fb[4:7] #ensure it is a known WFO site if site in WFOSites: sites.append(site) #remove our own site if siteConfig.GFESUITE_SITEID in sites: del sites[sites.index(siteConfig.GFESUITE_SITEID)] return sites
def getEditArea(name, siteID): pathMgr = PathManagerFactory.getPathManager(); commonStaticConfig = pathMgr.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.SITE) commonStaticConfig.setContextName(siteID) file = pathMgr.getFile(commonStaticConfig,"gfe/editAreas"+ File.separator + name + ".xml") if not os.path.exists(file.getPath()): commonStaticConfig = pathMgr.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.CONFIGURED) commonStaticConfig.setContextName(siteID) file = pathMgr.getFile(commonStaticConfig,"gfe/editAreas"+ File.separator + name + ".xml") refData = None try: if os.path.exists(file.getPath()): refData = SerializationUtil.jaxbUnmarshalFromXmlFile(file.getPath()); else: LogStream.logProblem("EDIT AREA NOT FOUND: ",name," for site ",siteID) except: LogStream.logProblem("Unable to unmarshal " + name + " in iscExtract") return refData
def getLocalizationFile(loctype, loclevel, contextname, filename): pathManager = PathManagerFactory.getPathManager() context = pathManager.getContext(loctype, loclevel) context.setContextName(contextname) localizationFile = pathManager.getLocalizationFile(context, filename) return localizationFile
def __init__(self, activeTable, activeTableMode, newRecords, offsetSecs=0.0, makeBackups=True, logger=None): # activeTable - current activeTable records # activeTableMode - which table is being modified--OPERATIONAL or PRACTICE # newRecords - records to merge in to activeTable # inputIsGZIP (0,1) - remote input file is gzipped # offsetSecs - Number of seconds +/- current time # makeBackups (False, True) - make backups of previous table # logger - python logging object to send all logs to if logger is not None: self._log = logger else: self._log = self.__initLogging() # create a dummy name to simplify the file access code in VTECTableUtil pathMgr = PathManagerFactory.getPathManager() commonSiteCx = pathMgr.getContextForSite( LocalizationType.COMMON_STATIC, siteConfig.GFESUITE_SITEID) filePath = pathMgr.getFile(commonSiteCx,"vtec").getPath() self._activeTableFilename = os.path.join(filePath, activeTableMode + ".tbl") # to ensure time calls are based on Zulu os.environ['TZ'] = "GMT0" self._time = time.time() + offsetSecs #present time self._makeBackups = makeBackups VTECTableUtil.VTECTableUtil.__init__(self, self._activeTableFilename) # get the SPC site id from the configuration file self._spcSite = getattr(VTECPartners, "VTEC_SPC_SITE", "KWNS") self._tpcSite = getattr(VTECPartners, "VTEC_TPC_SITE", "KNHC") # get our site siteid = siteConfig.GFESUITE_SITEID self._ourSite = self._get4ID(siteid) self._siteFilter = self._getFilterSites() self._log.info("MergeVTEC Starting") self._log.info("localFN= " + self._activeTableFilename + " sites= " + repr(self._siteFilter)) #read table to merge otherTable = newRecords self._log.info("Remote Table size: %d", len(otherTable)) #read active table self._log.info("Active Table size: %d", len(activeTable)) #save a copy for later backup purposes oldActiveTable = copy.deepcopy(activeTable) #delete "obsolete" records from our table and the other table vts = VTECTableSqueeze.VTECTableSqueeze(self._time) activeTable, tossRecords = vts.squeeze(activeTable) self._log.info("Active Table squeezed size: %d", len(activeTable)) self._log.info("Other Table size: %d", len(otherTable)) otherTable, tossRecordsOther = vts.squeeze(otherTable) self._log.info("Other Table squeezed size: %d", len(otherTable)) #merge the tables updatedTable, toDelete, changes = self._mergeTable(activeTable, otherTable) self._log.info("Updated Active Table size: %d", len(updatedTable)) updatedTable, tossRecordsMerged = vts.squeeze(updatedTable) self._log.info("Updated Active Table squeeze size: %d", len(updatedTable)) del vts self._updatedTable = [] self._purgedTable = [] self._changes = [] #notify the ifpServer of changes, save a backup copy if tossRecords or tossRecordsMerged or changes: self._log.debug("#tossRecords: %d", len(tossRecords)) self._log.debug("#tossRecordsMerged: %d", len(tossRecordsMerged)) self._log.debug("#changes: %d", len(changes)) # save lists for later retrieval self._updatedTable = updatedTable self._purgedTable.extend(tossRecords) self._purgedTable.extend(toDelete) self._purgedTable.extend([rec for rec in tossRecordsMerged if rec in oldActiveTable]) self._changes = changes #save backup copy if self._makeBackups: oldActiveTable = self._convertTableToPurePython(oldActiveTable, siteid) self.saveOldActiveTable(oldActiveTable) pTime = getattr(VTECPartners, "VTEC_BACKUP_TABLE_PURGE_TIME", 168) self.purgeOldSavedTables(pTime) self._log.info("MergeVTEC Finished")
FILEMODE = 'w' PATH_MGR = None try: logging.basicConfig(level=logging.INFO) logger = logging.getLogger("FormatterRunner") formatter = logging.Formatter( "%(asctime)s:%(name)s:%(levelname)s:%(message)s") # Get the information for the file logger from com.raytheon.uf.common.localization import PathManagerFactory from com.raytheon.uf.common.localization import LocalizationContext LocalizationType = LocalizationContext.LocalizationType LocalizationLevel = LocalizationContext.LocalizationLevel PATH_MGR = PathManagerFactory.getPathManager() except: logging.basicConfig(filename=DEFAULT_LOG_FILENAME, level=logging.DEBUG) logger = logging.getLogger() logger.exception("Exception occurred") ## TODO: Remove use of DataManager in this code. Will need to coordinate with ## the field developers to ensure local site overrides aren't relying on having ## access to it. def executeFromJava(databaseID, site, username, dataMgr, forecastList, logFile,
CATEGORY = 'GFE' DEFAULT_LOG_FILENAME = '/tmp/gfe.log' FILEMODE='w' PATH_MGR = None try: logging.basicConfig(level=logging.INFO) logger = logging.getLogger("FormatterRunner") formatter = logging.Formatter("%(asctime)s:%(name)s:%(levelname)s:%(message)s") # Get the information for the file logger from com.raytheon.uf.common.localization import PathManagerFactory from com.raytheon.uf.common.localization import LocalizationContext_LocalizationType as LocalizationType, LocalizationContext_LocalizationLevel as LocalizationLevel PATH_MGR = PathManagerFactory.getPathManager() except: logging.basicConfig(filename=DEFAULT_LOG_FILENAME,level=logging.DEBUG) logger = logging.getLogger() logger.exception("Exception occurred") def executeFromJava(databaseID, site, username, dataMgr, forecastList, logFile, cmdLineVarDict=None, drtTime=None, vtecMode=None, vtecActiveTable="active", testMode=0 ): if type(forecastList) is not list: forecastList = [str(forecastList)] # Set up the file logger for this product # ctx = PATH_MGR.getContext(LocalizationType.valueOf('CAVE_STATIC'), LocalizationLevel.valueOf('USER')) # logFile = PATH_MGR.getFile(ctx, os.path.join('gfe', 'logs', forecastList[0])).getPath() logger.info("logFile: " + str(logFile)) fh = logging.FileHandler(filename=logFile, mode=FILEMODE)
import time, os, os.path, sys, subprocess, select, errno import logging, UFStatusHandler from com.raytheon.uf.common.dissemination import OUPResponse _Logger = logging.getLogger("HandleOUP") _Logger.addHandler(UFStatusHandler.UFStatusHandler("com.raytheon.uf.edex.dissemination", "HandleOUP", level=logging.INFO)) _Logger.setLevel(logging.INFO) DB_SUCCESS = 0; DB_FAILURE = 1; DB_TIMEOUT = 2; DB_DUPLICATE = 4; ACTION_CODES = {} from com.raytheon.uf.common.localization import PathManagerFactory from com.raytheon.uf.common.localization import LocalizationContext_LocalizationType as LocalizationType, LocalizationContext_LocalizationLevel as LocalizationLevel pathMgr = PathManagerFactory.getPathManager() ctx = pathMgr.getContext(LocalizationType.valueOf('EDEX_STATIC'), LocalizationLevel.valueOf('BASE')) DPATH = pathMgr.getFile(ctx, 'dissemination').getPath() f = open(DPATH + '/rcv_action2codes.txt') for line in f: codeSplit = line.split() ACTION_CODES[codeSplit[0]] = codeSplit[1] f.close() from com.raytheon.uf.edex.core.props import PropertiesFactory env = PropertiesFactory.getInstance().getEnvProperties() dataDir = env.getEnvValue("DEFAULTDATADIR") OUT_DIR = dataDir + 'outgoing' if not os.path.isdir(OUT_DIR): os.mkdir(OUT_DIR) INGEST_DIR = dataDir + 'manual'
def __init__(self): self.pathManager = PathManagerFactory.getPathManager() self.localizationType = LocalizationContext.LocalizationType.COMMON_STATIC self.functionsDir = DerivedParameterGenerator.FUNCTIONS_DIR
def __init__(self): self.jpathManager = PathManagerFactory.getPathManager()
import itertools, logging, math, os, sets, time import ConfigParser import numpy, pupynere import Avn, AvnLib, AvnParser, Globals, MetarMonitor import UFStatusHandler _Logger = logging.getLogger(Avn.CATEGORY) _MetarMonitorDict = None ConfigDir = 'etc' try: from com.raytheon.uf.common.localization import PathManagerFactory from com.raytheon.uf.common.localization import LocalizationContext LocalizationType = LocalizationContext.LocalizationType LocalizationLevel = LocalizationContext.LocalizationLevel pathMgr = PathManagerFactory.getPathManager() ctx = pathMgr.getContext(LocalizationType.valueOf('CAVE_STATIC'), LocalizationLevel.valueOf('BASE')) ConfigDir = pathMgr.getFile(ctx, os.path.join('aviation', 'config')).getPath() except: _Logger.exception("Error determining AvnFPS config directory") pass ############################################################################### # weather check def curWx(tafs, items): result = {} for taf in tafs:
def deleteEditArea(name, siteID): pathMgr = PathManagerFactory.getPathManager() commonStaticConfig = pathMgr.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.CONFIGURED) commonStaticConfig.setContextName(siteID) file = pathMgr.getFile(commonStaticConfig,"gfe/editAreas"+ File.separator + name + ".xml") file.delete()
def __init__(self, activeTable, activeTableMode, newRecords, offsetSecs=0.0, makeBackups=True, logger=None, atChangeLog=None): # activeTable - current activeTable records # activeTableMode - which table is being modified--OPERATIONAL or PRACTICE # newRecords - records to merge in to activeTable # inputIsGZIP (0,1) - remote input file is gzipped # offsetSecs - Number of seconds +/- current time # makeBackups (False, True) - make backups of previous table # logger - python logging object to send all logs to if logger is not None: self._log = logger else: self._log = self.__initLogging() # create a dummy name to simplify the file access code in VTECTableUtil pathMgr = PathManagerFactory.getPathManager() edexSiteCx = pathMgr.getContextForSite(LocalizationType.EDEX_STATIC, siteConfig.GFESUITE_SITEID) filePath = pathMgr.getFile(edexSiteCx, "vtec").getPath() fileName = os.path.join(filePath, activeTableMode + ".tbl") # to ensure time calls are based on Zulu os.environ['TZ'] = "GMT0" self._time = time.time() + offsetSecs #present time self._makeBackups = makeBackups VTECTableUtil.VTECTableUtil.__init__(self, fileName) # get the SPC site id from the configuration file self._spcSite = JUtil.javaObjToPyVal( JavaVTECPartners.getInstance( siteConfig.GFESUITE_SITEID).getSpcSites("KWNS")) self._tpcSite = JUtil.javaObjToPyVal( JavaVTECPartners.getInstance( siteConfig.GFESUITE_SITEID).getTpcSites("KNHC")) # get our site siteid = siteConfig.GFESUITE_SITEID self._ourSite = self._get4ID(siteid) self._siteFilter = self._getFilterSites() self._log.info("MergeVTEC Starting") self._log.info("localFN= " + self._activeTableFilename + " sites= " + repr(self._siteFilter)) #read table to merge otherTable = newRecords self._log.info("Remote Table size: %d", len(otherTable)) #read active table self._log.info("Active Table size: %d", len(activeTable)) #save a copy for later backup purposes oldActiveTable = copy.deepcopy(activeTable) #delete "obsolete" records from our table and the other table vts = VTECTableSqueeze.VTECTableSqueeze(self._time) activeTable, tossRecords = vts.squeeze(activeTable) self._log.info("Active Table squeezed size: %d", len(activeTable)) self._log.info("Other Table size: %d", len(otherTable)) otherTable, tossRecordsOther = vts.squeeze(otherTable) self._log.info("Other Table squeezed size: %d", len(otherTable)) #merge the tables updatedTable, toDelete, changes = self._mergeTable( activeTable, otherTable, atChangeLog) self._log.info("Updated Active Table size: %d", len(updatedTable)) updatedTable, tossRecordsMerged = vts.squeeze(updatedTable) self._log.info("Updated Active Table squeeze size: %d", len(updatedTable)) del vts self._updatedTable = [] self._purgedTable = [] self._changes = [] #notify the ifpServer of changes, save a backup copy if tossRecords or tossRecordsMerged or changes: self._log.debug("#tossRecords: %d", len(tossRecords)) self._log.debug("#tossRecordsMerged: %d", len(tossRecordsMerged)) self._log.debug("#changes: %d", len(changes)) # save lists for later retrieval self._updatedTable = updatedTable self._purgedTable.extend(tossRecords) self._purgedTable.extend(toDelete) self._purgedTable.extend( [rec for rec in tossRecordsMerged if rec in oldActiveTable]) self._changes = changes #save backup copy if self._makeBackups: oldActiveTable = self._convertTableToPurePython( oldActiveTable, siteid) self.saveOldActiveTable(oldActiveTable) pTime = getattr(VTECPartners, "VTEC_BACKUP_TABLE_PURGE_TIME", 168) self.purgeOldSavedTables(pTime) self._log.info("MergeVTEC Finished")