Ejemplo n.º 1
0
def main ( file ):
	"""Fonction principale du programme"""
	
	# taille des n-grammes de caractères contigus
	NG_CHAR = 3	
	t = time.time()
	
	# Lecture du fichier, détection de son encoding et encodage en unicode
	raw_data = html.read( string.join(file, '') )      
	encoding, u_data = html.encoding( raw_data )
	
	# Si l'encoding n'est pas trouvé, on écourte le traitement de la page
	if encoding == None:
		return None
		
	# Extraction des différentes parties du fichier html + nétoyage des balises
	u_header, u_title, u_body, u_footer = html.extract_parts( u_data )
	u_body, u_body_clean, u_balises = html.clean( tools.decode_html_entities(u_body) )
	
	# Liste les mots et caractères et fait leurs effectifs
	u_list_words = tools.list_words( u_body_clean )
	u_dict_effect = tools.list_2_dict_effectif( u_list_words )	
	u_list_chars = tools.list_chars( u_dict_effect )
	u_char_effect = tools.char_effect( u_dict_effect )

	# Calcul la loi de Zipf sur les mots et les caractères	
	u_zipf = tools.dict_effectif2distrib_zipf( u_dict_effect )
	u_zipf_char = tools.dict_effectif2distrib_zipf( u_char_effect )
	
	# Trouve les groupes de mots et caractères contigus du texte
	u_adjoining_words = adjoining_words( u_list_words, 2 )
	u_adjoining_char = adjoining_words( u_list_chars, NG_CHAR, NG_CHAR )
		
	# Trouve des mot clefs du texte et fait des statistiques sur le nombre de mots
	u_tags = tag_cloud( u_zipf ) if u_zipf else []
	nbword = tools.word_stat( u_dict_effect ) if u_zipf else [0, 0, 0]
			
	# Sauvegarde les n-grammes de caractères dans un fichier texte
	if NG_CHAR in u_adjoining_char:
		with open(file[0] + file[1] + "_adjchars.txt", "w") as f:
			for char in u_adjoining_char[NG_CHAR]:
				f.write( "%s : %s \n"%( string.join(char[0], '').encode("utf-8"), str(char[1]) ) )
			
	# Sauvegarde les graphs sur la loi de zipf, sur le rang x effectif et sur longueur / effectif
	plot.save_zipf( file, "_word", u_zipf, "f(rang) = effectif" )
	plot.save_zipf( file, "_char", u_zipf_char, "f(rang) = effectif" )
	plot.save_rangeffectif( file, u_zipf )
	plot.save_leneffectif( file, u_zipf )
	
	# Sauvegarde le fichier colorié
	html.write(	file[0] + file[1] + "_color.html",
				u_header,
				color(u_adjoining_words, u_body, u_balises),
				u_footer,
				encoding )
	
	# Sauvegarde le fichier de statistique
	output.stat( file, u_title, u_tags, nbword, u_zipf, u_zipf_char, t )	
	
	return u_dict_effect
Ejemplo n.º 2
0
def nav_lang ( d, lang, file_list ):
	"""Sauvegarde la page de navigation de la langue"""
	
	file_link = u''
	for f in file_list:
		file_link += u'<a href="%s_nav.html" target="iframe_2">%s</a> - '%( os.path.splitext(f)[0], os.path.splitext(f)[0] )
	
	file_link += u'<a href="%s_stat.html" target="iframe_2">statistique de la langue</a>'%( lang )
	
	page = u"""
		<style type="text/css">
			#all { height: 100%%; }					
			#link { text-align: center; height: 30px; }					
			iframe { width: 100%%; }
		</style>				
		<script src="../jquery-1.6.4.min.js" type="text/javascript"></script>
		<div id="all">
			<div id="link">
				%s
			</div>
			
			<iframe src="%s" name="iframe_2" id="if"></iframe>
		</div>
	"""%(
		file_link,
		os.path.splitext(file_list[0])[0] + u"_nav.html"
	)
	
	html.write(	u"%s/nav.html"%( d+lang ),
				html.header( u"utf-8", lang ),
				page,
				u"</body>\n</html>",
				"utf-8" )
Ejemplo n.º 3
0
def nav_princ ( d, lang_list ):
	"""Sauvegarde la page de navigation principale"""
	
	lang_link = u''
	for lang in lang_list:
		lang_link += u'<a href="%s/nav.html" target="iframe_1">%s</a> - '%( lang, lang )
	
	lang_link = lang_link[:-3]
	
	page = u"""			
		<style type="text/css">
			#all { height: 100%%; }					
			#link { text-align: center; height: 30px; }					
			iframe { width: 100%%; }
		</style>				
		<script src="jquery-1.6.4.min.js" type="text/javascript"></script>
		<div id="all">
			<div id="link">
				%s
			</div>					
			<iframe src="%s" name="iframe_1" id="if"></iframe>
		</div>
	"""%(
		lang_link,
		lang_list[0] + u"/nav.html"
	)
	
	html.write(	u"%snav.html"%( d ),
				html.header( u"utf-8", u"LTAL TP 1-2" ),
				page,
				u"</body>\n</html>",
				"utf-8" )
Ejemplo n.º 4
0
def nav_file ( d, lang, f, ext ):
	"""Sauvegarde la page de navigation du fichier"""
	
	page = u"""
		<style type="text/css">
			#all { height: 100%%; }					
			#link { text-align: center; height: 30px; }					
			iframe { width: 100%%; }
		</style>				
		<script src="../jquery-1.6.4.min.js" type="text/javascript"></script>
		<div id="all">
			<div id="link">
				%s - 
				<a href="%s%s" target="iframe_3">version originale</a>
				<a href="%s_color.html" target="iframe_3">version coloriée</a>
				<a href="%s_stat.html" target="iframe_3">statistique</a>
			</div>
			
			<iframe src="%s_stat.html" name="iframe_3" id="if"></iframe>
		</div>
	"""%(
		f,
		f,
		ext,
		f,
		f,
		f
	)
	
	html.write(	u"%s/%s_nav.html"%( d+lang, f ),
				html.header( u"utf-8", f ),
				page,
				u"</body>\n</html>",
				"utf-8" )
Ejemplo n.º 5
0
    def update_messages(self, screen):
        """
        """

        # the messages are the same... no need to update.
        if not self.dirty['messages']:
            if self.message == self.last_message:
                self.dirty['messages'] = 0
                return []

        if self.dirty['messages']:
            self.dirty['messages'] = 0

            font = self.message_font  #pygame.font.Font(None, 18)
            rect = S_MESSAGES
            rect2 = pygame.Rect(S_MESSAGES)
            rect2.x -= 1
            rect2.y += 1

            aa = 0
            #color = (0x55,0xff,0x55) #(80,80,80)
            color = (0xff, 0x55, 0x55)  #(80,80,80)
            color2 = (0, 0, 0)  #(80,80,80)

            bgcolor = (0, 0, 0, 0)
            s = screen
            #screen.blit(self.bkgrb, S_MESSAGES)

            #pgu.html.render(font,rect,text,aa,color,bgcolor)
            html.write(s, font, rect2, self.message, aa, color2)
            html.write(s, font, rect, self.message, aa, color)

            return [rect]
        else:
            return []
Ejemplo n.º 6
0
    def update_equipment_words(self, screen):
        """
        """

        # the messages are the same... no need to update.
        if not self.dirty['equipment_words']:
            if self.equipment_message == self.equipment_last_message:
                self.dirty['equipment_words'] = 0
                return []

        if self.dirty['equipment_words']:
            self.dirty['equipment_words'] = 0

            font = self.equipment_message_font  #pygame.font.Font(None, 18)
            rect = S_ITEMS
            rect2 = pygame.Rect(S_ITEMS)
            rect2.x -= 1
            rect2.y += 1

            aa = 0
            color = (0x55, 0xff, 0x55)  #(80,80,80)
            color2 = (0, 0, 0)
            bgcolor = (0, 0, 0, 0)
            s = screen

            #pgu.html.render(font,rect,text,aa,color,bgcolor)
            html.write(s, font, rect2, self.equipment_message, aa, color2)
            html.write(s, font, rect, self.equipment_message, aa, color)

            return [rect]
        else:
            return []
Ejemplo n.º 7
0
 def preproc():
     for entity_to_write in UMLobjects.keys():
         if "." in entity_to_write:
             # Fully qualified enum names are also represented as classes in latest XMI version
             continue
             
         # try:
         #     c = UMLobjects[entity_to_write][0].xmi_class
         #     stereotype = (c/"properties")[0].stereotype
         #     if stereotype is not None: 
         #         stereotype = stereotype.lower()
         #     if stereotype is not None and (stereotype.startswith("pset") or stereotype == "$"):
         #         continue
         # except:
         #     pass
         
         
         if any(entity_to_write.lower().startswith(x) for x in ("qto", "pset", "penum", "p_", "q_")):
             continue
             
         try:
             UMLobjects[entity_to_write][0].xmi_class
         except:
             continue
             
         # try:
         tex_fn = os.path.join(tex_dir, entity_to_write)
         tex_object = Tex_object(tex_fn)
         UMLobject = UMLobjects[entity_to_write][0]
         tex_object.write_class2(UMLobject,UMLobjects)
         tex_object.generate_tex()
         html.write("<div style='display:none'><img src='%s.png'></div>\n" % entity_to_write)
         yield tex_object
Ejemplo n.º 8
0
    def update_equipment_words(self, screen):
        """
        """

        # the messages are the same... no need to update.
        if not self.dirty['equipment_words']:
            if self.equipment_message == self.equipment_last_message:
                self.dirty['equipment_words'] = 0
                return []

        if self.dirty['equipment_words']:
            self.dirty['equipment_words'] = 0

            font = self.equipment_message_font#pygame.font.Font(None, 18)
            rect = S_ITEMS
            rect2 = pygame.Rect(S_ITEMS)
            rect2.x -= 1
            rect2.y += 1

            aa = 0
            color = (0x55,0xff,0x55) #(80,80,80)
            color2 = (0,0,0)
            bgcolor = (0,0,0,0)
            s = screen

            #pgu.html.render(font,rect,text,aa,color,bgcolor)
            html.write(s,font,rect2,self.equipment_message,aa,color2)
            html.write(s,font,rect,self.equipment_message,aa,color)

            return [rect]
        else:
            return []
Ejemplo n.º 9
0
    def update_messages(self, screen):
        """
        """

        # the messages are the same... no need to update.
        if not self.dirty['messages']:
            if self.message == self.last_message:
                self.dirty['messages'] = 0
                return []

        if self.dirty['messages']:
            self.dirty['messages'] = 0

            font = self.message_font #pygame.font.Font(None, 18)
            rect = S_MESSAGES
            rect2 = pygame.Rect(S_MESSAGES)
            rect2.x -= 1
            rect2.y += 1

            aa = 0
            #color = (0x55,0xff,0x55) #(80,80,80)
            color = (0xff,0x55,0x55) #(80,80,80)
            color2 = (0,0,0) #(80,80,80)

            bgcolor = (0,0,0,0)
            s = screen
            #screen.blit(self.bkgrb, S_MESSAGES)

            #pgu.html.render(font,rect,text,aa,color,bgcolor)
            html.write(s,font,rect2,self.message,aa,color2)
            html.write(s,font,rect,self.message,aa,color)

            return [rect]
        else:
            return []
Ejemplo n.º 10
0
def diff(master_screens_path, current_screens_path, test_name, master_hash,
         current_hash):
    doc = dominate.document(title=test_name)
    master_screens = sorted(master_screens_path.iterdir())
    current_screens = sorted(current_screens_path.iterdir())

    with doc:
        h1(test_name)
        p("This UI test differs from master.",
          style="color: grey; font-weight: bold;")
        with table():
            with tr():
                td("Master:")
                td(master_hash, style="color: red;")
            with tr():
                td("Current:")
                td(current_hash, style="color: green;")
        hr()

        with table(border=1, width=600):
            with tr():
                th("Master")
                th("Current branch")

            html.diff_table(master_screens, current_screens)

    return html.write(REPORTS_PATH / "diff", doc, test_name + ".html")
Ejemplo n.º 11
0
def index():
    removed = list((REPORTS_PATH / "removed").iterdir())
    added = list((REPORTS_PATH / "added").iterdir())
    diff = list((REPORTS_PATH / "diff").iterdir())

    title = "UI changes from master"
    doc = dominate.document(title=title)

    with doc:
        h1("UI changes from master")
        hr()

        h2("Removed:", style="color: red;")
        i("UI fixtures that have been removed:")
        html.report_links(removed, REPORTS_PATH)
        br()
        hr()

        h2("Added:", style="color: green;")
        i("UI fixtures that have been added:")
        html.report_links(added, REPORTS_PATH)
        br()
        hr()

        h2("Differs:", style="color: grey;")
        i("UI fixtures that have been modified:")
        html.report_links(diff, REPORTS_PATH)

    return html.write(REPORTS_PATH, doc, "index.html")
    def preproc():
        for entity_to_write in UMLobjects.keys():
            if "." in entity_to_write:
                # Fully qualified enum names are also represented as classes in latest XMI version
                continue

            # try:
            #     c = UMLobjects[entity_to_write][0].xmi_class
            #     stereotype = (c/"properties")[0].stereotype
            #     if stereotype is not None:
            #         stereotype = stereotype.lower()
            #     if stereotype is not None and (stereotype.startswith("pset") or stereotype == "$"):
            #         continue
            # except:
            #     pass

            if any(entity_to_write.lower().startswith(x)
                   for x in ("qto", "pset", "penum", "p_", "q_")):
                continue

            UMLobjects[entity_to_write][0].xmi_class

            # try:
            tex_fn = os.path.join(tex_dir, entity_to_write)
            print(tex_fn)
            UMLobject = UMLobjects[entity_to_write][0]

            for i in range(4, 10):
                # keep trying until hc is large enough
                # to accomodate all elements
                try:
                    hc = HC(i, 2)
                    tex_object = Tex_object(tex_fn)
                    tex_object.write_class2(hc, xmi, UMLobject, UMLobjects)
                    break
                except ValueError as e:
                    continue

            tex_object.generate_tex()
            html.write("<div style='display:none'><img src='%s.png'></div>\n" %
                       entity_to_write)
            yield tex_object
Ejemplo n.º 13
0
def added(screens_path, test_name):
    doc = dominate.document(title=test_name)
    screens = sorted(screens_path.iterdir())

    with doc:
        h1(test_name)
        p(
            "This UI test has been added to fixtures.json.",
            style="color: green; font-weight: bold;",
        )
        hr()

        with table(border=1):
            with tr():
                th("Added files")

            for screen in screens:
                with tr():
                    html.image(screen)

    return html.write(REPORTS_PATH / "added", doc, test_name + ".html")
Ejemplo n.º 14
0
def stat ( file, u_title, u_tag, nbword, u_zipf, u_zipf_char, t ):
	"""Sauvegarde la page de statistique sur le document"""
	
	page = u"""
	<style type="text/css">
		.col {
			width: 50%%;
		}
		.left {
			float: left;
		}
		.right {
			float: right;
		}
		table {
			text-align: center;
		}
		td {
			color: #9370DB; 
			font-size: 20px; 
			font-weight: bold;
		}
		img {
			width: 100%%;
		}
		h1 {
			text-align: center;
		}
	</style>
	<p>
		%s<br />
		Fichier traité en %fs.	
	</p>
	<div class="left col">
		<table cellspacing="20">
			<tr>
				<td>%s</td>
			</tr>
			<tr>
				<td>%s</td>
			</tr>
			<tr>
				<td>%s</td>
			</tr>
		</table>
	</div>
	<div class="right col">
		<dl>
			<dt>Nombre de mots:</dt> <dd>%d</dd>
			<dt>Nombre de mots différents:</dt> <dd>%d</dd>
			<dt>Nombre de mots sur nombre de mots différents:</dt> <dd>%f</dd>
		</dl>
	</div>
	<br style="clear: both"/>
	<div class="left col">
		<img src="%s" alt="Nuage de points longueur et effectif" />
		<h1>Mots</h1>
		<img src="%s" alt="Loi de Zipf sur les mots" />
		<br />
		%s
	</div>
	<div class="right col">
		<img src="%s" alt="rang du mot x effectif" />
		<h1>Caractères</h1>
		<img src="%s" alt="Loi de Zipf sur les caractères" />
		<br />
		%s
	</div>
	"""%(
	u_title, 
	time.time() - t,
	string.join(u_tag[:5], u"</td><td>"), 
	string.join(u_tag[5:10], u"</td><td>"), 
	string.join(u_tag[10:], u"</td><td>"),
	nbword[0],
	nbword[1],
	nbword[2],
	unicode(file[1], 'utf-8') + u"_leneffect.png",
	unicode(file[1], 'utf-8') + u"_zipf_word.png",
	html.tuple_2_ol(u_zipf),
	unicode(file[1], 'utf-8') + u"_rangeffect.png",
	unicode(file[1], 'utf-8') + u"_zipf_char.png",
	html.tuple_2_ol(u_zipf_char)
	)
	
	html.write(	file[0] + file[1] + u"_stat.html",
				html.header( u"utf-8", u"Statistique de %s"%( string.join(file[1:]) ) ),
				page,
				u"</body>\n</html>",
				"utf-8" )
Ejemplo n.º 15
0
    html.write("""<html>
<head>
<script>
function filterimages(evt) {
    let t = evt.target.value.toLowerCase();
    let imgs = Array.from(document.querySelectorAll('img'));
    for (let im of imgs) {
        im.parentNode.style.display = t.length >= 3 && im.getAttribute('src').toLowerCase().indexOf(t) !== -1 ? 'block' : 'none';
    }
}
</script>
<style>
* {
    font-family: times;
    font-weight: normal;
}
input {
    padding: 4px;
    margin: 0 0 10px 0;
    display: block;
    border-radius: 3px;
    border: solid 1px gray;
    width: 100%;    
}
img {
    display: block;
}
</style>
</head>
<body>
<h1>IFC UML Image Listing</h1>
<input type='text' oninput="filterimages(event)" placeholder="filter">
""")
Ejemplo n.º 16
0
def form(rec, title):
    """Generate HTML content for a general form"""
    root = rec.data_store.root
    serving()
    page_header(title)
    write('<form action="" method="post" id="form"><table>')
    has_date = False
    for fld in rec.fields:
        val = getattr(rec, fld.name, None)
        write('<tr><th>', fld.name, '</th><td class="buttons">')
        inp = '<input name="' + fld.name + '"'
        if val:
            inp += ' value="' + str(val) + '"'
        if isinstance(fld, Date):
            write(inp, ' class="datepicker" size=7>')
            has_date = True
        elif isinstance(fld, Amount) or isinstance(fld, Number):
            write(inp, ' size=8>')
        elif isinstance(fld, Enum):
            write('<select name="', fld.name, '">\n')
            elm = 1
            for value in fld.values:
                sel = 'selected' if elm == val else ''
                write('<option value="' + value + '"', sel, '>', value,
                      '</option>\n')
                elm += 1
            write('</select>\n')
        elif isinstance(fld, Relation):
            write('<select name="' + fld.name + '">\n')
            ls = []
            if fld.allow_null:
                ls.append(('', ''))
            for rec in getattr(root, fld.related.path):
                ls.append((rec.get_id(), rec.show()))
            for key, value in ls:
                sel = 'selected' if key == val else ''
                write('<option value="' + key + '"', sel + '>', value,
                      '</option>\n')
            write('</select>\n')
        else:
            write(inp, '>')
        write('</td></tr>\n')
    write('<tr><td class="buttons">')
    write('<input type="submit" value="ok"></td>\n')
    write('<td class="buttons">')
    write('<input type="button" value="cancel" style="float:right"' +
          ' onclick="self.close();">')
    write('</td></tr>\n')
    write('</table></form>')
    write("<script>\n")
    if has_date:
        write('$(function() {$( ".datepicker" ).' +
              'datepicker({ dateFormat: "yy-mm-dd" });});\n')
    write('$( "#form" ).submit(function( event ) {\n' + 'json_form("' +
          rec.get_name() + '", "' + rec.get_key() +
          '", $( this ).serializeArray());\n' + 'event.preventDefault();});\n')
    write("</script>\n")
    return page_footer()