本文整理汇总了Python中models.Config.readconfig方法的典型用法代码示例。如果您正苦于以下问题:Python Config.readconfig方法的具体用法?Python Config.readconfig怎么用?Python Config.readconfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Config
的用法示例。
在下文中一共展示了Config.readconfig方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: logall
# 需要导入模块: from models import Config [as 别名]
# 或者: from models.Config import readconfig [as 别名]
def logall():
config = Config.readconfig()
while config != 0:
url = config["URLS"]
if os.path.exists("logs"):
pass
else:
os.mkdir("logs")
thread_list = []
for m in url:
# Instantiates the thread
# (i) does not make a sequence, so (i,)
t = threading.Thread(target=logs.log, args=(m,))
# Sticks the thread in a list so that it remains accessible
thread_list.append(t)
# Starts threads
for thread in thread_list:
thread.start()
# This blocks the calling thread until the thread whose join() method is called is terminated.
# From http://docs.python.org/2/library/threading.html#thread-objects
for thread in thread_list:
thread.join()
示例2: dash
# 需要导入模块: from models import Config [as 别名]
# 或者: from models.Config import readconfig [as 别名]
def dash(self, **params):
config = Config.readconfig()
# Attempts to read the config.
if config == 0:
# Else it uses the Arguements to create a config.
# organises make config data
data = {str(key):str(value) for key,value in params.items()}
url = []
for i, v in data.items():
url.append(v)
# makes config
Config.mkconfig(url)
else:
# If True it saves the data to a variable
URLS = config["URLS"]
refresh = config["refresh"]
# Runs the script in the Parsing Model. Parses the XML Files from URL
parse = Parsing.system()
refresh = config["refresh"]
# Returns the template with Parsed XML Data and The Refresh Integer from the Config.
return self.render_template('home/dash.html', template_vars={'data': parse, 'refresh': refresh})
示例3: index
# 需要导入模块: from models import Config [as 别名]
# 或者: from models.Config import readconfig [as 别名]
def index(self):
config = Config.readconfig()
# Check if there is a config.
if config != 0:
# Else redirect the User to the Dashboard
raise cherrypy.HTTPRedirect("Home/dash")
else:
# If True Return the template
return self.render_template('home/index.html')
示例4: settings
# 需要导入模块: from models import Config [as 别名]
# 或者: from models.Config import readconfig [as 别名]
def settings(self):
# get config data
config = Config.readconfig()
URLS = config["URLS"]
refresh = config["refresh"]
times = config["time"]
# Return the template
return self.render_template('home/settings.html', template_vars={'refresh': refresh, 'urls': URLS, 'time': times})
示例5: log
# 需要导入模块: from models import Config [as 别名]
# 或者: from models.Config import readconfig [as 别名]
def log(m):
refresh = 20
config = Config.readconfig()
refresh = config["refresh"]
name = ""
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
monit = ET.parse(urllib.urlopen(m, context=ctx)) or ET.parse(m)
root = monit.getroot()
for i in root.findall("server/localhostname"):
name = i.text
logs.setup_logger(name, SiteConfig.home + "/logs/" + name + '.txt')
logger = logging.getLogger(name)
while True:
data = ET.tostring(root)
logger.info(data)
time.sleep(float(refresh))
示例6: system
# 需要导入模块: from models import Config [as 别名]
# 或者: from models.Config import readconfig [as 别名]
def system():
# read config
config = Config.readconfig()
url = config["URLS"]
parsed = []
# for loop of URls in config
for m in url:
data = {}
de = []
hostlst = []
fs = []
# parse the xml whether its a local xml file or remote
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
monit = ET.parse(urllib.urlopen(m, context=ctx)) or ET.parse(m)
root = monit.getroot()
# find and save daemon xml data
for i in root.findall("*[@type='3']"):
daemon = {h.tag: h.text for h in i if h.text != '\n ' and h.text != '\n ' and h.text != None and h.text != '\n '}
daemon.update({"mem": {h.tag: h.text for l in i.iter("memory") for h in l}})
daemon.update({"cpu":{h.tag: h.text for l in i.iter("cpu") for h in l}})
daemon.update({"port":{h.tag: h.text for l in i.iter("port") for h in l}})
loop(daemon)
de.append(daemon)
data.update({"process": de})
# find and save host xml data
for i in root.findall("*[@type='4']"):
host = {h.tag: h.text for h in i if h.text != '\n ' and h.text != '\n ' and h.text != None and h.text != '\n '}
host.update({"port": {h.tag: h.text for l in i.iter("port") for h in l}})
loop(host)
hostlst.append(host)
data.update({"host": hostlst})
# find and save filesystem xml data
for i in root.findall("*[@type='0']"):
file = {h.tag: h.text for h in i if h.text != '\n ' and h.text != '\n ' and h.text != None and h.text != '\n '}
file.update({"block": {h.tag: h.text for l in i.iter("block") for h in l}})
file.update({"inode": {h.tag: h.text for l in i.iter("inode") for h in l}})
loop(file)
fs.append(file)
data.update({"fs": fs})
# find and save system details xml data
sys = {h.tag: h.text for i in root.findall("*[@type='5']") for h in i if h.text != '\n ' and h.text != '\n ' and h.text != None and h.text != '\n '}
loop(sys)
sys.update({"load": {h.tag: h.text for i in root.findall("*[@type='5']/system/load") for h in i}, "cpu": {h.tag: h.text for i in root.findall("*[@type='5']/system/cpu") for h in i}, "memory":{h.tag: h.text for i in root.findall("*[@type='5']/system/memory") for h in i}, "swap":{h.tag: h.text for i in root.findall("*[@type='5']/system/swap") for h in i}, "server": {h.tag: h.text for i in root.findall("server") for h in i}, 'platform': {h.tag: h.text for i in root.findall('platform') for h in i}})
loop(sys["server"])
data.update({"sys": sys})
netloc = urlparse.urlparse(m).netloc
scheme = urlparse.urlparse(m).scheme
data.update({"url": scheme + ":\\\\www." + netloc })
loop(data)
parsed.append(data)
return parsed
示例7: duration
# 需要导入模块: from models import Config [as 别名]
# 或者: from models.Config import readconfig [as 别名]
def duration(seconds):
config = Config.readconfig()
time = config["time"]
if time == "Week Day Hour Minute Second":
minutes, seconds = divmod(int(seconds), 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
weeks, days = divmod(days, 7)
if weeks == 0:
date = '{}D {}H {}M {}S'.format(days, hours, minutes, seconds)
elif days == 0:
date = '{}H {}M {}S'.format(hours, minutes, seconds)
elif hours == 0:
date = '{}M {}S'.format(minutes, seconds)
else:
date = '{}W {}D {}H {}M {}S'.format(weeks, days, hours, minutes, seconds)
elif time == "Day Hour Minute Second":
minutes, seconds = divmod(int(seconds), 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
if days == 0:
date = '{}H {}M {}S'.format(hours, minutes, seconds)
if hours == 0:
date = '{}M {}S'.format(minutes, seconds)
else:
date = '{}D {}H {}M {}S'.format(days, hours, minutes, seconds)
elif time == "Week Day Hour Minute":
minutes, seconds = divmod(int(seconds), 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
weeks, days = divmod(days, 7)
if weeks == 0:
date = '{}D {}H {}M'.format(days, hours, minutes)
elif days == 0:
date = '{}H {}M'.format(hours, minutes)
elif hours == 0:
date = '{}M'.format(minutes)
else:
date = '{}W {}D {}H {}M'.format(weeks, days, hours, minutes)
elif time == "Year Day Hour Minute":
minutes, seconds = divmod(int(seconds), 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
weeks, days = divmod(days, 7)
years, weeks = divmod(days, 52)
if years == 0:
date = '{}D {}H {}M'.format(days, hours, minutes)
elif days == 0:
date = '{}H {}M'.format(hours, minutes)
elif hours == 0:
date = '{}M'.format(minutes)
else:
date = '{}Y {}D {}H {}M'.format(years, days, hours, minutes)
return str(date)