本文整理汇总了Python中pxStats.lib.LanguageTools.LanguageTools.getMainApplicationLanguage方法的典型用法代码示例。如果您正苦于以下问题:Python LanguageTools.getMainApplicationLanguage方法的具体用法?Python LanguageTools.getMainApplicationLanguage怎么用?Python LanguageTools.getMainApplicationLanguage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pxStats.lib.LanguageTools.LanguageTools
的用法示例。
在下文中一共展示了LanguageTools.getMainApplicationLanguage方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addOptions
# 需要导入模块: from pxStats.lib.LanguageTools import LanguageTools [as 别名]
# 或者: from pxStats.lib.LanguageTools.LanguageTools import getMainApplicationLanguage [as 别名]
def addOptions( parser ):
"""
@summary : This method is used to add all available options to the option parser.
"""
parser.add_option("-c", "--combine", action="store_true", dest = "combine", default=False, \
help=_("Combine data from all specified machines.") )
parser.add_option("-d", "--date", action="store", type="string", dest="date", default=StatsDateLib.getIsoFromEpoch( time.time() ),\
help=_("Decide current time. Usefull for testing.") )
parser.add_option("-i", "--individual", action="store_true", dest = "individual", default=False, \
help=_("Create individual graphics for all specified machines.") )
parser.add_option( "-l", "--logins", action="store", type="string", dest="logins", default="pds",\
help = _("Logins to be used to connect to machines.") )
parser.add_option( "-m", "--machines", action="store", type="string", dest="machines", default=LOCAL_MACHINE,\
help = _("Machines for wich you want to collect data.") )
parser.add_option("-o", "--outputLanguage", action="store", type="string", dest="outputLanguage",\
default=LanguageTools.getMainApplicationLanguage(), help = _("Language in which the graphics are outputted.") )
parser.add_option("-s", "--span", action="store",type ="int", dest = "timespan", default=24, \
help=_("timespan( in hours) of the graphic."))
示例2: prepareQuery
# 需要导入模块: from pxStats.lib.LanguageTools import LanguageTools [as 别名]
# 或者: from pxStats.lib.LanguageTools.LanguageTools import getMainApplicationLanguage [as 别名]
def prepareQuery(self):
"""
@summary : Buildup the query to be executed.
@SIDE_EFFECT : modifies self.query value.
"""
global _
if self.queryParameters.combine == 'true':
totals = True
mergerType = "regular"
else:
totals = False
mergerType = ""
fixedCurrent = False
fixedPrevious = False
if _("current") in str(self.queryParameters.fixedSpan).lower() :
fixedCurrent = True
elif _("previous") in str(self.queryParameters.fixedSpan).lower():
fixedPrevious = True
else:
fixedCurrent = False
fixedPrevious = False
hour = self.queryParameters.endTime.split(" ")[1]
splitDate = self.queryParameters.endTime.split(" ")[0].split( '-' )
date = splitDate[2] + '-' + splitDate[1] + '-' + splitDate[0] + " " + hour
if self.queryParameters.span == "":
timespan = 0
else:
timespan = int(self.queryParameters.span )
StatsDateLib.setLanguage( self.querierLanguage )
startTime, endTime = StatsDateLib.getStartEndInIsoFormat(date, timespan, self.queryParameters.specificSpan, fixedCurrent, fixedPrevious )
timespan = int( StatsDateLib.getSecondsSinceEpoch( endTime ) - StatsDateLib.getSecondsSinceEpoch( startTime ) ) / 3600
combinedMachineName = ""
for machine in self.queryParameters.machines:
combinedMachineName = combinedMachineName + machine
machines = [ combinedMachineName ]
self.graphicProducer = RRDGraphicProducer( self.queryParameters.fileTypes[0], self.queryParameters.statsTypes ,\
totals, self.queryParameters.specificSpan,\
self.queryParameters.sourLients, timespan,\
startTime, endTime, machines, False,
mergerType, True, self.querierLanguage, self.querierLanguage )
StatsDateLib.setLanguage( LanguageTools.getMainApplicationLanguage() )
示例3: __init__
# 需要导入模块: from pxStats.lib.LanguageTools import LanguageTools [as 别名]
# 或者: from pxStats.lib.LanguageTools.LanguageTools import getMainApplicationLanguage [as 别名]
def __init__( self, languages = None ):
"""
@param languages: list of languages
for which to generate
the doc web pages.
"""
global _
self.mainLanguage = LanguageTools.getMainApplicationLanguage()
self.languages = languages or LanguageTools.getSupportedLanguages()
示例4: buildCsvFileName
# 需要导入模块: from pxStats.lib.LanguageTools import LanguageTools [as 别名]
# 或者: from pxStats.lib.LanguageTools.LanguageTools import getMainApplicationLanguage [as 别名]
def buildCsvFileName( infos ):
"""
@summary: Builds and returns the file name to use for the csv file.
@param infos: _CvsInfos instance containing the required
information to build up the file name.
@return: Return the built up file name.
"""
global _
StatsDateLib.setLanguage(infos.outputLanguage)
paths = StatsPaths()
paths.setPaths( infos.outputLanguage )
machinesStr = str(infos.machinesForLabels).replace('[','').replace( ']','' ).replace(',', '').replace("'","").replace( '"','').replace( ' ','' )
currentYear, currentMonth, currentDay = StatsDateLib.getYearMonthDayInStrfTime( StatsDateLib.getSecondsSinceEpoch (infos.start) )
currentWeek = time.strftime( "%W", time.gmtime( StatsDateLib.getSecondsSinceEpoch (infos.start) ) )
fileName = paths.STATSCSVFILES
if infos.span == "daily":
fileName = fileName + "/" + _("daily/") + infos.fileType + "/%s/%s/%s/%s.csv" %( machinesStr, currentYear, currentMonth, currentDay )
elif infos.span == "weekly":
fileName = fileName + "/" + _("weekly/") + infos.fileType + "/%s/%s/%s.csv" %( machinesStr, currentYear, currentWeek )
elif infos.span == "monthly":
fileName = fileName + "/" + _("monthly/") + infos.fileType + "/%s/%s/%s.csv" %( machinesStr, currentYear, currentMonth )
elif infos.span == "yearly":
fileName = fileName + "/" + _("yearly/") + infos.fileType + "/%s/%s.csv" %( machinesStr, currentYear )
StatsDateLib.setLanguage( LanguageTools.getMainApplicationLanguage() )
return fileName
示例5: getImagesLangFromForm
# 需要导入模块: from pxStats.lib.LanguageTools import LanguageTools [as 别名]
# 或者: from pxStats.lib.LanguageTools.LanguageTools import getMainApplicationLanguage [as 别名]
def getImagesLangFromForm():
"""
@summary : Parses form with whom this program was called.
@return: Returns the images and language found within the form.
"""
lang = LanguageTools.getMainApplicationLanguage()
images = []
newForm = {}
form = cgi.FieldStorage()
for key in form.keys():
value = form.getvalue(key, "")
if isinstance(value, list):
newvalue = ",".join(value)
else:
newvalue = value
newForm[key.replace("?","")]= newvalue
try:
images = newForm["images"]
images = images.split(';')
except:
pass
try:
lang = newForm["lang"]
except:
pass
return images, lang
示例6: addOptions
# 需要导入模块: from pxStats.lib.LanguageTools import LanguageTools [as 别名]
# 或者: from pxStats.lib.LanguageTools.LanguageTools import getMainApplicationLanguage [as 别名]
def addOptions( parser ):
"""
@summary : This method is used to add all available options to the option parser.
"""
parser.add_option("-c", "--clients", action="store", type="string", dest="clients", default="",
help=_("Clients' names") )
parser.add_option( "--copy", action="store_true", dest = "copy", default=False, help=_("Create a copy file for the generated image.") )
parser.add_option( "--combineClients", action="store_true", dest = "combineClients", default=False, \
help=_("Combine the data of all client into a single graphics for each graphic type.") )
parser.add_option("-d", "--date", action="store", type="string", dest="currentTime", \
default=StatsDateLib.getIsoFromEpoch( time.time() ), help=_("Decide current time. Usefull for testing.") )
parser.add_option("-f", "--fileType", action="store", type="string", dest="fileType", default='tx',\
help=_("Type of log files wanted.") )
parser.add_option( "-g", "--groupName", action="store", type="string", dest="groupName", default="",
help=_("Specify a name for the combined graphics of numerous client/sources. Note : requires the --combinedClients options to work." ) )
parser.add_option( "-m", "--machines", action="store", type="string", dest="machines", default=LOCAL_MACHINE,\
help = _("Machines for wich you want to collect data.") )
parser.add_option("-n", "--collectUpToNow", action="store_true", dest = "collectUpToNow", default=False, \
help=_("Collect data up to current second.") )
parser.add_option("-o", "--outputLanguage", action="store", type="string", dest="outputLanguage",\
default=LanguageTools.getMainApplicationLanguage(), help = _("Language in which the graphics are outputted.") )
parser.add_option("-p", "--products", action="store", type = "string", dest = "productTypes", default=_("All"), \
help=_("Specific product types to look for in the data collected.") )
parser.add_option("-s", "--span", action="store",type ="int", dest = "timespan", default=12, help=_("timespan( in hours) of the graphic.") )
parser.add_option("-t", "--types", type="string", dest="types", default=_("All"),help=_("Types of data to look for.") )
示例7: main
# 需要导入模块: from pxStats.lib.LanguageTools import LanguageTools [as 别名]
# 或者: from pxStats.lib.LanguageTools.LanguageTools import getMainApplicationLanguage [as 别名]
def main():
"""
Generates the web page based on the received
machines and file type parameters.
"""
error = ""
form = getForm()
# print form
try:
wordType = form["wordType"]
if wordType != "products" and wordType != "groupName":
error = "Error. Word type needs to be either products or groupName."
except:
wordType = ""
try:
language = form["lang"]
if language not in LanguageTools.getSupportedLanguages():
raise
except:
language = LanguageTools.getMainApplicationLanguage()
try:
word = form["word"]
word = word.replace(" ", "")
except:
error = "Error. Word needs to be specified."
word = ""
if word != "":
updateWordsFromDB(wordType, word, language)
returnReply(error)
示例8: getGraphicProducerFromParserOptions
# 需要导入模块: from pxStats.lib.LanguageTools import LanguageTools [as 别名]
# 或者: from pxStats.lib.LanguageTools.LanguageTools import getMainApplicationLanguage [as 别名]
def getGraphicProducerFromParserOptions( parser ):
"""
This method parses the argv received when the program was called
It takes the params wich have been passed by the user and sets them
in the corresponding fields of the infos variable.
If errors are encountered in parameters used, it will immediatly terminate
the application.
"""
graphicType = _("other")
mergerType = ""
( options, args )= parser.parse_args()
timespan = options.timespan
machines = options.machines.replace( ' ','').split(',')
clientNames = options.clients.replace( ' ','' ).split(',')
types = options.types.replace( ' ', '').split(',')
date = options.date.replace('"','').replace("'",'')
fileType = options.fileType.replace("'",'')
havingRun = options.havingRun
individual = options.individual
totals = options.totals
daily = options.daily
weekly = options.weekly
monthly = options.monthly
yearly = options.yearly
fixedCurrent = options.fixedCurrent
fixedPrevious = options.fixedPrevious
copy = options.copy
turnOffLogging = options.turnOffLogging
outputLanguage = options.outputLanguage
if outputLanguage == "":
outputLanguage = LanguageTools.getMainApplicationLanguage()
else :
if outputLanguage not in LanguageTools.getSupportedLanguages():
print _("Error. The specified language is not currently supported by this application.")
print _("Please specify one of the following languages %s or use the default value()" %( str( LanguageTools.getSupportedLanguages() ).replace("[","").replace("]",""), LanguageTools.getMainApplicationLanguage() ) )
print _("Program terminated.")
sys.exit()
counter = 0
specialParameters = [daily, monthly, weekly, yearly]
for specialParameter in specialParameters:
if specialParameter:
counter = counter + 1
if counter > 1 :
print _("Error. Only one of the daily, weekly and yearly options can be use at a time ")
print _("Use -h for help.")
print _("Program terminated.")
sys.exit()
elif counter == 1 and timespan != None :
print _("Error. When using the daily, the weekly or the yearly options timespan cannot be specified. " )
print _("Use -h for help.")
print _("Program terminated.")
sys.exit()
elif counter == 0:
if fixedPrevious or fixedCurrent:
print _("Error. When using one of the fixed options, please use either the -d -m -w or -y options. " )
print _("Use -h for help.")
print _("Program terminated.")
sys.exit()
if copy :
if daily or not( weekly or monthly or yearly ):
print _("Error. Copying can only be used with the -m -w or -y options. ")
print _("Use -h for help.")
print _("Program terminated.")
if counter == 0 and timespan == None :
timespan = 12
if fixedPrevious and fixedCurrent:
print _("Error. Please use only one of the fixed options,either fixedPrevious or fixedCurrent. ")
print _("Use -h for help.")
print _("Program terminated.")
sys.exit()
if individual and totals:
print _("Error. Please use only one of the group options,either individual or totals. ")
print _("Use -h for help.")
print _("Program terminated.")
sys.exit()
try: # Makes sure date is of valid format.
# Makes sure only one space is kept between date and hour.
t = time.strptime( date, '%Y-%m-%d %H:%M:%S' )
split = date.split()
date = "%s %s" %( split[0], split[1] )
except:
print _("Error. The date format must be YYYY-MM-DD HH:MM:SS")
#.........这里部分代码省略.........
示例9: StatsPaths
# 需要导入模块: from pxStats.lib.LanguageTools import LanguageTools [as 别名]
# 或者: from pxStats.lib.LanguageTools.LanguageTools import getMainApplicationLanguage [as 别名]
"""
sys.path.insert(1, os.path.dirname( os.path.abspath(__file__) ) + '/../../')
from pxStats.lib.StatsDateLib import StatsDateLib
from pxStats.lib.RrdUtilities import RrdUtilities
from pxStats.lib.GeneralStatsLibraryMethods import GeneralStatsLibraryMethods
from pxStats.lib.StatsPaths import StatsPaths
from pxStats.lib.LanguageTools import LanguageTools
from pxStats.lib.RRDGraphicProducer import RRDGraphicProducer
"""
- Small function that adds pxLib to sys path.
"""
STATSPATHS = StatsPaths( )
STATSPATHS.setPaths( LanguageTools.getMainApplicationLanguage() )
sys.path.append( STATSPATHS.PXLIB )
# These Imports require pxlib
from PXManager import *
from Logger import *
LOCAL_MACHINE = os.uname()[1]
CURRENT_MODULE_ABS_PATH = os.path.abspath(__file__).replace( ".pyc", ".py" )
def getGraphicProducerFromParserOptions( parser ):
"""
This method parses the argv received when the program was called
示例10: printWebPage
# 需要导入模块: from pxStats.lib.LanguageTools import LanguageTools [as 别名]
# 或者: from pxStats.lib.LanguageTools.LanguageTools import getMainApplicationLanguage [as 别名]
def printWebPage( self ):
"""
@summary : prints out the entire bottom web page
@precondition: Requires _ translator to have been set prior to calling this function.
"""
global _
paths = StatsPaths()
paths.setPaths( LanguageTools.getMainApplicationLanguage() )
fileName = paths.STATSWEBPAGES + "bottom.html"
fileHandle = open( fileName, "w" )
fileHandle.write("""
<html>
<head>
""")
self.__printJavaScript(fileHandle)
fileHandle.write("""
</head>
""")
fileHandle.write("""
<body bgcolor="#FFD684">
<div style="position:absolute;top:20%%;vertical-align: middle;text-align:center;left:15%%;bottom:0%%;">
<img name="logo" id="logo" src="images/mainLogo_%s.gif" ></img>
</div>
""" %self.mainLanguage)
fileHandle.write( """
<div name="linksSection" id="linksSection" style="position:absolute;top:67%;vertical-align: middle;text-align:center;left:45%;bottom:0%;">
""")
for i in range( len( self.otherLanguages ) ):
_ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, self.otherLanguages[i] )
try:
fileHandle.write("""<a href="top_%s.html" target="top" onclick="JavaScript:%sVersionWasClicked()">"""%( self.otherLanguages[i],self.otherLanguages[i]) + _("English version.")+ """</a>""")
except:
print _( "Error.Unsupported language detected." )
print _( "Make sure %s is a supported language") %( self.otherLanguages[i] )
print _( "Program terminated")
sys.exit()
if i != len(self.otherLanguages)-1 :
fileHandle.write( "<br>" )
fileHandle.write( """
</div>
</body>
</html>
""")
fileHandle.close()
示例11: createSymbolicLinks
# 需要导入模块: from pxStats.lib.LanguageTools import LanguageTools [as 别名]
# 或者: from pxStats.lib.LanguageTools.LanguageTools import getMainApplicationLanguage [as 别名]
def createSymbolicLinks( path, currentlyUsedLanguages ):
"""
@summary : create symbolic links from web-interface to general
pxStats package.
This will prevent us from having to sync both
sides all the time. i.e updating pxStats
( via svn update for example) will update both
the web interface and the source files at the
same time.
@param path : Paths in which we are installing
the web interface.
@param currentlyUsedLanguages: Languages currently set to be
displayed in the web interface
@precondition : copyFiles method MUST have been called
prior to calling this method.
"""
statsPaths = StatsPaths()
#Links to files in the main application language.
statsPaths.setPaths( LanguageTools.getMainApplicationLanguage() )
#index.html
commands.getstatusoutput( "ln -s %s/index.html %s/index.html" %( statsPaths.STATSWEBPAGES, path ) )
#print "ln -s %s/index.html %s/index.html" %( statsPaths.STATSWEBPAGES, path )
# .../path/bottom.html Only on, multilingual fomr of this file exists.
commands.getstatusoutput( "ln -s %s/bottom.html %s/bottom.html" %(statsPaths.STATSWEBPAGES , path ) )
#print "ln -s %s/bottom.html %s/bottom.html" %(statsPaths.STATSWEBPAGES , path )
# .../path/bottom.html Only on, multilingual fomr of this file exists.
commands.getstatusoutput( "ln -s %s/top_%s.html %s/top.html" %(statsPaths.STATSWEBPAGES , LanguageTools.getMainApplicationLanguage(), path ) )
#print "ln -s %s/bottom.html %s/bottom.html" %(statsPaths.STATSWEBPAGES , path )
# .../path/pxStats
commands.getstatusoutput( "ln -s %s %s/pxStats" %( statsPaths.STATSROOT, path ) )
#print "ln -s %s %s/pxStats" %( statsPaths.STATSROOT, path )
#.../path/images
commands.getstatusoutput( "ln -s %s/images %s/images" %( statsPaths.STATSWEBPAGES, path ) )
#print "ln -s %s/images %s/images" %( statsPaths.STATSWEBPAGES, path )
#.../path/scripts/cgi-bin
commands.getstatusoutput( "ln -s %s %s/scripts/cgi-bin "%( statsPaths.STATSWEBPAGESGENERATORS, path ) )
#print "ln -s %s %s/scripts/cgi-bin "%( statsPaths.STATSWEBPAGESGENERATORS, path )
for language in currentlyUsedLanguages:
statsPaths.setPaths( language )
# .../path/html_lang
commands.getstatusoutput( "ln -s %s/html %s/html_%s" %( statsPaths.STATSWEBPAGES, path, language ) )
#print "ln -s %s/html %s/html_%s" %( statsPaths.STATSWEBPAGES, path, language )
# .../path/archives_lang
commands.getstatusoutput( "ln -s %s %s/archives_%s" %( statsPaths.STATSGRAPHSARCHIVES[:-1], path, language ) )
#print "ln -s %s %s/archives_%s" %( statsPaths.STATSGRAPHSARCHIVES[:-1], path, language )
# .../paths/html_lang/archives
commands.getstatusoutput( "ln -s %s %s/html_%s/archives" %( statsPaths.STATSGRAPHSARCHIVES[:-1], path, language ) )
#print "ln -s %s %s/html_%s/archives" %( statsPaths.STATSGRAPHSARCHIVES[:-1], path, language )
#.../paths/html_lang/csvFiles
commands.getstatusoutput( "ln -s %s %s/html_%s/%s" %( statsPaths.STATSCSVFILES[:-1], path, language, os.path.basename( statsPaths.STATSCSVFILES ) ) )
# .../path/top_lang.html
commands.getstatusoutput( "ln -s %s/top_%s.html %s/top_%s.html" %( statsPaths.STATSWEBPAGES, language, path, language ) )
#print "ln -s %s/top_%s.html %s/top_%s.html" %( statsPaths.STATSWEBPAGES, language, path, language )
#.../path/scripts/js_lang
commands.getstatusoutput( "ln -s %s/js %s/scripts/js_%s " %( statsPaths.STATSWEBPAGES, path, language ) )
#print "ln -s %s/js %s/scripts/js_%s " %( statsPaths.STATSWEBPAGES, path, language )
commands.getstatusoutput( "ln -s %s/html/howTo_%s.html %s/html_%s/docPages/links/howTo_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
commands.getstatusoutput( "ln -s %s/html/installation_%s.html %s/html_%s/docPages/links/installation_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
commands.getstatusoutput( "ln -s %s/html/monitoringDoc_%s.html %s/html_%s/docPages/links/monitoringDoc_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
commands.getstatusoutput( "ln -s %s/html/translationDoc_%s.html %s/html_%s/docPages/links/translationDoc_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
commands.getstatusoutput( "ln -s %s/html/developersDoc_%s.html %s/html_%s/docPages/links/developersDoc_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
commands.getstatusoutput( "ln -s %s/html/installation_%s.html %s/html_%s/docPages/links/installation_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
commands.getstatusoutput( "ln -s %s/html/rrdToolDoc_%s.html %s/html_%s/docPages/links/rrdToolDoc_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
commands.getstatusoutput( "ln -s %s/html/troubleshooting_%s.html %s/html_%s/docPages/links/troubleshooting_%s.html" %(statsPaths.STATSDOC,language,path,language,language) )
commands.getstatusoutput( "ln -s %s/html/images %s/html_%s/docPages/links/images" %(statsPaths.STATSDOC,path,language ) )
示例12: updateGroupedRoundRobinDatabases
# 需要导入模块: from pxStats.lib.LanguageTools import LanguageTools [as 别名]
# 或者: from pxStats.lib.LanguageTools.LanguageTools import getMainApplicationLanguage [as 别名]
def updateGroupedRoundRobinDatabases( infos, logger = None ):
"""
@summary : This method is to be used to update the database
used to stored the merged data of a group.
"""
endTime = StatsDateLib.getSecondsSinceEpoch( infos.endTime )
tempRRDFileName = RrdUtilities.buildRRDFileName( _("errors"), clients = infos.group, machines = infos.machines, fileType = infos.fileTypes[0] )
startTime = RrdUtilities.getDatabaseTimeOfUpdate( tempRRDFileName, infos.fileTypes[0] )
if startTime == 0 :
startTime = StatsDateLib.getSecondsSinceEpoch( StatsDateLib.getIsoTodaysMidnight( infos.endTime ) )
timeSeperators = getTimeSeperatorsBasedOnAvailableMemory( StatsDateLib.getIsoFromEpoch( startTime ), StatsDateLib.getIsoFromEpoch( endTime ), infos.clients, infos.fileTypes[0], infos.machines )
#print timeSeperators
for i in xrange(0, len( timeSeperators ),2 ):#timeseperators should always be coming in pairs
startTime = StatsDateLib.getSecondsSinceEpoch( timeSeperators[i] )
dataPairs = getPairs( infos.clients, infos.machines, infos.fileTypes[0], timeSeperators[i], timeSeperators[i+1], infos.group, logger )
for dataType in dataPairs:
translatedDataType = LanguageTools.translateTerm(dataType, 'en', LanguageTools.getMainApplicationLanguage(), CURRENT_MODULE_ABS_PATH)
rrdFileName = RrdUtilities.buildRRDFileName( dataType = translatedDataType, clients = infos.group, groupName = infos.group, machines = infos.machines,fileType = infos.fileTypes[0], usage = "group" )
if not os.path.isfile( rrdFileName ):
createRoundRobinDatabase( rrdFileName, startTime, dataType )
if endTime > startTime :
j = 0
while dataPairs[ dataType ][j][0] < startTime and j < len( dataPairs[ dataType ] ):
#print "going over : %s startime was :%s" %(dataPairs[ dataType ][j][0], startTime)
j = j +1
for k in range ( j, len( dataPairs[ dataType ] ) ):
#print "updating %s at %s" %(rrdFileName, int( dataPairs[ dataType ][k][0] ))
try:
rrdtool.update( rrdFileName, '%s:%s' %( int( dataPairs[ dataType ][k][0] ), dataPairs[ dataType ][k][1] ) )
except:
if logger != None:
try:
logger.warning( "Could not update %s. Last update was more recent than %s " %( rrdFileName,int( dataPairs[ dataType ][k][0] ) ) )
except:
pass
pass
else:
#print "endTime %s was not bigger than start time %s" %( endTime, startTime )
if logger != None :
try:
logger.warning( _( "This database was not updated since it's last update was more recent than specified date : %s" ) %rrdFileName )
except:
pass
RrdUtilities.setDatabaseTimeOfUpdate( tempRRDFileName, infos.fileTypes[0], endTime )
示例13: updateRoundRobinDatabases
# 需要导入模块: from pxStats.lib.LanguageTools import LanguageTools [as 别名]
# 或者: from pxStats.lib.LanguageTools.LanguageTools import getMainApplicationLanguage [as 别名]
def updateRoundRobinDatabases( client, machines, fileType, endTime, logger = None ):
"""
@summary : This method updates every database linked to a certain client.
@note : Database types are linked to the filetype associated with the client.
"""
combinedMachineName = ""
combinedMachineName = combinedMachineName.join( [machine for machine in machines ] )
tempRRDFileName = RrdUtilities.buildRRDFileName( dataType = _("errors"), clients = [client], machines = machines, fileType = fileType)
startTime = RrdUtilities.getDatabaseTimeOfUpdate( tempRRDFileName, fileType )
if startTime == 0 :
startTime = StatsDateLib.getSecondsSinceEpoch( StatsDateLib.getIsoTodaysMidnight( endTime ) )
endTime = StatsDateLib.getSecondsSinceEpoch( endTime )
timeSeperators = getTimeSeperatorsBasedOnAvailableMemory(StatsDateLib.getIsoFromEpoch( startTime ), StatsDateLib.getIsoFromEpoch( endTime ), [client], fileType, machines )
for i in xrange( len(timeSeperators) -1 ) :
dataPairs = getPairs( [client], machines, fileType, timeSeperators[i], timeSeperators[i+1] , groupName = "", logger = logger )
for dataType in dataPairs:
translatedDataType = LanguageTools.translateTerm(dataType, 'en', LanguageTools.getMainApplicationLanguage(), CURRENT_MODULE_ABS_PATH)
rrdFileName = RrdUtilities.buildRRDFileName( dataType = translatedDataType, clients = [client], machines = machines, fileType = fileType )
if not os.path.isfile( rrdFileName ):
createRoundRobinDatabase( databaseName = rrdFileName , startTime= startTime, dataType = dataType )
if endTime > startTime :
j = 0
while dataPairs[ dataType ][j][0] < startTime:
j = j +1
for k in range ( j, len( dataPairs[ dataType ] ) ):
try:
rrdtool.update( rrdFileName, '%s:%s' %( int( dataPairs[ dataType ][k][0] ), dataPairs[ dataType ][k][1] ) )
except:
if logger != None:
try:
logger.warning( "Could not update %s. Last update was more recent than %s " %( rrdFileName,int( dataPairs[ dataType ][k][0] ) ) )
except:
pass
pass
if logger != None :
try:
logger.info( _( "Updated %s db for %s in db named : %s" ) %( dataType, client, rrdFileName ) )
except:
pass
else:
if logger != None :
try:
logger.warning( _( "This database was not updated since it's last update was more recent than specified date : %s" ) %rrdFileName )
except:
pass
RrdUtilities.setDatabaseTimeOfUpdate( rrdFileName, fileType, endTime )
示例14: buildRRDFileName
# 需要导入模块: from pxStats.lib.LanguageTools import LanguageTools [as 别名]
# 或者: from pxStats.lib.LanguageTools.LanguageTools import getMainApplicationLanguage [as 别名]
def buildRRDFileName( dataType = 'errors', clients = None , machines = None,\
groupName = "", fileType = "", usage = "regular" ):
"""
@summary : Returns the name of the round robin database bases on the parameters.
@param dataType: byteocunt, errors, filecount, filesOverMaxLatency and latency.
@param clients: list of clients/sources names. If only one is wanted, include it in a list.
@param machines: list of machines associated with client/sources names. If only one is wanted, include it in a list.
@param fileType : Useless for regular and group databases. Obligatory for totalForMachine databases.
@param groupName: optional. Use only if the list of client/sources has a KNOWN group name.
@param usage: regular, group or totalForMachine.
@return: Returns the name of the round robin database bases on the parameters.
"""
_ = LanguageTools.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, LanguageTools.getMainApplicationLanguage() )
clients = clients or ['client1','client1']
machines = machines or ['machine1','machine2']
fileName = ""
combinedMachineName = ""
for machine in machines:
combinedMachineName = combinedMachineName + machine
combinedClientsName = ""
for client in clients:
combinedClientsName = combinedClientsName + client
if len(clients) ==1:
if usage == "regular":
fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" %( dataType, combinedClientsName, combinedMachineName )
elif usage == "group":
fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" %( dataType, groupName, combinedMachineName )
elif usage == "totalForMachine":
fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" %( dataType, fileType, combinedMachineName )
else:
if usage == "regular":
fileName = STATSPATHS.STATSCURRENTDB + _("%s/combined/%s_%s") %( dataType, combinedClientsName, combinedMachineName )
elif usage == "group":
#fileName = STATSPATHS.STATSCURRENTDB + _("%s/combined/%s_%s") %( dataType, groupName, combinedMachineName )
try:
existingFiles= os.listdir(STATSPATHS.STATSCURRENTDB + "%s/combined/"%( dataType) )
for file in existingFiles:
if fnmatch.fnmatch(file, groupName + "*"):
fileName = file
break
except:
pass
if fileName == "":#no preexisitng file exist for this group
fileName = STATSPATHS.STATSCURRENTDB + "%s/%s_%s" %( dataType, groupName, combinedMachineName )
else:#else
fileName = STATSPATHS.STATSCURRENTDB + "%s/combined/"%(dataType) + fileName
elif usage == "totalForMachine":
fileName = STATSPATHS.STATSCURRENTDB + _("%s/combined/%s_%s") %( dataType, fileType, combinedMachineName )
#print "before ", fileName
#fileName = fileName.replace("année","year").replace("nbreDeBytes","bytecount").replace("nbreDeFichiers","filecount").replace("erreurs","errors").replace("latence","latency").replace("fichiersAvecLatenceInnacceptable","filesOverMaxLatency").replace("heures","hours").replace("mois","month").replace("jour","day").replace("","")
#print "after ", fileName
return fileName