def createReports(sloObj,site,datacenter): www = HTML() html_index = '/www/' + site + '/fast.html' sloCSV = '/www/' + site + '/CSV/' + site + '_slo.csv' csv = open(sloCSV, 'w') f_index = open(html_index,'w') f_index.write(www.start_html('SLO Summary')) linkpath = "/" + site + "/CSV/" + site + '_slo.csv' fpSummLink = '<a href=' + linkpath + '>SLO CSV</a>\n' f_index.write(www.EMC_Header(site,datacenter,'',fpSummLink)) csv.write('SLO Report for ' + site + '\n\n') csv.write("SLO Policy,Response Time Target\n") f_index.write(www.start_table(3,'SLO Policies')) f_index.write(www.tr + www.th + 'Policy Name' + www.th + 'Response Time Target (ms)\n') for slo in sloObj.slo_policies: html = www.tr + www.td + slo + www.td + sloObj.slo_policies[slo] + "\n" csv.write(slo + ',' + sloObj.slo_policies[slo] + '\n') f_index.write(html) f_index.write(www.end_table) f_index.write(www.end_html) f_index.close() csv.close()
def __init__(self, settings, session, data, inputs): # --- Definitions self.settings = settings self.session = session self.data = data self.inputs = inputs self.html = HTML(self) self.display = True # --- Pre-processing self.pre_process() # --- Actions if self.inputs.getvalue('form_action') is not None: # NB: stop is for redirection stop = self.form_action() else: stop = None # --- Html if stop is None: self.html.meta(Language=self.session.language) self.html.favicon('Core/Style/Icons/favicon.ico?v={0}'.format( time())) self.html.style('fonts') self.html.style('common') self.html.jsfile('Core/JS/jquery.js') self.html.jsfile('Core/JS/common.js') self.set_html()
def createReports(sloObj, site, datacenter): www = HTML() html_index = '/www/' + site + '/fast.html' sloCSV = '/www/' + site + '/CSV/' + site + '_slo.csv' csv = open(sloCSV, 'w') f_index = open(html_index, 'w') f_index.write(www.start_html('SLO Summary')) linkpath = "/" + site + "/CSV/" + site + '_slo.csv' fpSummLink = '<a href=' + linkpath + '>SLO CSV</a>\n' f_index.write(www.EMC_Header(site, datacenter, '', fpSummLink)) csv.write('SLO Report for ' + site + '\n\n') csv.write("SLO Policy,Response Time Target\n") f_index.write(www.start_table(3, 'SLO Policies')) f_index.write(www.tr + www.th + 'Policy Name' + www.th + 'Response Time Target (ms)\n') for slo in sloObj.slo_policies: html = www.tr + www.td + slo + www.td + sloObj.slo_policies[slo] + "\n" csv.write(slo + ',' + sloObj.slo_policies[slo] + '\n') f_index.write(html) f_index.write(www.end_table) f_index.write(www.end_html) f_index.close() csv.close()
def __init__(self, master=None): Frame.__init__(self, master) self.options_list = [ "table", "tr", "td", "h1", "h2", "h3", "h4", "h5", "h6", "br", "span", "div", "a", "link", "nav", "title", "abbr", "address", "code", "em", "progress", "strong", "sub", "sup", "time", "u", "var", "samp", "small", "q", "mark", "s", "pre", "ins", "form", "input", "button", "fieldset", "legend", "label", "datalist", "option", "optgroup", "textarea", "keygen", "output", "select", "img", "map", "area", "canvas", "iframe", "figure", "figcaption", "audio", "source", "track", "video", "ul", "li", "ol", "dl", "dt", "dd", "menu", "menuitem", "caption", "thead", "tbody", "tfoot", "col", "colgroup", "style", "header", "footer", "main", "section", "article", "aside", "details", "dialog", "summary", "head", "meta", "base", "script", "noscript", "embed", "object", "param", "blockquote", "hr", "b", "bdi", "bdo", "dfn", "cite", "del", "q", "meter", "rp", "rt", "ruby" ] self.options_list.sort() self.add_item = False self.nested = False self.delete_something = False self.meta = False self.temp_dict = {} self.order_number = 1 self.html_object = HTML() self.CheckVar1 = IntVar() self.CheckVar2 = IntVar() self.C1 = Checkbutton(root, text = "Full HTML", variable = self.CheckVar1, \ command = self.html_full, onvalue = 1, offvalue = 0, height=4, \ width = 15) self.C2 = Checkbutton(root, text = "Has Body", variable = self.CheckVar2, \ command = self.html_has_body, onvalue = 1, offvalue = 0, height=4, \ width = 15) self.C1.pack() self.C2.pack() self.generate_button = Button(root, text='Generate HTML', command=self.make_file) self.generate_button.place(x=30, y=115) self.add_element_button = Button(root, text='Add Element', command=self.add_html_element) self.add_element_button.place(x=30, y=15) self.order_button = Button(root, text='Order Elements', command=self.order_html) self.order_button.place(x=30, y=75) self.delete_button = Button(root, text='Delete Element', command=self.delete_html) self.delete_button.place(x=30, y=45)
def getKline(period, symbol , var_time_hour_period , count = 200): now_datetime = datetime.now() hours_before = now_datetime + timedelta(hours=-count) bitmex_hour = hours_before.strftime('%Y-%m-%dT%H:%M:%S.%fZ') #print now_datetime , hours_before , bitmex_hour url = "https://www.bitmex.com/api/v1/trade/bucketed?binSize=%s&partial=false&symbol=%s&count=%s&reverse=false&startTime=%s" % ( period , symbol , str(count), bitmex_hour ) #print url data = HTML.get_html(url) #print data #data = gzip_uncompress(data) #print data if len(data) > 0: data = json.loads(data) #print data[-1] while len(data) > 0 and (getHour(data[-1]["timestamp"]) % var_time_hour_period) != 0: data = data[:-1] #print data #ret = [ (x["close"] , x["timestamp"] , getHour(x["timestamp"])) for x in data] #print ret ret = [ x["close"] for x in data] # print "ret_data:" , data , len(data) return ret else: return []
def main(output=None): with HTML(output=output) as doc: with TopLevelTag("head") as head: with Tag("title") as title: title.text = "hello" head += title doc += head with TopLevelTag("body") as body: with Tag("h1", klass=("main-text", )) as h1: h1.text = "Test" body += h1 with Tag("div", klass=("container", "container-fluid"), id="lead") as div: with Tag("p") as paragraph: paragraph.text = "another test" div += paragraph with Tag("img", is_single=True, src="/icon.png") as img: div += img body += div doc += body
def __init__(self, settings, session, data, inputs): # --- Definitions self.settings = settings self.session = session self.data = data self.inputs = inputs self.html = HTML(self) self.display = True; # --- Pre-processing self.pre_process() # --- Actions if self.inputs.getvalue('form_action') is not None: # NB: stop is for redirection stop = self.form_action() else: stop = None # --- Html if stop is None: self.html.meta(Language=self.session.language) self.html.favicon('Core/Style/Icons/favicon.ico?v={0}'.format(time())) self.html.style('fonts') self.html.style('common') self.html.jsfile('Core/JS/jquery.js') self.html.jsfile('Core/JS/common.js') self.set_html()
def test_html_object_set_element(self): html_obj = HTML() test_element = html_element() html_obj.add_element(test_element) swap_element = html_element(False, "a", "Anchor") html_obj.set_element(0, swap_element) self.assertEqual(swap_element, html_obj.get_element(0))
def createReports(symObj,site,datacenter,sid): # www = HTML() # Create directories if they don't exist f = Files() f.dir = "/www/" + site + "/OR/" f.mkdir() htmlfile = '/www/' + site + '/OR/index.html' perf = '/opt/EMC/Scripts/shell/rcopyperf_' + sid + '.log' f.read_file(perf) page = [] page.append(www.start_html_refresh('OR Sessions')) page.append(www.EMC_Header(site,datacenter)) page.append(www.start_table(1,"OR Port Performance")) header = ["FA Port","MB/s","Ceiling","Number of Devices"] page.append(www.th_list(header)) perftotal = 0 for line in f.readfile: line = line.strip() fields = line.split() if len(fields) == 5: fields = fields[1:5] perftotal += int(fields[1]) page.append(www.tr_list(fields)) page.append(www.tr + www.th + "Total OR MB/s" + www.th + str(perftotal)) page.append(www.end_table) page.append('<br><br><pre>\n') for line in symObj.or_list: page.append(line) f.write_file(htmlfile,page)
def test_empty_html_object(self): html_obj = HTML() self.assertFalse(html_obj.is_full_html) self.assertFalse(html_obj.has_body) self.assertFalse(html_obj.has_head) temp_list = [] self.assertEqual(temp_list, html_obj.element_list) self.assertEqual("", html_obj.html_string) self.assertEqual(0, html_obj.inc_id)
def test_html_object_generate_full_html_no_body_with_elements(self): html_obj = HTML(True, False, False) test_element = html_element(False, "a", "Anchor") html_obj.add_element(test_element) html_obj.generate_html() self.assertEqual("<!DOCTYPE html>\n <html>\n<a>Anchor</a>\n</html>", html_obj.html_string)
def main(): # Read xml and get results inst_dict = parseInstructions() tabs_dict = genTabsDict(inst_dict) # Create HTML html_file_name = 'Dashboard.html' html = HTML(tabs_dict) create_file(html_file_name, html.file_content) webbrowser.open_new_tab(html_file_name) # Print result print_result(tabs_dict)
def insertTab(self, text, asHTML, beforeIndex=None): """ 1st arg can, instead of being 'text', be a widget """ if beforeIndex is None: beforeIndex = asHTML asHTML = False if (beforeIndex < 0) or (beforeIndex > self.getTabCount()): #throw new IndexOutOfBoundsException(); pass if isinstance(text, str): if asHTML: item = HTML(text) else: item = Label(text) item.setWordWrap(False) else: # passing in a widget, it's expected to have its own style item = text self.insertTabWidget(item, beforeIndex)
def __init__(self, autoHide=None, modal=True, **kwargs): PopupPanel.__init__(self, autoHide, modal, **kwargs) self.caption = HTML() self.child = None self.dragging = False self.dragStartX = 0 self.dragStartY = 0 self.panel = FlexTable(Height="100%", BorderWidth="0", CellPadding="0", CellSpacing="0") self.panel.setWidget(0, 0, self.caption) self.panel.getCellFormatter().setHeight(1, 0, "100%") self.panel.getCellFormatter().setWidth(1, 0, "100%") self.panel.getCellFormatter().setAlignment( 1, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE) PopupPanel.setWidget(self, self.panel) self.setStyleName("gwt-DialogBox") self.caption.setStyleName("Caption") self.caption.addMouseListener(self)
def handle_file(self, file_name): """ Handle a file :param file_name: The filename to process :return: None """ dir_name = os.path.dirname(file_name.path) basename = os.path.basename(file_name.path) path = CC_BASE + self.ROOT_PATH + "/" + os.path.abspath(dir_name) path = path.replace('//', '/') if not os.path.exists(path): os.makedirs(path) open_file = open(os.path.join(path, basename + HTML.FILE_EXT), "w") source_data = File.read_file(self.script_base + file_name.path) last_pos = dir_name.rfind("/") html_link = HTML.get_link(CC_BASE, "root", "") + \ HTML.get_link(path, dir_name[last_pos + 1:], basename) open_file.write(HTML.get_header(html_link, HTML.SRC_PREFIX)) processing_line = 1 previous_line_is_continued = False for line in source_data.splitlines(): line = line.decode("utf-8") line = line.replace("&", "&") line = line.replace(">", ">") line = line.replace("<", "<") line = line.replace('"', '"') line_covered = processing_line in file_name.lines and \ Code.line_is_code(line) or \ processing_line > 1 and \ previous_line_is_continued if line_covered: span_class = "covered" elif Code.line_is_code(line): span_class = "not_covered" else: span_class = "not_code" line_to_save = HTML.get_html( HTML.LINE_SOURCE) % (processing_line, span_class, line) open_file.write(line_to_save) previous_line_is_continued = True if line.endswith("\\") else False processing_line = processing_line + 1 open_file.write( HTML.get_html(HTML.SRC_SUFFIX) + HTML.get_footer( file_name.total_lines, file_name.covered_lines, False))
def createReports(srdfObj,site,datacenter): Alerts = {} alert = 0 www = HTML() f = Files() mailObj = EMail() dates = DateString() page = [] csvpage = [] htmlfile = '/www/SRDF.html' csvfile = '/www/SRDF.csv' reportDate = str(time.strftime("%c")) page.append(www.start_html('SRDF Report')) html = '<p>Report Date: ' + reportDate + '<br><br>' html += 'SRDF Status Report<br><br>' page.append(html) for group in srdfObj.SRDF_Groups: # Print header table page.append('<p><br><table align=center border=3>\n') row = ['Group ID','SymID','RemoteSymID','Tracks Pending','Delta Time'] page.append(www.th_list(row)) csvpage.append(', '.join(row) + '\n') info = srdfObj.SRDF_Groups_Info[group] row = [ group, info['symid'],info['remote_symid'],info['tracks'],info['delta'] ] page.append(www.tr_list(row)) page.append(www.end_table) csvpage.append(', '.join(row) + '\n') # Print Pair data page.append('<p><br><table align=center border=3>\n') row = ['Source','Target','Link State','Mode','Replication State'] page.append(www.th_list(row)) csvpage.append(', '.join(row) + '\n') pairs = srdfObj.SRDF_Groups_Pairs[group] for pair in pairs: list = pair.split(',') if list[4] != 'Consistent': bgcolor="#B0B3AF" alert += 1 Alerts[group] = "SRDF is not in a consistent state for " + group else: bgcolor="#69F24E" page.append(www.tr_list(list,bgcolor)) csvpage.append(', '.join(list) + '\n') page.append(www.end_table) page.append(www.end_html) f.write_file(htmlfile,page) f.write_file(csvfile,csvpage) if alert > 0: alertMessage = "The Following SRDF Groups are not Consistent\n\n" for groupalert in Alerts: alertMessage += Alerts[groupalert] mailObj.subject = "VMAX SRDF Alert " + site + ', ' + datacenter mailObj.message = alertMessage mailObj.send_mail()
def insertTab(self, text, asHTML, beforeIndex=None): """ 1st arg can, instead of being 'text', be a widget. 1st arg can also be None, which results in a blank space between tabs. Use this to push subsequent tabs out to the right hand end of the TabBar. (the "blank" tab, by not being focussable, is not clickable). """ if beforeIndex is None: beforeIndex = asHTML asHTML = False if (beforeIndex < 0) or (beforeIndex > self.getTabCount()): #throw new IndexOutOfBoundsException(); pass if text is None: text = HTML(" ", True) text.setWidth("100%") text.setStyleName("gwt-TabBarRest") self.panel.insert(text, beforeIndex + 1) self.panel.setCellWidth(text, "100%") return try: istext = isinstance(text, str) or isinstance(text, unicode) except: istext = isinstance(text, str) if istext: if asHTML: item = HTML(text) else: item = Label(text) item.setWordWrap(False) else: # passing in a widget, it's expected to have its own style item = text self.insertTabWidget(item, beforeIndex)
def createReports(fpObj,site,datacenter): htmlpage = [] csvpage = [] www = HTML() f = Files() html_index = '/www/' + site + '/fast_demand.html' fastCSV = '/www/' + site + '/CSV/' + site + '_fast_demand.csv' htmlpage.append(www.start_html('MV Summary')) linkpath = "/" + site + "/CSV/" + site + '_fast_demand.csv' fpSummLink = '<a href=' + linkpath + '>FAST CSV</a>\n' htmlpage.append(www.EMC_Header(site,datacenter,'',fpSummLink)) csvpage.append('FAST-VP Report for ' + site + '\n\n') htmlpage.append(www.start_table(3,'FAST-VP Demand report')) heading = ['SG_Name'] for tier in fpObj.tiernames: heading.append(tier) htmlpage.append(www.th_list(heading)) csvpage.append(', '.join(heading)) for sg in fpObj.tiers: # line = [str(sg)] for tiername in fpObj.tiernames: if tiername in fpObj.tiers[sg]: line.append(fpObj.tiers[sg][tiername]) else: line.append('0') csvpage.append(', '.join(line)) htmlpage.append(www.tr_list(line)) htmlpage.append(www.end_table) htmlpage.append(www.end_html) f.write_file(html_index,htmlpage) f.write_file(fastCSV,csvpage)
def __init__(self, autoHide=None, modal=True, **kwargs): PopupPanel.__init__(self, autoHide, modal, **kwargs) self.caption = HTML() self.child = None self.dragging = False self.dragStartX = 0 self.dragStartY = 0 self.panel = FlexTable(Height="100%", BorderWidth="0", CellPadding="0", CellSpacing="0") self.panel.setWidget(0, 0, self.caption) self.panel.getCellFormatter().setHeight(1, 0, "100%") self.panel.getCellFormatter().setWidth(1, 0, "100%") self.panel.getCellFormatter().setAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE) PopupPanel.setWidget(self, self.panel) self.setStyleName("gwt-DialogBox") self.caption.setStyleName("Caption") self.caption.addMouseListener(self)
def __init__(self, sender, offsetX, offsetY, contents, show_delay, hide_delay, styleName, **kwargs): """ contents may be a text string or it may be a widget """ PopupPanel.__init__(self, True, **kwargs) self.show_delay = show_delay self.hide_delay = hide_delay if isinstance(contents, str): contents = HTML(contents) self.add(contents) left = sender.getAbsoluteLeft() + offsetX top = sender.getAbsoluteTop() + offsetY self.setPopupPosition(left, top) self.setStyleName(styleName) if tooltip_hide_timer: self.tooltip_show_timer = Timer(1, self) else: self.tooltip_show_timer = Timer(self.show_delay, self)
def draw(self, month, year): tod = time.localtime() mm = tod.tm_mon yy = tod.tm_year # has today changed and thus changed month? cater to rare case where widget in created on last day of month & # page left till next day hasChangeMonth = False if yy <> self.todayYear or mm <> self.todayMonth: hasChangeMonth = True self.todayYear = yy self.todayMonth = mm # check to see if we have drawn the full widget before if self.defaultGrid is None: self.drawFull(month, year) else: # ok means we are re-drawing, but first check if it is the same as the defaultGrid, if yes, just use it if not hasChangeMonth and month == self.todayMonth and year == self.todayYear: self.middlePanel.setWidget(self.defaultGrid) self.currentMonth = self.todayMonth self.currentYear = self.todayYear else: # we have to redraw the grid -- bah g = self.drawGrid(month, year) if hasChangeMonth: self.defaultGrid = grid # reset the default grid as we have changed months # # what about the title panel? # self.titlePanel.setWidget( HTML("<b>" + self.getMonthsOfYear()[month - 1] + " " + str(year) + "</b>")) self.setVisible(True) return
def createReports(fpObj, site, datacenter): www = HTML() html_index = '/www/' + site + '/fast.html' fastCSV = '/www/' + site + '/CSV/' + site + '_fast.csv' csv = open(fastCSV, 'w') f_index = open(html_index, 'w') f_index.write(www.start_html('MV Summary')) linkpath = "/" + site + "/CSV/" + site + '_fast.csv' fpSummLink = '<a href=' + linkpath + '>FAST CSV</a>\n' demandReportPath = '/' + site + '/fast_demand.html' DemandReportLink = '<a href=' + demandReportPath + '>FAST-VP Demand Report</a>\n' fastReportPath = '/' + site + '/fast.html' fastReportLink = '<a href=' + fastReportPath + '>FAST-VP Policy Report</a>\n' f_index.write(www.EMC_Header(site, datacenter, '', fpSummLink)) f_index.write('<p><br><table align=center border=3>\n') row = [fastReportLink, DemandReportLink] f_index.write(www.th_list(row)) f_index.write(www.end_table) csv.write('FAST-VP Report for ' + site + '\n\n') csv.write("Fast Policy,Tier,Max Percent per DG\n") for fp in fpObj.fast_policies: # Write out a table for FAST Policy txt = 'FAST-VP Policy: ' + fp + '\n' f_index.write(www.start_table(3, txt)) f_index.write(www.tr + www.th + 'Tier Name' + www.th + 'Max Percent per SG\n') for tier in fpObj.fast_policies[fp]: html = www.tr + www.td + tier + www.td + fpObj.fast_policies[fp][ tier] + "\n" csv.write(fp + ',' + tier + ',' + fpObj.fast_policies[fp][tier] + '\n') f_index.write(html) f_index.write(www.end_table) f_index.write(www.end_html) f_index.close() csv.close()
def createReports(fpObj, site, datacenter): htmlpage = [] csvpage = [] www = HTML() f = Files() html_index = '/www/' + site + '/fast_demand.html' fastCSV = '/www/' + site + '/CSV/' + site + '_fast_demand.csv' htmlpage.append(www.start_html('MV Summary')) linkpath = "/" + site + "/CSV/" + site + '_fast_demand.csv' fpSummLink = '<a href=' + linkpath + '>FAST CSV</a>\n' htmlpage.append(www.EMC_Header(site, datacenter, '', fpSummLink)) csvpage.append('FAST-VP Report for ' + site + '\n\n') htmlpage.append(www.start_table(3, 'FAST-VP Demand report')) heading = ['SG_Name'] for tier in fpObj.tiernames: heading.append(tier) htmlpage.append(www.th_list(heading)) csvpage.append(', '.join(heading)) for sg in fpObj.tiers: # line = [str(sg)] for tiername in fpObj.tiernames: if tiername in fpObj.tiers[sg]: line.append(fpObj.tiers[sg][tiername]) else: line.append('0') csvpage.append(', '.join(line)) htmlpage.append(www.tr_list(line)) htmlpage.append(www.end_table) htmlpage.append(www.end_html) f.write_file(html_index, htmlpage) f.write_file(fastCSV, csvpage)
class Spot: """ The Spot class """ # ---------------------------------------------------------------------- def __init__(self, settings, session, data, inputs): # --- Definitions self.settings = settings self.session = session self.data = data self.inputs = inputs self.html = HTML(self) self.display = True; # --- Pre-processing self.pre_process() # --- Actions if self.inputs.getvalue('form_action') is not None: # NB: stop is for redirection stop = self.form_action() else: stop = None # --- Html if stop is None: self.html.meta(Language=self.session.language) self.html.favicon('Core/Style/Icons/favicon.ico?v={0}'.format(time())) self.html.style('fonts') self.html.style('common') self.html.jsfile('Core/JS/jquery.js') self.html.jsfile('Core/JS/common.js') self.set_html() # ---------------------------------------------------------------------- def pre_process(self): ''' Pre-processing method Inputs: - Output: None ''' # --- Set language self.set_lang() # ---------------------------------------------------------------------- def set_html(self): ''' Sets html code Inputs: - Output: None ''' pass # ---------------------------------------------------------------------- def set_lang(self): ''' Determine spot language Inputs: - Output: None ''' # self.session.language # --- Modification lang = self.inputs.getvalue('lang') if lang is not None and lang in self.settings.LANGUAGES: # Update database self.session.DB.update('Sessions', 'lang', lang, 'sid=?', self.session.id) # Update session self.session.language = lang # --- Conversion self.LangIdx = self.settings.LANGUAGES.index(self.session.language) # ---------------------------------------------------------------------- def mlt(self, M, decode=True, newlines=True): ''' Multi-language text handler Inputs: M (tuple) The text in many languages decode (bool=true) Decode html or not newlines (bool=true) Convert newlines ('\n' -> '<br>') Output: The text in the current language ''' # --- Manage input if isinstance(M, str): tmp = M else: tmp = M[self.LangIdx] # --- Convert special chararters (decode) if decode: res = '' K = list(html.entities.entitydefs.keys()) V = list(html.entities.entitydefs.values()) for char in tmp: if char in V: res += '&{0};'.format(K[V.index(char)]) else: res += char else: res = tmp # --- Convert newlines if newlines: res = str.replace(res, '\n', '<br>') # --- Return return res # ---------------------------------------------------------------------- def truncate(self, s, limit=100, suffix='...'): ''' Smart truncate Inputs: M (tuple) The text in many languages Output: The text in the current language ''' if len(s) <= limit: return s else: return ' '.join(s[:limit+1].split(' ')[0:-1]) + suffix # ---------------------------------------------------------------------- def redirect(self, location): ''' Redirection (javascript based) Inputs: location (str) The new spot location Output None ''' self.html.javascript('document.location.href="{0}"'.format(location)) # ---------------------------------------------------------------------- def language_chooser(self): ''' Language chooser Inputs: - Output None ''' # --- Store reference ref = self.html.ref # Language container self.html.div(0, id='language') if self.session.language != 'en': self.html.a(0, "?spot={0}&lang=en".format(self.settings.get('spot'))) self.html.img(0, 'Core/Style/Icons/Flags/English.png') if self.session.language != 'fr': self.html.a(0, "?spot={0}&lang=fr".format(self.settings.get('spot'))) self.html.img(0, 'Core/Style/Icons/Flags/French.png') # --- Restore reference self.html.ref = ref # ---------------------------------------------------------------------- def main_menu(self, mid): ''' Append the main menu. Inputs: None Output: None ''' # Logo self.html.a(mid, '?spot=home') self.html.img(0, 'Core/Style/Logo.svg', id='logo') # Language chooser self.html.ref = mid self.language_chooser() self.html.a(0, '?spot=connection', id='disconnection') # Menu containers self.html.div(mid, id='menu') self.html.a(0, '?spot=settings', id="menu_Param", cls='menu_item') self.html.text(0, ("General settings", "Paramètres généraux")) self.html.a(-1, '?spot=users', id='menu_Users', cls='menu_item') self.html.text(0, ("Manage users", "Gestion des utilisateurs")) self.html.a(-1, '?spot=locations', id='menu_Locations', cls='menu_item') self.html.text(0, ("Storage locations", "Espaces de stockage"))
def createReports(sgObj, site, datacenter): www = HTML() mailObj = EMail() dates = DateString() page = [] csvpage = [] temppage = [] today = dates.today yesterday = dates.yesterday tomorrow = dates.tomorrow pagedirs = ['download', 'history'] subdirs = [today, tomorrow, yesterday] f = Files() for dir in pagedirs: f.dir = '/var/www/html/' + dir f.mkdir() for sub in subdirs: f.dir = '/var/www/html/' + dir + '/' + sub f.mkdir() csvfile = '/www/download/' + today + '/' + datacenter + site + '_failed_disks.csv' csvfileperm = '/www/download/' + datacenter + site + '_failed_disks.csv' csvlink = '<a href=/download/' + today + '/' + datacenter + site + '_failed_disks.csv>CSV</a>' yesterdaylink = '<a href=/history/' + yesterday + '/' + datacenter + site + '_Failed_disks.html>' + yesterday + '</a>' tomorrowlink = '<a href=/history/' + tomorrow + '/' + datacenter + site + '_Failed_disks.html>' + tomorrow + '</a>' htmlfile1 = '/www/history/' + today + '/' + datacenter + site + '_Failed_disks.html' tempfile = '/www/history/' + tomorrow + '/' + datacenter + site + '_Failed_disks.html' htmlfile2 = '/www/' + datacenter + site + '_Failed_disks.html' logfile = '/www/' + site + '_Failed_disks.log' log = [] reportDate = str(time.strftime("%c")) page.append(www.start_html('Failed Disk Report for ' + site)) page.append(www.EMC_Header(site, datacenter, '', csvlink)) page.append('<p><br><table align=center border=3>\n') row = ['Failed Disk Report', tomorrowlink, yesterdaylink] page.append(www.th_list(row)) page.append(www.end_table) page.append(www.start_table(3, site)) heading = [ 'Disk_ID', 'DA_Port', 'Spindle_ID', 'Tech', 'Speed', 'Vendor', 'Size', 'Failed' ] page.append(www.th_list(heading)) csvpage.append(', '.join(heading) + '\n') alertMessage = 'Disk Error...\n\n' alertMessage += ', '.join(heading) + '\n\n' alerts = 0 for disk in sgObj.FailedDisks: alerts += 1 info = sgObj.FailedDisks[disk].split() row = [ info[0], info[1], info[2], info[3], info[4], info[5], info[6], info[7] ] alertMessage += ', '.join(row) + '\n\n' csvpage.append(', '.join(row) + '\n') page.append(www.tr_list(row)) page.append(www.end_table) page.append(www.end_html) f.write_file(htmlfile2, page) f.write_file(htmlfile1, page) f.write_file(csvfile, csvpage) f.write_file(csvfileperm, csvpage) temppage.append(www.start_html()) temppage.append( www.Not_Found_Header('Report not created yet for ' + tomorrow)) temppage.append(www.end_html) f.write_file(tempfile, temppage) if alerts > 0: mailObj.subject = "WARNING: DISK ERROR - VMAX Failed Disk Alert " + site + ', ' + datacenter mailObj.message = alertMessage mailObj.send_mail() if len(sgObj.New_Failures.keys()) > 0: reportDate = str(time.strftime("%x - %X")) for failed_disk in sgObj.New_Failures.keys(): log.append(reportDate + " :" + mailObj.subject + " " + failed_disk + "\n") f.write_file(logfile, log)
def createReports(sgObj, site, datacenter): # # Create directories if they don't exist orange = '#F7EE6F' green = '#69F24E' dir = "/www/" + site + "/SG/" if not os.path.isdir(dir): subprocess.call(["mkdir", dir]) dir = '/www/' + site + '/CSV' if not os.path.isdir(dir): subprocess.call(["mkdir", dir]) # # reportDate = str(time.strftime("%c")) GB = float(sgObj.ProvisionedCapacity) / 1024 ProvisionedGB = "%.2f" % GB info1 = 'Total Porvisioned(GB)=' + str(ProvisionedGB) www = HTML() html_index = '/www/' + site + '/index.html' sgSummCSV = '/www/' + site + '/CSV/' + site + '_SG_Summary.csv' f_index = open(html_index, 'w') f_SummCSV = open(sgSummCSV, 'w') f_SummCSV.write( "Storage Group,SLO Policy,Capacity GB,Masking View,Max IOPS,Max MB/s\n" ) linkpath = "/" + site + "/CSV/" + site + '_SG_Summary.csv' sgSummLink = '<a href=' + linkpath + '>Summary CSV</a>\n' f_index.write(www.start_html('SG Summary')) f_index.write(www.EMC_Header(site, datacenter, info1, sgSummLink)) f_index.write(www.start_table()) f_index.write(www.end_table) fpTables = {} policies = {} for sg in sgObj.SGs: # color = '' link = "/" + site + "/SG/" + sg + ".html" sgGB = float(sgObj.SG2Capacity[sg]) / 1024 sgProvisionedGB = "%.2f" % sgGB MVs = sgObj.SGinMV[sg] fp = sgObj.SGinSLO[sg] policies[fp] = 1 if not fp in fpTables: fpTables[fp] = [] IOPS_LIMIT = str(sgObj.SG_IOPS_Limit[sg]) MB_LIMIT = str(sgObj.SG_MB_Limit[sg]) if MVs.upper() == 'NO': color = orange rowlist = [ "<a href=" + link + '>' + sg + "</a>", fp, str(sgProvisionedGB), MVs, IOPS_LIMIT, MB_LIMIT ] SGhtml = www.tr_list(rowlist, color) fpTables[fp].append(SGhtml) f_SummCSV.write(sg + ',' + fp + ',' + str(sgProvisionedGB) + ',' + MVs + ',' + IOPS_LIMIT + ',' + MB_LIMIT + "\n") # go ahead and write out the sg detail HTML page. sgfile = "/www/" + site + "/SG/" + sg + ".html" sgCSV = "/www/" + site + "/CSV/" + site + '_' + sg + ".csv" linkpath = "/" + site + "/CSV/" + site + '_' + sg + ".csv" link1 = '<a href=' + linkpath + '>SG CSV</a>\n' f_sg = open(sgfile, 'w') f_sgCSV = open(sgCSV, 'w') f_sgCSV.write('Storage Group Report for ' + sg + '\n\n\n') f_sg.write(www.start_html('SG Detail')) f_sg.write(www.EMC_Header(site, datacenter, '', link1)) html = "<p><H3><center>Detailed Storage Report for " + sg + " SSC_VMAX40K_1794</center></H3>\n" f_sg.write(html) f_sg.write(www.start_table()) f_sg.write(www.tr + www.th + "Storage Group<th>SLO Policy<TH>Capacity GB</tr>\n") html = www.tr + www.td + sg + www.td + fp + www.td + str( sgProvisionedGB) + "\n" f_sg.write(html) f_sg.write(www.end_table) f_sg.write(www.start_table(3, 'Device List')) f_sg.write(www.tr + www.th + "Device<th>Capacity GB</tr>\n") f_sgCSV.write("Volume,Capacity GB\n") for device in sgObj.SGs[sg]: devGB = float(sgObj.SGs[sg][device]) / 1024 dev_formatted = "%.2f" % devGB html = www.tr + www.td + device + www.td + str( dev_formatted) + "\n" f_sg.write(html) f_sgCSV.write(device + ',' + str(dev_formatted) + '\n') f_sg.write(www.end_table) f_sg.write(www.end_html) f_sg.close() f_sgCSV.close() for fp in policies: f_index.write(www.start_table(3, 'Groups with SLO ' + fp + ' Policy')) f_index.write( "<tr><th>Storage Group<th>SLO Policy<TH>Capacity GB<TH>Masking View<TH>IOPS Limit<TH>MB/s Limit</tr>\n" ) for line in fpTables[fp]: f_index.write(line) f_index.write(www.end_table) f_index.write(www.end_html) f_index.close() f_SummCSV.close()
class Html_Builder(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.options_list = [ "table", "tr", "td", "h1", "h2", "h3", "h4", "h5", "h6", "br", "span", "div", "a", "link", "nav", "title", "abbr", "address", "code", "em", "progress", "strong", "sub", "sup", "time", "u", "var", "samp", "small", "q", "mark", "s", "pre", "ins", "form", "input", "button", "fieldset", "legend", "label", "datalist", "option", "optgroup", "textarea", "keygen", "output", "select", "img", "map", "area", "canvas", "iframe", "figure", "figcaption", "audio", "source", "track", "video", "ul", "li", "ol", "dl", "dt", "dd", "menu", "menuitem", "caption", "thead", "tbody", "tfoot", "col", "colgroup", "style", "header", "footer", "main", "section", "article", "aside", "details", "dialog", "summary", "head", "meta", "base", "script", "noscript", "embed", "object", "param", "blockquote", "hr", "b", "bdi", "bdo", "dfn", "cite", "del", "q", "meter", "rp", "rt", "ruby" ] self.options_list.sort() self.add_item = False self.nested = False self.delete_something = False self.meta = False self.temp_dict = {} self.order_number = 1 self.html_object = HTML() self.CheckVar1 = IntVar() self.CheckVar2 = IntVar() self.C1 = Checkbutton(root, text = "Full HTML", variable = self.CheckVar1, \ command = self.html_full, onvalue = 1, offvalue = 0, height=4, \ width = 15) self.C2 = Checkbutton(root, text = "Has Body", variable = self.CheckVar2, \ command = self.html_has_body, onvalue = 1, offvalue = 0, height=4, \ width = 15) self.C1.pack() self.C2.pack() self.generate_button = Button(root, text='Generate HTML', command= self.make_file) self.generate_button.place(x=30, y=115) self.add_element_button = Button(root, text='Add Element', command = self.add_html_element) self.add_element_button.place(x=30, y=15) self.order_button = Button(root, text='Order Elements', command = self.order_html) self.order_button.place(x=30, y=75) self.delete_button = Button(root, text='Delete Element', command = self.delete_html) self.delete_button.place(x=30, y=45) def html_has_body(self): if(self.CheckVar2.get() == 1): self.html_object.has_body = True else: self.html_object.has_body = False def html_full(self): if(self.CheckVar1.get() == 1): self.html_object.is_full_html = True else: self.html_object.is_full_html = False def el_is_nested(self): if(self.check_is_nested.get() == 1): self.nested = True else: self.nested = False def make_file(self): self.html_object.generate_html() self.html_object.generate_file() def add_html_element(self): if(self.add_item == False and self.delete_something == False): self.option = StringVar() self.text_element = StringVar() self.option_list_pane = apply(OptionMenu, (root, self.option) + tuple(self.options_list)) self.option.set(self.options_list[0]) self.option_list_pane.place(x=20, y=200) self.add_button = Button(root, text='Add', width=7, command = self.add) self.add_button.place(x=175, y=450) self.text_element_box = Entry(root, textvariable=self.text_element) self.text_element_box.place(x=130, y=200) self.check_is_nested = IntVar() self.check_is_nested_button = Checkbutton(root, text = "Is Nested Element", variable = self.check_is_nested, \ command = self.el_is_nested, onvalue = 1, offvalue = 0, height=2, \ width = 14) self.check_is_nested_button.place(x=260, y=200) self.has_meta = IntVar() self.has_meta_button = Checkbutton(root, text = "Has Attributes", variable = self.has_meta, \ command = self.el_has_meta, onvalue = 1, offvalue = 0, height=2, \ width = 14) self.has_meta_button.place(x=260, y=275) self.add_item = True else: toplevel = Toplevel() label1 = Label(toplevel, text='Please finish your current action!', height=5, width=50) label1.pack() def el_has_meta(self): if(self.has_meta.get() == 1): self.meta = True self.meta_label = Label(root, text='Attribute Text:') self.meta_label.place(x=20, y=275) self.add_meta_button = Button(root, text='Add Attribute', width=11, command = self.add_meta) self.add_meta_button.place(x=115, y=330) self.value_label = Label(root, text='Attribute Value:') self.value_label.place(x=20, y=300) self.meta_text = StringVar() self.meta_element_box = Entry(root, textvariable=self.meta_text) self.meta_element_box.place(x=115, y=275) self.value_text = StringVar() self.value_box = Entry(root, textvariable=self.value_text) self.value_box.place(x=115, y=300) else: self.meta = False def add_meta(self): self.temp_dict[self.meta_text.get()] = self.value_text.get() print self.temp_dict[self.meta_text.get()] #self.html_object.meta_dict = self.temp_dict def order_html(self): square = self.html_object.is_full_html def delete_html(self): if not self.html_object.element_list: toplevel2 = Toplevel() label1 = Label(toplevel2, text='There are no items to delete', height=5, width=50) label1.pack() elif(self.add_item): toplevel3 = Toplevel() label1 = Label(toplevel3, text='Please finish your current action!', height=5, width=50) label1.pack() else: self.delete_something = True self.w = Spinbox(root, values=tuple(self.html_object.get_element_list()), width=30) self.w.place(x=175, y=225) self.delete_button = Button(root, text='Delete', width=7, command = self.delete) self.delete_button.place(x=175, y = 275) def delete(self): self.deleted_object = self.w.get() self.html_object.del_element(self.deleted_object) self.delete_something = False self.w.destroy() self.delete_button.destroy() def add(self): element_object = html_element(self.nested, self.option.get(), self.text_element.get(), self.order_number, self.temp_dict) temp = self.html_object.get_top_element_nested_level() if (element_object.is_nested): element_object.nested_level = temp + 1 print element_object.nested_level else: temp = 0 element_object.nested_level = 0 self.html_object.add_element(element_object) self.order_number += 1 #destroy all of the add options once the object has been added self.add_item = False self.nested = False self.option_list_pane.destroy() self.add_button.destroy() self.text_element_box.destroy() self.check_is_nested_button.destroy() self.has_meta_button.destroy() self.value_box.destroy() self.value_label.destroy() if (self.meta): self.meta = False self.meta_label.destroy() self.meta_element_box.destroy() self.add_meta_button.destroy()
def createReports(sgObj, site, datacenter): www = HTML() mailObj = EMail() dates = DateString() tiers = ['EFD', 'FC', 'SATA'] alertLimits = {} alertLimits['EFD'] = 99 alertLimits['FC'] = 80 alertLimits['SATA'] = 85 page = [] csvpage = [] temppage = [] today = dates.today yesterday = dates.yesterday tomorrow = dates.tomorrow pagedirs = ['download', 'history'] subdirs = [today, tomorrow, yesterday] f = Files() for dir in pagedirs: f.dir = '/var/www/html/' + dir f.mkdir() for sub in subdirs: f.dir = '/var/www/html/' + dir + '/' + sub f.mkdir() csvfile = '/www/download/' + today + '/' + site + '_pools.csv' csvfileperm = '/www/download/' + site + '_pools.csv' csvlink = '<a href=/download/' + today + '/' + site + '_pools.csv>CSV</a>' yesterdaylink = '<a href=/history/' + yesterday + '/' + datacenter + site + '_EMC_Summary.html>' + yesterday + '</a>' tomorrowlink = '<a href=/history/' + tomorrow + '/' + datacenter + site + '_EMC_Summary.html>' + tomorrow + '</a>' htmlfile1 = '/www/history/' + today + '/' + datacenter + site + '_EMC_Summary.html' tempfile = '/www/history/' + tomorrow + '/' + datacenter + site + '_EMC_Summary.html' htmlfile2 = '/www/' + datacenter + site + '_EMC_Summary.html' reportDate = str(time.strftime("%c")) page.append(www.start_html('Thin Pool Report for ' + site)) page.append(www.EMC_Header(site, datacenter, '', csvlink)) page.append('<p><br><table align=center border=3>\n') row = ['EMC Storage Summary Report', tomorrowlink, yesterdaylink] page.append(www.th_list(row)) page.append(www.end_table) page.append(www.start_table(3, site)) heading = [ 'Pool', 'Capacity', 'Used', 'Percent Used', 'Free', 'Provisioned', 'Subscription', 'Subscription Limit', 'PRC', 'Technology', 'Protection' ] page.append(www.th_list(heading)) total_usable = 0 total_provisioned = 0 total_used = 0 total_free = 0 #csvpage.append('Thin Pool Report for ' + site + '\n\n') csvpage.append(', '.join(heading) + '\n') alertMessage = 'The following pools exceed set thresholds...\n\n' alerts = 0 for tier in tiers: for pool in sgObj.pools.keys(): comparepool = str(pool) comparepool = pool.upper() if tier in comparepool: ########## compression = sgObj.pooldetails[pool]['COMPRESSION'] subscription_limit = sgObj.pooldetails[pool][ 'SUBSCRIPTION_LIMIT'] PRC = sgObj.pooldetails[pool]['PRC'] tech = sgObj.pooldetails[pool]['TECH'] protection = sgObj.pooldetails[pool]['LAYOUT'] ########## usable = float(sgObj.pools[pool]['total_usable_tracks_gb']) used = float(sgObj.pools[pool]['total_used_tracks_gb']) percent_used = sgObj.pools[pool]['percent_full'] free = float(sgObj.pools[pool]['total_free_tracks_gb']) subscription = sgObj.pools[pool]['subs_percent'] usable = int(round(usable, 0)) used = int(round(used, 0)) free = int(round(free, 0)) if int(subscription) == 0: provisioned = 0 else: provisioned = usable * (float(subscription) / 100) total_provisioned += provisioned total_usable += usable total_used += used total_free += free html = www.tr if int(percent_used) >= alertLimits[tier]: html = www.alerttr alertMessage += "Thin pool " + comparepool + " is " + str( percent_used) + "% used.\n" alertMessage += str(free) + " GB free remain in the pool\n" alertMessage += " The threshold for " + comparepool + ' is set to ' + str( alertLimits[tier]) + '%\n\n' alerts += 1 row = [ pool, str(usable), str(used), str(percent_used), str(free), str(provisioned), subscription, subscription_limit, PRC, tech, protection ] csvpage.append(', '.join(row) + '\n') page.append(www.tr_list(row)) total_pct_used = int((int(total_used) / float(total_usable)) * 100) total_subscription = int( (int(total_provisioned) / float(total_usable)) * 100) row = [ 'Totals', str(total_usable), str(total_used), str(total_pct_used), str(total_free), str(total_provisioned), str(total_subscription), '___', '___', '___', '___' ] page.append(www.tr_list(row)) page.append(www.end_table) page.append(www.end_html) f.write_file(htmlfile2, page) f.write_file(htmlfile1, page) f.write_file(csvfile, csvpage) f.write_file(csvfileperm, csvpage) temppage.append(www.start_html()) temppage.append( www.Not_Found_Header('Report not created yet for ' + tomorrow)) temppage.append(www.end_html) f.write_file(tempfile, temppage) if alerts > 0: mailObj.subject = "Storage Capacity Alert, " + site + ', ' + datacenter mailObj.message = alertMessage mailObj.send_mail()
def __init__(self, **kwargs): if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-TabBar" # this is awkward: HorizontalPanel is the composite, # so we either the element here, and pass it in to HorizontalPanel. element = None if kwargs.has_key('Element'): element = kwargs.pop('Element') self.panel = HorizontalPanel(Element=element) self.selectedTab = None self.tabListeners = [] self.panel.setVerticalAlignment(HasAlignment.ALIGN_BOTTOM) first = HTML(" ", True) rest = HTML(" ", True) first.setStyleName("gwt-TabBarFirst") rest.setStyleName("gwt-TabBarRest") first.setHeight("100%") rest.setHeight("100%") self.panel.add(first) self.panel.add(rest) first.setHeight("100%") self.panel.setCellHeight(first, "100%") self.panel.setCellWidth(rest, "100%") Composite.__init__(self, self.panel, **kwargs) self.sinkEvents(Event.ONCLICK)
def test_html_object_get_element(self): html_obj = HTML() test_element = html_element() html_obj.add_element(test_element) self.assertEqual(test_element, html_obj.get_element(0))
def createDemandReport(fpObj, sgObj, site, datacenter): dates = DateString() htmlpage = [] csvpage = [] temppage = [] www = HTML() f = Files() today = dates.today yesterday = dates.yesterday tomorrow = dates.tomorrow pagedirs = ['download', 'history'] subdirs = [today, tomorrow, yesterday] f = Files() for dir in pagedirs: f.dir = '/var/www/html/' + dir f.mkdir() for sub in subdirs: f.dir = '/var/www/html/' + dir + '/' + sub f.mkdir() csvfile = '/www/download/' + today + '/' + site + '_fast_demand.csv' csvfileperm = '/www/download/' + site + '_fast_demand.csv' csvlink = '<a href=/download/' + today + '/' + site + '_fast_demand.csv>CSV</a>' yesterdaylink = '<a href=/history/' + yesterday + '/' + datacenter + '_fast_demand.html>' + yesterday + '</a>' tomorrowlink = '<a href=/history/' + tomorrow + '/' + datacenter + '_fast_demand.html>' + tomorrow + '</a>' htmlfile1 = '/www/history/' + today + '/' + datacenter + '_fast_demand.html' tempfile = '/www/history/' + tomorrow + '/' + datacenter + '_fast_demand.html' htmlfile2 = '/www/' + datacenter + '_fast_demand.html' html_index = '/www/' + site + '/fast_demand.html' fastCSV = '/www/' + site + '/CSV/' + site + '_fast_demand.csv' htmlpage.append(www.start_html('FAST Demand')) htmlpage.append(www.EMC_Header(site, datacenter, '', csvlink)) demandReportPath = '/' + site + '/fast_demand.html' DemandReportLink = '<a href=' + demandReportPath + '>FAST-VP Demand Report</a>\n' fastReportPath = '/' + site + '/fast.html' fastReportLink = '<a href=' + fastReportPath + '>FAST-VP Policy Report</a>\n' htmlpage.append('<p><br><table align=center border=3>\n') row = [fastReportLink, DemandReportLink] htmlpage.append(www.th_list(row)) htmlpage.append(www.end_table) htmlpage.append('<p><br><table align=center border=3>\n') row = ['FAST Demand Report', tomorrowlink, yesterdaylink] htmlpage.append(www.th_list(row)) htmlpage.append(www.end_table) csvpage.append('FAST-VP Report for ' + site + '\n\n') htmlpage.append(www.start_table(3, 'FAST-VP Demand report')) heading = ['SG_Name', 'Policy'] for tier in fpObj.tiernames: heading.append(tier) heading.append('SG_USED') heading.append('SG_PROVISIONED') htmlpage.append(www.th_list(heading)) csvpage.append(', '.join(heading) + '\n') for sg in fpObj.tiers: policy = fpObj.Associations[sg] GB = float(sgObj.SG2Capacity[sg]) / 1024 ProvisionedGB = "%.2f" % GB sg_provisioned = str(ProvisionedGB) + ' GB' # sglinkpath = "/" + site + "/SG/" + sg + ".html" sglink = '<a href=' + sglinkpath + '>' + str(sg) + '</a>' line = [sglink, policy] line2 = [sg, policy] for tiername in fpObj.tiernames: if tiername in fpObj.tiers[sg]: line.append(fpObj.tiers[sg][tiername]) line2.append(fpObj.tiers[sg][tiername]) else: line.append('0') line2.append('0') # The next 5 lines add total used and provisioned columns... sg_total = str(fpObj.tiers[sg]['SG_USED']) + ' GB' line.append(sg_total) line2.append(sg_total) line.append(sg_provisioned) line2.append(sg_provisioned) # csvpage.append(', '.join(line2) + '\n') htmlpage.append(www.tr_list(line)) htmlpage.append(www.end_table) htmlpage.append(www.end_html) f.write_file(html_index, htmlpage) f.write_file(fastCSV, csvpage) f.write_file(htmlfile2, htmlpage) f.write_file(htmlfile1, htmlpage) f.write_file(csvfile, csvpage) f.write_file(csvfileperm, csvpage) temppage.append(www.start_html()) temppage.append( www.Not_Found_Header('Report not created yet for ' + tomorrow)) temppage.append(www.end_html) f.write_file(tempfile, temppage)
def createReports(sgObj,site,datacenter): www = HTML() mailObj = EMail() dates = DateString() tiers = ['EFD','FC','SATA'] alertLimits = {} alertLimits['EFD'] = 99 alertLimits['FC'] = 80 alertLimits['SATA'] = 85 page = [] csvpage = [] temppage = [] today = dates.today yesterday = dates.yesterday tomorrow = dates.tomorrow pagedirs = ['download','history'] subdirs = [today,tomorrow,yesterday] f = Files() for dir in pagedirs: f.dir = '/var/www/html/' + dir f.mkdir() for sub in subdirs: f.dir = '/var/www/html/' + dir + '/' + sub f.mkdir() csvfile = '/www/download/' + today + '/' + site + '_pools.csv' csvfileperm = '/www/download/' + site + '_pools.csv' csvlink = '<a href=/download/' + today + '/' + site + '_pools.csv>CSV</a>' yesterdaylink = '<a href=/history/' + yesterday + '/' + datacenter + site + '_EMC_Summary.html>' + yesterday + '</a>' tomorrowlink = '<a href=/history/' + tomorrow + '/' + datacenter + site + '_EMC_Summary.html>' + tomorrow + '</a>' htmlfile1 = '/www/history/' + today + '/' + datacenter + site + '_EMC_Summary.html' tempfile = '/www/history/' + tomorrow + '/' + datacenter + site + '_EMC_Summary.html' htmlfile2 = '/www/' + datacenter + site + '_EMC_Summary.html' reportDate = str(time.strftime("%c")) page.append(www.start_html('Thin Pool Report for ' + site)) page.append(www.EMC_Header(site,datacenter,'',csvlink)) page.append('<p><br><table align=center border=3>\n') row = ['EMC Storage Summary Report',tomorrowlink,yesterdaylink] page.append(www.th_list(row)) page.append(www.end_table) page.append(www.start_table(3,site)) heading = ['Pool','Capacity','Used','Percent Used','Free','Provisioned','Subscription','Subscription Limit','PRC','Technology','Protection'] page.append(www.th_list(heading)) total_usable = 0 total_provisioned = 0 total_used = 0 total_free = 0 #csvpage.append('Thin Pool Report for ' + site + '\n\n') csvpage.append(', '.join(heading) + '\n') alertMessage = 'The following pools exceed set thresholds...\n\n' alerts = 0 for tier in tiers: for pool in sgObj.pools.keys(): comparepool = str(pool) comparepool = pool.upper() if tier in comparepool: ########## compression = sgObj.pooldetails[pool]['COMPRESSION'] subscription_limit = sgObj.pooldetails[pool]['SUBSCRIPTION_LIMIT'] PRC = sgObj.pooldetails[pool]['PRC'] tech = sgObj.pooldetails[pool]['TECH'] protection = sgObj.pooldetails[pool]['LAYOUT'] ########## usable = float(sgObj.pools[pool]['total_usable_tracks_gb']) used = float(sgObj.pools[pool]['total_used_tracks_gb']) percent_used = sgObj.pools[pool]['percent_full'] free = float(sgObj.pools[pool]['total_free_tracks_gb']) subscription = sgObj.pools[pool]['subs_percent'] usable = int(round(usable,0)) used = int(round(used,0)) free = int(round(free,0)) if int(subscription) == 0: provisioned = 0; else: provisioned = usable * ( float(subscription) / 100) total_provisioned += provisioned total_usable += usable total_used += used total_free += free html = www.tr if int(percent_used) >= alertLimits[tier]: html = www.alerttr alertMessage += "Thin pool " + comparepool + " is " + str(percent_used) + "% used.\n" alertMessage += str(free) + " GB free remain in the pool\n" alertMessage += " The threshold for " + comparepool + ' is set to ' + str(alertLimits[tier]) + '%\n\n' alerts += 1 row = [pool,str(usable),str(used),str(percent_used),str(free),str(provisioned),subscription,subscription_limit,PRC,tech,protection] csvpage.append(', '.join(row) + '\n') page.append(www.tr_list(row)) total_pct_used = int((int(total_used) / float(total_usable)) * 100) total_subscription = int((int(total_provisioned) / float(total_usable)) * 100) row = ['Totals',str(total_usable),str(total_used),str(total_pct_used),str(total_free),str(total_provisioned),str(total_subscription),'___','___','___','___'] page.append(www.tr_list(row)) page.append(www.end_table) page.append(www.end_html) f.write_file(htmlfile2,page) f.write_file(htmlfile1,page) f.write_file(csvfile,csvpage) f.write_file(csvfileperm,csvpage) temppage.append(www.start_html()) temppage.append(www.Not_Found_Header('Report not created yet for '+tomorrow)) temppage.append(www.end_html) f.write_file(tempfile,temppage) if alerts > 0: mailObj.subject = "Storage Capacity Alert, " + site + ', ' + datacenter mailObj.message = alertMessage mailObj.send_mail()
class Spot: """ The Spot class """ # ---------------------------------------------------------------------- def __init__(self, settings, session, inputs): # --- Definitions self.settings = settings self.session = session self.inputs = inputs self.html = HTML(self) self.display = True # --- Pre-processing self.pre_process() # --- Actions if self.inputs.getvalue("form_action") is not None: # NB: stop is for redirection stop = self.form_action() else: stop = None # --- Html if stop is None: self.html.meta(Language=self.session.language) self.html.favicon("Core/Style/Icons/favicon.ico?v={0}".format(time())) self.html.style("fonts") self.html.style("common") self.html.jsfile("Core/JS/jquery.js") self.html.jsfile("Core/JS/common.js") self.set_html() # ---------------------------------------------------------------------- def pre_process(self): """ Pre-processing method Inputs: - Output: None """ # --- Set language self.set_lang() # ---------------------------------------------------------------------- def set_html(self): """ Sets html code Inputs: - Output: None """ pass # ---------------------------------------------------------------------- def set_lang(self): """ Determine spot language Inputs: - Output: None """ # self.session.language # --- Modification lang = self.inputs.getvalue("lang") if lang is not None and lang in self.settings.LANGUAGES: # Update database self.session.DB.update("Sessions", "lang", lang, "sid=?", self.session.id) # Update session self.session.language = lang # --- Conversion self.LangIdx = self.settings.LANGUAGES.index(self.session.language) # ---------------------------------------------------------------------- def mlt(self, M, decode=True, newlines=True): """ Multi-language text handler Inputs: M (tuple) The text in many languages decode (bool=true) Decode html or not newlines (bool=true) Convert newlines ('\n' -> '<br>') Output: The text in the current language """ # --- Manage input if isinstance(M, str): tmp = M else: tmp = M[self.LangIdx] # --- Convert special chararters (decode) if decode: res = "" K = list(html.entities.entitydefs.keys()) V = list(html.entities.entitydefs.values()) for char in tmp: if char in V: res += "&{0};".format(K[V.index(char)]) else: res += char else: res = tmp # --- Convert newlines if newlines: res = str.replace(res, "\n", "<br>") # --- Return return res # ---------------------------------------------------------------------- def truncate(self, s, limit=100, suffix="..."): """ Smart truncate Inputs: M (tuple) The text in many languages Output: The text in the current language """ if len(s) <= limit: return s else: return " ".join(s[: limit + 1].split(" ")[0:-1]) + suffix # ---------------------------------------------------------------------- def redirect(self, location): """ Redirection (javascript based) Inputs: location (str) The new spot location Output None """ self.html.javascript('document.location.href="{0}"'.format(location)) # ---------------------------------------------------------------------- def language_chooser(self): """ Language chooser Inputs: - Output None """ # --- Store reference ref = self.html.ref # Language container self.html.div(0, id="language") if self.session.language != "en": self.html.a(0, "?spot={0}&lang=en".format(self.settings.get("spot"))) self.html.img(0, "Core/Style/Icons/Flags/English.png") if self.session.language != "fr": self.html.a(0, "?spot={0}&lang=fr".format(self.settings.get("spot"))) self.html.img(0, "Core/Style/Icons/Flags/French.png") # --- Restore reference self.html.ref = ref # ---------------------------------------------------------------------- def navbar(self, tree, main, last, page=()): """ Append a navigation bar. Inputs: - parent (int) The identifier of the most remote element Output: None """ # Append style and javascript to the head self.html.style("navbar") self.html.jsfile("Core/JS/navbar.js") # Main contener self.html.div(main, id="navbar") # Get parent list P = int(last) Plist = [] while True: Plist.extend([P]) if P == 0: break else: tmp = tree.single("SELECT parent FROM Elements WHERE id=?", P) P = tmp["parent"] # Display navbar for P in reversed(Plist): ref = self.html.ref if P: # --- Spacer tmp = self.html.div(0, cls="nav_cont") self.html.a(tmp, "#", id="nav_spacer_{0}".format(P), cls="nav_spacer") self.html.text(0, "▼", decode=False) # --- Element res = tree.single("SELECT * FROM Elements WHERE id=?", P) if res["type"] == "group": if P == int(last) and not page: if res["name"]: self.html.p(tmp, cls="nav_elm_group nav_elm_mod", contenteditable="true") self.html.text(0, res["name"]) else: self.html.p(tmp, cls="nav_elm_group nav_elm_mod nav_elm_mod_empty", contenteditable="true") self.html.span(0, cls="nav_undef") self.html.text(0, "Group {0}".format(P)) else: self.html.a(tmp, "?spot=home&parent={0}".format(P), cls="nav_elm_group") if res["name"]: self.html.text(0, res["name"]) else: self.html.span(0, cls="nav_undef") self.html.text(0, "Group {0}".format(P)) elif res["type"] == "note": if P == int(last) and not page: if res["name"]: self.html.p(tmp, cls="nav_elm_note nav_elm_mod", contenteditable="true") self.html.text(0, res["name"]) else: self.html.p(tmp, cls="nav_elm_note nav_elm_mod nav_elm_mod_empty", contenteditable="true") self.html.span(0, cls="nav_undef") self.html.text(0, "Note {0}".format(P)) else: self.html.a(tmp, "?spot=note¬e={0}".format(P), cls="nav_elm_note") if res["name"]: self.html.text(0, res["name"]) else: self.html.span(0, cls="nav_undef") self.html.text(0, "Note {0}".format(P)) # --- List tmp = self.html.div(tmp, id="nav_list_{0}".format(P), cls="nav_list") for alt in tree.multi( "SELECT * FROM Elements WHERE id!=? AND parent=(SELECT parent FROM Elements WHERE id=?)", P, P ): if alt["type"] == "group": self.html.a(tmp, "?spot=home&parent={0}".format(alt["id"]), cls="nav_menu_item") self.html.img(0, "Core/Style/Icons/navbar_group.png", cls="nav_icon_group") elif alt["type"] == "note": self.html.a(tmp, "?spot=note¬e={0}".format(alt["id"]), cls="nav_menu_item") self.html.img(0, "Core/Style/Icons/navbar_note.png", cls="nav_icon_note") if alt["name"]: self.html.text(0, alt["name"]) elif alt["type"] == "note": self.html.span(0, cls="nav_undef") self.html.text(0, "Note {0}".format(alt["id"])) elif alt["type"] == "group": self.html.span(0, cls="nav_undef") self.html.text(0, "Group {0}".format(alt["id"])) else: self.html.a(0, "?spot=home", cls="nav_elm") self.html.img(0, "Core/Style/Icons/navbar_home.png", id="nav_icon_home") self.html.text(0, "Home") self.html.ref = ref if page: # --- Get page infos note = page[0] nid = page[1] pid = page[2] # --- Spacer tmp = self.html.div(0, cls="nav_cont") self.html.a(tmp, "#", id="nav_spacer_page", cls="nav_spacer_page") self.html.text(0, "▼", decode=False) # --- Element res = note.single("SELECT * FROM Pages WHERE id=?", pid) if res["name"]: self.html.p(tmp, cls="nav_elm_page nav_elm_mod", contenteditable="true") self.html.text(0, res["name"]) else: self.html.p(tmp, cls="nav_elm_page nav_elm_mod nav_elm_mod_empty", contenteditable="true") self.html.span(0, cls="nav_undef") self.html.text(0, "Page {0}".format(res["position"])) # --- List tmp = self.html.div(tmp, id="nav_list_page", cls="nav_list") for res in note.multi("SELECT * FROM Pages ORDER BY position"): self.html.a( tmp, "?spot=page¬e={0}&page={1}".format(nid, res["id"]), id="nav_menu_item_{0}".format(res["id"]), cls="nav_menu_item_page", ) if res["name"]: self.html.text(0, "{0}. {1}".format(res["position"], res["name"])) else: self.html.text( 0, '{0}. <span class="nav_undef">Page {1}</span>'.format(res["position"], res["position"]), decode=False, )
def createReports(sgObj,site,datacenter): www = HTML() mailObj = EMail() swObj = BRCD() swObj.get_connection_map() dates = DateString() page = [] csvpage = [] temppage = [] today = dates.today yesterday = dates.yesterday tomorrow = dates.tomorrow pagedirs = ['download','history'] subdirs = [today,tomorrow,yesterday] f = Files() for dir in pagedirs: f.dir = '/var/www/html/' + dir f.mkdir() for sub in subdirs: f.dir = '/var/www/html/' + dir + '/' + sub f.mkdir() csvfile = '/www/download/' + today + '/' + site + '_FA.csv' csvlink = '<a href=/download/' + today + '/' + site + '_FA.csv>CSV</a>' htmlfile = '/www/' + site + '/FA_Ports.html' reportDate = str(time.strftime("%c")) page.append(www.start_html('FA Port Report for ' + site)) page.append(www.EMC_Header(site,datacenter,'',csvlink)) page.append(www.start_table(3,site)) heading = ['FA Port','WWN','Device Count', 'Switch', 'Portname', 'Port'] page.append(www.th_list(heading)) csvpage.append('FA Port Report for ' + site + '\n\n') csvpage.append(', '.join(heading) + '\n') for FAPORT in sorted(sgObj.FA2WWNmap): port = str(FAPORT) wwn = str(sgObj.FA2WWNmap[FAPORT]) if wwn.lower() in swObj.connectionmap: fields = swObj.connectionmap[wwn.lower()] switchname = fields[0] switchportname = fields[1] switchport = fields[2] else: switchname = 'Not_Connected' switchportname = 'Not_Connected' switchport = 'Not_Connected' if 'Total' in port: color = '#C7C5C6' switchname = '---' switchportname = '---' switchport = '---' else: color = '#DEF2FA' dev_count = str(sgObj.FA_Device_Count[FAPORT]) row = [port,wwn, dev_count, switchname, switchportname, switchport] csvpage.append(', '.join(row) + '\n') page.append(www.tr_list(row,color)) page.append(www.end_table) page.append(www.end_html) f.write_file(htmlfile,page) f.write_file(csvfile,csvpage)
def createReports(sgObj,site,datacenter): www = HTML() mailObj = EMail() dates = DateString() page = [] csvpage = [] temppage = [] today = dates.today yesterday = dates.yesterday tomorrow = dates.tomorrow pagedirs = ['download','history'] subdirs = [today,tomorrow,yesterday] f = Files() for dir in pagedirs: f.dir = '/var/www/html/' + dir f.mkdir() for sub in subdirs: f.dir = '/var/www/html/' + dir + '/' + sub f.mkdir() csvfile = '/www/download/' + today + '/' + site + '_failed_disks.csv' csvfileperm = '/www/download/' + site + '_failed_disks.csv' csvlink = '<a href=/download/' + today + '/' + site + '_failed_disks.csv>CSV</a>' yesterdaylink = '<a href=/history/' + yesterday + '/' + datacenter + '_Failed_disks.html>' + yesterday + '</a>' tomorrowlink = '<a href=/history/' + tomorrow + '/' + datacenter + '_Failed_disks.html>' + tomorrow + '</a>' htmlfile1 = '/www/history/' + today + '/' + datacenter + '_Failed_disks.html' tempfile = '/www/history/' + tomorrow + '/' + datacenter + '_Failed_disks.html' htmlfile2 = '/www/' + datacenter + site + '_Failed_disks.html' logfile = '/www/' + site + '_Failed_disks.log' log = [] reportDate = str(time.strftime("%c")) page.append(www.start_html('Failed Disk Report for ' + site)) page.append(www.EMC_Header(site,datacenter,'',csvlink)) page.append('<p><br><table align=center border=3>\n') row = ['Failed Disk Report',tomorrowlink,yesterdaylink] page.append(www.th_list(row)) page.append(www.end_table) page.append(www.start_table(3,site)) heading = ['Disk_ID','DA_Port','Spindle_ID','Tech','Speed','Vendor','Size','Failed'] page.append(www.th_list(heading)) csvpage.append(', '.join(heading) + '\n') alertMessage = 'Disk Error...\n\n' alertMessage += ', '.join(heading) + '\n\n' alerts = 0 for disk in sgObj.FailedDisks: alerts += 1 info = sgObj.FailedDisks[disk].split() row = [info[0],info[1],info[2],info[3],info[4],info[5],info[6],info[7]] alertMessage += ', '.join(row) + '\n\n' csvpage.append(', '.join(row) + '\n') page.append(www.tr_list(row)) page.append(www.end_table) page.append(www.end_html) f.write_file(htmlfile2,page) f.write_file(htmlfile1,page) f.write_file(csvfile,csvpage) f.write_file(csvfileperm,csvpage) temppage.append(www.start_html()) temppage.append(www.Not_Found_Header('Report not created yet for '+tomorrow)) temppage.append(www.end_html) f.write_file(tempfile,temppage) if alerts > 0: mailObj.subject = "WARNING: DISK ERROR - VMAX Failed Disk Alert " + site + ', ' + datacenter mailObj.message = alertMessage mailObj.send_mail() if len(sgObj.New_Failures.keys()) > 0: reportDate = str(time.strftime("%x - %X")) for failed_disk in sgObj.New_Failures.keys(): log.append(reportDate + " :" + mailObj.subject + " " + failed_disk + "\n") f.write_file(logfile,log)
def outputHtmlUserlist(fname, db, keys): h = HTML() head = h.head("") with h.body(""): with h.table(border='1', newlines=True): with h.colgroup: h.col(span="1", style="width: 64px;") h.col(span="1", style="width: 130px;") h.col(span="1", style="width: 250px;") h.col(span="1", style="width: 250px;") with h.tr: h.th("avatar") h.th("username") h.th("fullname") h.th("location") for u in keys: with h.tr: with h.td(): h.img('',src=escape(db.usernames[u].avatar), width="64", height="64") h.td(u) h.td(escape(db.usernames[u].fullname)) h.td(escape(db.usernames[u].location)) open(fname, "w").write(str(h))
def createReports(sgObj,site,datacenter): # # Create directories if they don't exist orange = '#F7EE6F' green = '#69F24E' dir = "/www/" + site + "/SG/" if not os.path.isdir(dir): subprocess.call(["mkdir", dir]) dir = '/www/' + site + '/CSV' if not os.path.isdir(dir): subprocess.call(["mkdir", dir]) # # reportDate = str(time.strftime("%c")) GB = float(sgObj.ProvisionedCapacity)/1024 ProvisionedGB = "%.2f" % GB info1 = 'Total Porvisioned(GB)=' + str(ProvisionedGB) www = HTML() html_index = '/www/' + site + '/index.html' sgSummCSV = '/www/' + site + '/CSV/' + site + '_SG_Summary.csv' f_index = open(html_index,'w') f_SummCSV = open(sgSummCSV,'w') f_SummCSV.write("Storage Group,SLO Policy,Capacity GB,Masking View,Max IOPS,Max MB/s\n") linkpath = "/" + site + "/CSV/" + site + '_SG_Summary.csv' sgSummLink = '<a href=' + linkpath + '>Summary CSV</a>\n' f_index.write(www.start_html('SG Summary')) f_index.write(www.EMC_Header(site,datacenter,info1,sgSummLink)) f_index.write(www.start_table()) f_index.write(www.end_table) fpTables = {} policies = {} for sg in sgObj.SGs: # color = '' link = "/" + site + "/SG/" + sg + ".html" sgGB = float(sgObj.SG2Capacity[sg])/1024 sgProvisionedGB = "%.2f" % sgGB MVs = sgObj.SGinMV[sg] fp = sgObj.SGinSLO[sg] policies[fp] = 1 if not fp in fpTables: fpTables[fp] = [] IOPS_LIMIT = str(sgObj.SG_IOPS_Limit[sg]) MB_LIMIT = str(sgObj.SG_MB_Limit[sg]) if MVs.upper() == 'NO': color = orange rowlist = ["<a href=" + link + '>' + sg + "</a>",fp, str(sgProvisionedGB),MVs,IOPS_LIMIT,MB_LIMIT] SGhtml = www.tr_list(rowlist,color) fpTables[fp].append(SGhtml) f_SummCSV.write(sg + ',' + fp + ',' + str(sgProvisionedGB) + ',' + MVs + ',' + IOPS_LIMIT + ',' + MB_LIMIT + "\n") # go ahead and write out the sg detail HTML page. sgfile = "/www/" + site + "/SG/" + sg + ".html" sgCSV = "/www/" + site + "/CSV/" + site + '_' + sg + ".csv" linkpath = "/" + site + "/CSV/" + site + '_' + sg + ".csv" link1 = '<a href=' + linkpath + '>SG CSV</a>\n' f_sg = open(sgfile,'w') f_sgCSV = open(sgCSV,'w') f_sgCSV.write('Storage Group Report for ' + sg + '\n\n\n') f_sg.write(www.start_html('SG Detail')) f_sg.write(www.EMC_Header(site,datacenter,'',link1)) html = "<p><H3><center>Detailed Storage Report for " + sg + " SSC_VMAX40K_1794</center></H3>\n" f_sg.write(html) f_sg.write(www.start_table()) f_sg.write(www.tr + www.th + "Storage Group<th>SLO Policy<TH>Capacity GB</tr>\n") html = www.tr + www.td + sg + www.td + fp + www.td + str(sgProvisionedGB) + "\n" f_sg.write(html) f_sg.write(www.end_table) f_sg.write(www.start_table(3,'Device List')) f_sg.write(www.tr + www.th + "Device<th>Capacity GB</tr>\n") f_sgCSV.write("Volume,Capacity GB\n") for device in sgObj.SGs[sg]: devGB = float(sgObj.SGs[sg][device])/1024 dev_formatted = "%.2f" % devGB html = www.tr + www.td + device + www.td + str(dev_formatted) +"\n" f_sg.write(html) f_sgCSV.write(device + ',' + str(dev_formatted) + '\n') f_sg.write(www.end_table) f_sg.write(www.end_html) f_sg.close() f_sgCSV.close() for fp in policies: f_index.write(www.start_table(3,'Groups with SLO ' + fp + ' Policy')) f_index.write("<tr><th>Storage Group<th>SLO Policy<TH>Capacity GB<TH>Masking View<TH>IOPS Limit<TH>MB/s Limit</tr>\n") for line in fpTables[fp]: f_index.write(line) f_index.write(www.end_table) f_index.write(www.end_html) f_index.close() f_SummCSV.close()
class DialogBox(PopupPanel): def __init__(self, autoHide=None, modal=True, **kwargs): PopupPanel.__init__(self, autoHide, modal, **kwargs) self.caption = HTML() self.child = None self.dragging = False self.dragStartX = 0 self.dragStartY = 0 self.panel = FlexTable(Height="100%", BorderWidth="0", CellPadding="0", CellSpacing="0") self.panel.setWidget(0, 0, self.caption) self.panel.getCellFormatter().setHeight(1, 0, "100%") self.panel.getCellFormatter().setWidth(1, 0, "100%") self.panel.getCellFormatter().setAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE) PopupPanel.setWidget(self, self.panel) self.setStyleName("gwt-DialogBox") self.caption.setStyleName("Caption") self.caption.addMouseListener(self) def getHTML(self): return self.caption.getHTML() def getText(self): return self.caption.getText() def onEventPreview(self, event): # preventDefault on mousedown events, outside of the # dialog, to stop text-selection on dragging type = DOM.eventGetType(event) if type == 'mousedown': target = DOM.eventGetTarget(event) elem = self.caption.getElement() event_targets_popup = target and DOM.isOrHasChild(elem, target) if event_targets_popup: DOM.eventPreventDefault(event) return PopupPanel.onEventPreview(self, event) def onMouseDown(self, sender, x, y): self.dragging = True DOM.setCapture(self.caption.getElement()) self.dragStartX = x self.dragStartY = y def onMouseEnter(self, sender): pass def onMouseLeave(self, sender): pass def onMouseMove(self, sender, x, y): if self.dragging: absX = x + self.getAbsoluteLeft() absY = y + self.getAbsoluteTop() self.setPopupPosition(absX - self.dragStartX, absY - self.dragStartY) def onMouseUp(self, sender, x, y): self.dragging = False DOM.releaseCapture(self.caption.getElement()) def remove(self, widget): if self.child != widget: return False self.panel.remove(widget) self.child = None return True def setHTML(self, html): self.caption.setHTML(html) def setText(self, text): self.caption.setText(text) def doAttachChildren(self): PopupPanel.doAttachChildren(self) self.caption.onAttach() def doDetachChildren(self): PopupPanel.doDetachChildren(self) self.caption.onDetach() def setWidget(self, widget): if self.child is not None: self.panel.remove(self.child) if widget is not None: self.panel.setWidget(1, 0, widget) self.child = widget
def test_html_object_element_list(self): html_obj = HTML() empty_list = html_obj.get_element_list() test_list = [] self.assertEqual(test_list, empty_list)
# # # # # if __name__ == "__main__": DebugLevel = logging.DEBUG logging.basicConfig(level=DebugLevel) from Settings import Settings from Top import Top Top.settings = Settings(FromConfigFile = True) from HTML import HTML WebPage = HTML() WebPage.makeHeader() f = Gaussian() f.file = sys.argv[1] #import profile #profile.run('f.parse()') f.parse() f.postprocess() print f.steps[0] b1, b2 = f.webData() WebPage.makeLine(b1,b2) WebPage.makeTail() WebPage.write()
def test_html_object_get_nested_level(self): html_obj = HTML() self.assertEqual(0, html_obj.get_top_element_nested_level())
def test_html_object_change_has_body(self): html_obj = HTML(True, True) html_obj.change_has_body() self.assertEqual(False, html_obj.has_body)
def test_html_object_string_method(self): html_obj = HTML() blank_string = html_obj.__str__() self.assertEqual("", blank_string)
def test_html_object_generate_full_html_no_body(self): html_obj = HTML(True) html_obj.generate_html() self.assertEqual("<!DOCTYPE html>\n <html>\n</html>", html_obj.html_string)
def outputHtmlUserlist(fname, db, keys): h = HTML() head = h.head("") with h.body(""): with h.table(border='1', newlines=True): with h.colgroup: h.col(span="1", style="width: 64px;") h.col(span="1", style="width: 130px;") h.col(span="1", style="width: 250px;") h.col(span="1", style="width: 250px;") with h.tr: h.th("avatar") h.th("username") h.th("fullname") h.th("location") for u in keys: with h.tr: with h.td(): h.img('', src=escape(db.usernames[u].avatar), width="64", height="64") h.td(u) h.td(escape(db.usernames[u].fullname)) h.td(escape(db.usernames[u].location)) open(fname, "w").write(str(h))
def test_html_object_generate_full_html_with_body_and_head(self): html_obj = HTML(True, True, True) html_obj.generate_html() self.assertEqual( "<!DOCTYPE html>\n <html>\n<head>\n</head>\n<body>\n</body>\n</html>", html_obj.html_string)
def test_html_object_change_full_html(self): html_obj = HTML(True, True) html_obj.change_full_html() self.assertEqual(False, html_obj.is_full_html)
log = logging.getLogger('terse.py') DebugLevel = getattr(logging,debug) lf = '[%(levelname)s: %(funcName)s at %(filename)s +%(lineno)s] %(message)s' logging.basicConfig(format=lf ,level=DebugLevel) absolute_tersepic = settings.OutputFolder + '/' + settings.tersepic if not IO.prepareDir(settings.OutputFolder): sys.exit() if not IO.prepareDir(absolute_tersepic): sys.exit() IO.cleanDir(absolute_tersepic) WebPage = HTML() WebPage.readTemplate() for fl in files: log.debug('Opening ' + str(fl)) if fl[0] == 'file': if not IO.all_readable(fl[1:]): continue f = ParserAssigner().typeByExt(fl) else: f = ParserAssigner().typeByCommandLine(fl) f.file = fl[1] try: f.parse()
def test_html_object_generate_not_full_html_with_elements(self): html_obj = HTML(False, False, False) test_element = html_element(False, "a", "Anchor") html_obj.add_element(test_element) html_obj.generate_html() self.assertEqual("<a>Anchor</a>\n", html_obj.html_string)
def __init__(self, master=None): Frame.__init__(self, master) self.options_list = [ "table", "tr", "td", "h1", "h2", "h3", "h4", "h5", "h6", "br", "span", "div", "a", "link", "nav", "title", "abbr", "address", "code", "em", "progress", "strong", "sub", "sup", "time", "u", "var", "samp", "small", "q", "mark", "s", "pre", "ins", "form", "input", "button", "fieldset", "legend", "label", "datalist", "option", "optgroup", "textarea", "keygen", "output", "select", "img", "map", "area", "canvas", "iframe", "figure", "figcaption", "audio", "source", "track", "video", "ul", "li", "ol", "dl", "dt", "dd", "menu", "menuitem", "caption", "thead", "tbody", "tfoot", "col", "colgroup", "style", "header", "footer", "main", "section", "article", "aside", "details", "dialog", "summary", "head", "meta", "base", "script", "noscript", "embed", "object", "param", "blockquote", "hr", "b", "bdi", "bdo", "dfn", "cite", "del", "q", "meter", "rp", "rt", "ruby" ] self.options_list.sort() self.add_item = False self.nested = False self.delete_something = False self.meta = False self.temp_dict = {} self.order_number = 1 self.html_object = HTML() self.CheckVar1 = IntVar() self.CheckVar2 = IntVar() self.C1 = Checkbutton(root, text = "Full HTML", variable = self.CheckVar1, \ command = self.html_full, onvalue = 1, offvalue = 0, height=4, \ width = 15) self.C2 = Checkbutton(root, text = "Has Body", variable = self.CheckVar2, \ command = self.html_has_body, onvalue = 1, offvalue = 0, height=4, \ width = 15) self.C1.pack() self.C2.pack() self.generate_button = Button(root, text='Generate HTML', command= self.make_file) self.generate_button.place(x=30, y=115) self.add_element_button = Button(root, text='Add Element', command = self.add_html_element) self.add_element_button.place(x=30, y=15) self.order_button = Button(root, text='Order Elements', command = self.order_html) self.order_button.place(x=30, y=75) self.delete_button = Button(root, text='Delete Element', command = self.delete_html) self.delete_button.place(x=30, y=45)
from HTML import HTML from TopLevelTag import TopLevelTag from Tag import Tag if __name__ == "__main__": with HTML("test.html") as doc: with TopLevelTag("head") as head: with Tag("title") as title: title.text = "hello" head += title doc += head with TopLevelTag("body") as body: with Tag("h1", klass=("main-text", )) as h1: h1.text = "Test" body += h1 with Tag("div", klass=("container", "container-fluid"), id="lead") as div: with Tag("p") as paragraph: paragraph.text = "another test" div += paragraph with Tag("img", is_single=True, src="/icon.png", data_image="responsive") as img: div += img body += div
def createReports(sgObj,site,datacenter): # # Create directories if they don't exist orange = '#F7EE6F' green = '#69F24E' dir = "/www/" + site + "/SG/" if not os.path.isdir(dir): subprocess.call(["mkdir", dir]) dir = '/www/' + site + '/CSV' if not os.path.isdir(dir): subprocess.call(["mkdir", dir]) # # reportDate = str(time.strftime("%c")) GB = float(sgObj.ProvisionedCapacity)/1024 ProvisionedGB = "%.2f" % GB info1 = 'Total Porvisioned(GB)=' + str(ProvisionedGB) www = HTML() html_index = '/www/' + site + '/index.html' sgSummCSV = '/www/' + site + '/CSV/' + site + '_SG_Summary.csv' f_index = open(html_index,'w') f_SummCSV = open(sgSummCSV,'w') f_SummCSV.write("Storage Group,FAST Policy,Capacity GB,Masking View,Max IOPS,Max MB/s\n") linkpath = "/" + site + "/CSV/" + site + '_SG_Summary.csv' sgSummLink = '<a href=' + linkpath + '>Summary CSV</a>\n' f_index.write(www.start_html('SG Summary')) f_index.write(www.EMC_Header(site,datacenter,info1,sgSummLink)) f_index.write(www.start_table()) f_index.write(www.end_table) # Dictionary: key = policy name and value is a list of html formatted lines, one line per SG with that policy. fpTables = {} # Dictionary of policies. Used to iterate over the above var. policies = {} demandpage = '/www/' + site + '/fast_demand.html' f = Files() f.read_file(demandpage) dp = f.readfile[:] for sg in sgObj.SGs: # # found = False demandtable = '' for txt in dp: if 'SG_Name' in txt: hr = txt if str(sg) in txt: found = True rowdata = txt if found: demandtable = '<br><p><table border=3 align=center><caption>FAST-VP Demand</caption>\n' demandtable += hr demandtable += '\n' demandtable += rowdata demandtable += '\n' demandtable += '\n</table>' color = '' if sg in sgObj.Associations: fp = sgObj.Associations[sg] else: fp = 'NO_FAST_POLICY' color = orange # policies[fp] = 1 if not fp in fpTables: fpTables[fp] = [] # link = "/" + site + "/SG/" + sg + ".html" sgGB = float(sgObj.SG2Capacity[sg])/1024 sgProvisionedGB = "%.2f" % sgGB MVs = sgObj.SGinMV[sg] IOPS_LIMIT = str(sgObj.SG_IOPS_Limit[sg]) MB_LIMIT = str(sgObj.SG_MB_Limit[sg]) if MVs.upper() == 'NO': color = orange rowlist = ["<a href=" + link + '>' + sg + "</a>",fp, str(sgProvisionedGB),MVs,IOPS_LIMIT,MB_LIMIT] SGhtml = www.tr_list(rowlist,color) fpTables[fp].append(SGhtml) f_SummCSV.write(sg + ',' + fp + ',' + str(sgProvisionedGB) + ',' + MVs + ',' + IOPS_LIMIT + ',' + MB_LIMIT + "\n") # go ahead and write out the sg detail HTML page. sgfile = "/www/" + site + "/SG/" + sg + ".html" sgCSV = "/www/" + site + "/CSV/" + site + '_' + sg + ".csv" linkpath = "/" + site + "/CSV/" + site + '_' + sg + ".csv" link1 = '<a href=' + linkpath + '>SG CSV</a>\n' f_sg = open(sgfile,'w') f_sgCSV = open(sgCSV,'w') f_sgCSV.write('Storage Group Report for ' + sg + '\n\n\n') f_sg.write(www.start_html('SG Detail')) f_sg.write(www.EMC_Header(site,datacenter,'',link1)) html = "<p><H3><center>Detailed Storage Report for " + sg + " SSC_VMAX40K_1794</center></H3>\n" f_sg.write(html) f_sg.write(www.start_table()) f_sg.write(www.tr + www.th + "Storage Group<th>FAST<TH>Capacity GB</tr>\n") html = www.tr + www.td + sg + www.td + fp + www.td + str(sgProvisionedGB) + "\n" f_sg.write(html) f_sg.write(www.end_table) f_sg.write(demandtable) f_sg.write(www.start_table(3,'Device List')) f_sg.write(www.tr + www.th + "Device<th>Capacity GB</tr>\n") f_sgCSV.write("Volume,Capacity GB\n") for device in sgObj.SGs[sg]: devGB = float(sgObj.SGs[sg][device])/1024 dev_formatted = "%.2f" % devGB html = www.tr + www.td + device + www.td + str(dev_formatted) +"\n" f_sg.write(html) f_sgCSV.write(device + ',' + str(dev_formatted) + '\n') f_sg.write(www.end_table) f_sg.write(www.end_html) f_sg.close() f_sgCSV.close() for fp in policies: f_index.write(www.start_table(3,'Groups with FAST VP ' + fp + ' Policy Association')) f_index.write("<tr><th>Storage Group<th>FAST<TH>Capacity GB<TH>Masking View<TH>IOPS Limit<TH>MB/s Limit</tr>\n") for line in fpTables[fp]: f_index.write(line) f_index.write(www.end_table) f_index.write(www.end_html) f_index.close() f_SummCSV.close()
def createReports(mvObj,site,datacenter): reportDate = str(time.strftime("%c")) GB = float(mvObj.mvCapTotal)/1024 ProvisionedGB = "%.2f" % GB info1 = 'Total Porvisioned=' + str(ProvisionedGB) www = HTML() f = Files() html_index = '/www/' + site + '/views.html' viewsCSV = '/www/' + site + '/CSV/' + site + '_views.csv' htmlpage = [] csvpage = [] htmlpage.append(www.start_html('MV Summary')) linkpath = "/" + site + "/CSV/" + site + '_views.csv' mvSummLink = '<a href=' + linkpath + '>Views CSV</a>\n' htmlpage.append(www.EMC_Header(site,datacenter,info1,mvSummLink)) csvpage.append('MV Report for ' + site + '\n\n') # Write out a table for Masking Views csvpage.append("View Name,SG,IG,PG,Capacity\n") for pg in mvObj.portgroups: htmlpage.append(www.start_table(3,'Masking Views on PG, ' + pg )) htmlpage.append("<tr><th>View Name<th>SG<th>IG<th>PG<th>Capacity</tr>\n") for mv in mvObj.portgroups[pg]: viewname = mv['MV'] ig = mv['IG'] pg = mv['PG'] sg = mv['SG'] gb = float(mv['MB'])/1024 fmtgb = "%.2f" % gb gb = str(fmtgb) sglink = "<a href=/" + site + "/SG/" + sg + ".html>" + sg + "</a>\n" iglink = "<a href=/" + site + "/IG/" + ig + ".html>" + ig + "</a>\n" row = [viewname,sglink,iglink,pg,gb] htmlpage.append(www.tr_list(row)) csrow = [viewname,sg,ig,pg,gb] csvpage.append(', '.join(csrow) + '\n') htmlpage.append(www.end_table) htmlpage.append(www.end_html) f.write_file(html_index,htmlpage) f.write_file(viewsCSV,csvpage) dir = "/www/" + site + "/IG/" if not os.path.isdir(dir): subprocess.call(["mkdir", dir]) for IG in mvObj.HostInitiatorGroups: igPage = '/www/' + site + '/IG/' + IG + '.html' f_ig = open(igPage,'w') f_ig.write(www.start_html('Initiator Group ' + IG)) f_ig.write(www.EMC_Header(site,datacenter)) # Write out a table for Masking Views f_ig.write(www.start_table(3,'Initiator Group ' + IG)) f_ig.write("<tr><th>HBA Initiators</tr>\n") for wwpn in mvObj.HostInitiatorGroups[IG]: f_ig.write("<tr><th>" + wwpn + "</tr>\n") f_ig.write(www.end_table) f_ig.write(www.end_html) f_ig.close() for IG in mvObj.ClusterInitiatorGroups: igPage = '/www/' + site + '/IG/' + IG + '.html' f_ig = open(igPage,'w') f_ig.write(www.start_html('Cluster Initiator Group ' + IG)) f_ig.write(www.EMC_Header(site,datacenter)) # Write out a table for Masking Views f_ig.write(www.start_table(3,'Initiator Group ' + IG)) f_ig.write("<tr><th>Cluster Nodes</tr>\n") for wwpn in mvObj.ClusterInitiatorGroups[IG]: link = '<a href=/' + site + '/IG/' + wwpn + '.html>' + wwpn + '</a>\n' f_ig.write("<tr><th>" + link + "</tr>\n") f_ig.write(www.end_table) f_ig.write(www.end_html) f_ig.close() # Database section # First, grab a list of known WWPN logins vmaxdb=mysql.connect(host="chatst3utsan01",user="******",passwd="emc",db="vmax") cur = vmaxdb.cursor() query = "SELECT wwpn,ig FROM initiatorgroups" results = cur.execute(query) rows = cur.fetchall() # Now create a simple list of logins. We use this to check whether we've seen a login before. # If we know this login, we just update the time seen and array/port. knownwwpns = [] p = re.compile('\w+') for row in rows: wwpn = row[0] ig = row[1] key = ''.join(p.findall(wwpn + ig)).lower() knownwwpns.append(key) # Now get the current date and time. today = datetime.date.today() formatteddate = today.strftime('%Y-%m-%d') now = datetime.datetime.now().time() formattedtime = now.strftime('%H:%M:%S') for IG in mvObj.HostInitiatorGroups: for wwpn in mvObj.HostInitiatorGroups[IG]: wwpn = wwpn.lower() ig = str(IG) ig = ig.lower() insertquery = 'insert into initiatorgroups(wwpn,array_name,ig,record_date,record_time) ' insertquery += " values('" + wwpn + "','" + site + "','" insertquery += ig + "',NOW(),NOW() );" updatequery = 'update initiatorgroups SET array_name = %s, ig = %s, record_date = %s, record_time = %s ' updatequery += ' WHERE wwpn = %s AND ig = %s' wwpn_ig = ''.join(p.findall(wwpn + ig)) if wwpn_ig in knownwwpns: results = cur.execute(updatequery, (site,ig,formatteddate,formattedtime,wwpn,ig)) else: results = cur.execute(insertquery)