# coding=UTF-8
# -*- coding: UTF-8 -*-
import string, re
import os
import codecs
import pprint

import configs
targetos = configs.targetos
targetbrowser = configs.targetbrowser

pages = configs.pages
##pageNames = configs.pageNames
pagenames = configs.pagenames
langs = configs.langs 
default_lang = configs.default_lang

#targetbrowser = 'firefox' # or 'kmeleon'  # overide -

# ----------- cache Installable files paths --------
file_mask = r'.*\.(msi|exe|bat|zip|7z|jar)'
mask_re = re.compile(file_mask)


lch_path = "../lch/";
lch_tpl = '''[Launch]
ExecuteFile=${cwd}$pathtofile''';

url_redirect_tpl = '''
<html><head>
<meta http-equiv="refresh" content="0;url=$url">
</head><body></body></html>
'''

url_lch_tpl = '''
[Launch]
ExecuteFile=$url
''' ##ExecuteParameter=${cwd}$parameter

#---Label---#000000#FFFFFF------------------------------------------------------
generator_start_node_installs = '../../../Programos/';
#lch_start_node_installs = '..\\Programos\\'; # launcheriui reikia paduoti tik ..\\Programos , nes jis skaiciuoja nuo \bin\ katalogo
lch_start_node_html = '../autorun/html/'; # launcheriui reikia paduoti tik ..\\Programos , nes jis skaiciuoja nuo \bin\ katalogo
installable_files = []
installable_files_used = []
new_lch_list = []

img_root = "../images/icons/mokslui/final-h40/"
img_fnames = []
re_img = re.compile(r'.*\.(png|gif|jpg)')
proglist = []

import mylibs
getftext = mylibs.getftext
putftext = mylibs.putftext
putftextU = mylibs.putftextU
fileExists = mylibs.fileExists

exclude_dirs = 'Gimp/Portatyvus/App'.split(';')
def has_fragment(dir):
    res = False
    ##dir = dir.replace('\\', '/')
    for fragment in exclude_dirs:
        if dir.find(fragment) > -1:
            res = True
    return res

def callback_scan(arg, directory, files):
    for file in files:
        if mask_re.match(file) and not has_fragment(directory):
            full_path = os.path.join(directory, file)
            installable_files.append(full_path.replace('\\', '/'))
os.path.walk(generator_start_node_installs, callback_scan, file_mask)


##def callback_scan_imgs(arg, directory, files):
##    for file in files:
##        if mask_re.match(file) : img_fnames.append(file.lower().replace('\\', '/'))
###os.path.walk('../' + img_root, callback_scan_imgs, re_img)
img_fnames = os.listdir(os.path.abspath( img_root))

def look_for_install_file(fname_fragment):
    found = False
    fname_fragment = fname_fragment.lower()
    for file_path in installable_files:
       fname = file_path.split('/')[-1]
       #if re.compile(fcodename).search(fname):
       if fname.lower().find(fname_fragment) != -1:
           found = True
           installable_files_used.append(file_path)
           return file_path
    return False

found_imgs = []
def imgExists(fname):
    for img in img_fnames:
        if img.lower() == fname.lower():
            found_imgs.append (img)
            return img
    return ''    


## handle links..
linkify2 = re.compile(r'\[\[http(://[^ \t]+) +(.*?)\]\]')
linkify1 = re.compile(r'http://([^ \t]+)')
linkify_local = re.compile(r'\[\[([^ \t]+) +(.*?)\]\]')
linkify_kmeleon = re.compile(r'("http://[^"]+")|(\'http://[^\']+\')')
#linkify_kmeleon = re.compile(r'"(http://[^"]+)"')
forbiden_in_fname = re.compile (r'[%\?\!:\'\"\\\(\)\=\& ]+')


spec4win = re.compile(r'<win>(.+?)</win>')
spec4lin = re.compile(r'<lin>(.+?)</lin>')
spec4allos = re.compile(r'<altinfo>(.+?)</altinfo>')

def filter_os(src):
    rez = src
    if targetos == 'w':  rez = spec4win .sub('\\1', rez) ;     rez = spec4lin .sub('', rez) ;        rez = spec4allos .sub('', rez) ;
    elif targetos == 'l':  rez = spec4win .sub('', rez) ;          rez = spec4lin .sub('\\1', rez) ;   rez = spec4allos .sub('', rez) ;
    else:  rez = spec4win .sub('', rez) ;           rez = spec4lin .sub('', rez) ;        rez = spec4allos .sub('\\1', rez) ;
    return rez

def filter_linkify(src):
    rez = src
    #if targetbrowser == 'firefox':
    rez = linkify2.sub('<a href="http_\\1">\\2</a>', rez)
    rez = linkify_local.sub('<a href="\\1">\\2</a>', rez)
    rez = linkify1.sub('<a href="http://\\1">\\1</a>', rez)
    rez = rez.replace('http_', 'http')
    rez = filter_linkify_4kmeleon(rez)
    return rez

def clean_url4fname (url):
    rez = forbiden_in_fname.sub('', url)
    rez = rez.replace('/', '__').strip(' _')
    if rez[0:8] == 'http____': rez = rez[8:]
    return rez


def linkify_4kmeleon(url):
    if targetbrowser == 'kmeleon':
        url2fname = clean_url4fname(url)
    ## !!! LAbai svarbu nekurti labai ilgu vardu - max 63 simboliai, nes paskui CD/DVD gali Windai neskaityt
        ##htmlfname = 'external/'+url2fname+'.redirect.html'
        lchfname = lch_path+'external/'+ url2fname + '.lch'
        ##putftext(htmlfname, url_redirect_tpl.replace('$url', url))
        url_lch_txt = url_lch_tpl.replace('$url', url)  ##lch_start_node_html+htmlfname
        putftext(lchfname, url_lch_txt)
        rezurl = lchfname
    ##elif targetbrowser == 'welcomecenter':
     ##   rezurl = url
    else: rezurl = url
    return rezurl

def filter_linkify_4kmeleon(src):
    rez = src
    if targetbrowser == 'kmeleon':
        ##rez = linkify_kmeleon.sub( '"external/' + clean_url4fname('\\1') + '.lch"', src)
        for match in re.finditer(linkify_kmeleon, src):
            url = match.group(0).strip('\'"')
            lchfname = linkify_4kmeleon(url)
            rez = rez.replace(url, lchfname)
##            url2fname = clean_url4fname(url)
##            htmlfname = 'external/'+url2fname+'.redirect.html'
##            putftext(htmlfname, url_redirect_tpl.replace('$url', url))
##            url_lch_txt = lch_tpl.replace('$pathtofile', lch_start_node_html+htmlfname)
##            putftext(lch_path+'external/'+ url2fname + '.lch', url_lch_txt)
    ##elif targetbrowser == 'welcomecenter':
    return rez

## map program names to file names on disk
letters_lt    = u'ąčęėįšųūžĄČĘĖĮŠŲŪŽ'
letters_latin = 'aceeisuuzACEEISUUZ'
def latinize(str):
    ##print str
    for i in range(len(letters_latin)):
        ##print (letters_lt[i], letters_latin[i])
        str = str.replace(letters_lt[i], letters_latin[i])
    str = re.sub('[^\w ()-_]+', '', str)
    str = re.sub('\s+', '-', str)
    ##str = re.sub('[_-]{2,5}', '-', str)
    return str.encode('ascii', 'ignore').strip('- _')
## --------------

def listofdict_filterkey(listofdict, key):
    reslist = []
    for d in listofdict:
        reslist.append(d[key])
    return reslist    
##    return [d[key]    for d in listofdict]


def sortlist(listofdict, key):
##    newdict = {}
##    index =[]
    n = len(listofdict)
    for i  in range(n):
        for j in range(i, n):
            if listofdict[i][key] > listofdict[i][key]:
                listofdict[i], listofdict[j] = listofdict[j], listofdict[i]
##    for a in listofdict:
##        ##index.append(key)
##        newdict[key] = a
    return listofdict    

def _(str):
    return  str;   
    ## TODO: endof functions

# ----------- get Program Description list ----
##f = open ('src.txt') #( 'programu_mokslui_sarasas.csv' )
f = codecs.open('src.txt', encoding='utf-8')
lines = f.readlines()
f.close()
_imgextraformat = ' border="0" align="right"'
for a in range(50):  print " "

# ------------- Parse the list

outlist = {}
for lang in langs:          #TODO: main loop
    outlist[lang] = []
    for pi in range(len(pages)):
        page = pages[pi]
        pageName = pagenames[pi]
        if pages[pi] == '-': pageName = '__just_4generating_some_lch'
        ## init vals
        _prev_header = ''
        out = ""
        
        pagecatlist = []
        category_progs = []
        category_out = ''

        catname_last  = '' # to trigger the change of category in search-list

        for line in lines[1:]:
            inputline2list = re.split(r'\t', line)[:29]
            #fields = 'os, technology, importance, licence, usefor, catname, progname, linuxrun,  installfname, eninstallfname, progwww, enprogwww, devs, localised, about, moreinfo, morehtml, comments, shortcommings, targetgroup, firststeps, enabout'.split(', ')
            fields1 = 'usefor, catname, progname, _progname, progwww, localised, importance'
            fields2 = 'os'
            fields_extra = 'downloadwww'
            fields_loc = 'progwww, localised'
            os, technology, importance, licence, usefor, catname, progname, linpacketname, linrecommends, linsuggests  , linuxrun,  installfname, windirectrun, eninstallfname, progwww, enprogwww, downloadwww, endownloadwww, lessonswww, enlessonswww, localised, about, moreinfo, morehtml, comments, shortcommings, targetgroup, firststeps, enabout = inputline2list
            abouts = {}
            catnames = {}
            progwwws = {}
            installfnames = {}
            downloadwwws = {}
            lessonswwws = {}
            
            os_alternatives_raw = os
            os = os.split('/')[0]  ## untested are separated with /
            os = os.split('?')[0]
            
            _catnames =  catname.split('|')         ##get/split/prepair languages info
            if len(_catnames) > 1: 
                catnames['lt'], catnames['en'] = _catnames[:len(langs)]
            else: catnames['lt'] = _catnames[0].strip();  catnames['en'] = catnames['lt']
            abouts['lt'] = about
            abouts['en'] = enabout
            progwwws['lt'] = progwww
            progwwws['en'] = enprogwww
            if progwwws['en'].strip() == '': progwwws['en'] = progwww
            installfnames['lt'] = installfname
            installfnames['en'] = eninstallfname
            if installfnames['en'].strip() == '': installfnames['en'] = installfname
            
            downloadwwws['lt'] = downloadwww
            downloadwwws['en'] = endownloadwww
            if downloadwwws['en'].strip() == '': downloadwwws['en'] = downloadwww
            lessonswwws['lt'] = lessonswww
            lessonswwws['en'] = enlessonswww
            if lessonswwws['en'].strip() == '': lessonswwws['en'] = lessonswww
            
            catname = catnames[lang]
            about = abouts[lang]    ## assign current language
            progwww = progwwws[lang]
            installfname = installfnames[lang]
            downloadwww = downloadwwws[lang]
            lessonswww = downloadwwws[lang]
    #end bridging multilang
            if string.strip (catname) != '' and catname.strip() != '!!!':
                if len(category_progs) > 0:   #if there are programs in category
                    out += category_out;   
                    pagecatlist.append(catname_current);             #give rendered contents (if there are any)
                category_progs = []
                catname_current = string.strip(catname) 
                category_out = "<h2 class='catname'><a  id='"+latinize(catname_current)+"' name='"+latinize(catname_current)+"'></a>" +  catname_current + "</h2>\n"
                

            ## start doing the listing job :)
            if os.find('i') !=-1 or targetbrowser== 'firefox' : internet_stuff = True;  # When we (for some reason) have no local install, but still want folks to know about good software
            else: internet_stuff = False;
            
            page_right = 0  ## checks if program fits for this html-page, which is now being generated
            if usefor.find('/')  > -1:
                usefor = usefor.split('/')[0];
                for i in range(len(usefor) ):
                    if page.find(usefor[i] ) > -1: page_right = 1
            elif len(usefor) > 0 and page.find(usefor[0] ) > -1:  page_right = 1
            if ((os.find(targetos) !=-1) or internet_stuff ) and progname.strip() != '' and catname.strip() != '!!!' \
                and page_right and ( importance.strip() != '' and int(importance) > configs.importance_level):
                if    page_right :  ## junk question  (page.find(usefor[0] ) > -1)
	                #_progname = string.split('-', line)[:1]  ## test
	                filter_brackets_re = re.compile( '\(.*?\)')
	                progname4work = filter_brackets_re.sub('', progname)
	                _progname = latinize(progname4work)
	                _progname = _progname.strip(' -').lower()
	                _progname = re.sub(r'[ -]+', '-', _progname )
	                category_progs.append(_progname)
	                
	                if string.strip(progwww) == '':
	                    progwww = "http://www.google.lt/search?q=" + progname4work +"&btnI=I'm Feeling Lucky"
	                
	                if string.strip(downloadwww) == '':
	                    downloadwww = "http://www.google.lt/search?q=" + progname4work +"+download&btnI=I'm Feeling Lucky"
	                #if os_alternatives_raw.find('i') != -1 
	                _download = '<a href="%s" title="%s"><img src="../images/download.png" border="0" %s></a>' % (downloadwww, _(u'parsiųsti %s')% progname4work  , _imgextraformat )
	                if targetbrowser != 'firefox' or downloadwww == '-':
	                    downloadwww = '';
	                    _download = ''
	                
	                
	                linuxrun = linuxrun.strip()
	                if linuxrun=='' or  linuxrun=='_': linuxrun += _progname.lower().strip()
	                


	                _install = ''
	                if targetos == 'w':
	                    if installfname.strip() == '': installfname = _progname
	                    install_path = look_for_install_file(installfname)
	                    lch_fname = lch_path+_progname+'.lch'
	                    if install_path:
	                        print install_path, ' | ', _progname
	                        if fileExists(lch_fname) == False:
	                            print 'CREATE ', lch_fname
	                            new_lch_list.append(lch_fname)
	                            putftext(lch_fname, lch_tpl.replace('$pathtofile', install_path[5:]))
	                        install_file_found = True;
	                    else:
	                        print 'NO INSTALL FOUND: ', _progname
	                        install_file_found = False;
	                    ##if internet_stuff: install_file_found = False;
	    
	                    install_type = ''
	                    if install_file_found:              #discover install method (installation file type)
	                        flch = open ( lch_fname, 'r' )
	                        lch_txt = flch.read()
	                        if lch_txt.find('.direct')  > -1:
	                            install_type = 'rundirectly'
	                        elif (lch_txt.find('.exe') > -1) or (lch_txt.find('.exe') > -1) or (lch_txt.find('.msi') > -1 ) :
	                            install_type = 'exe'
	                        elif lch_txt.find('.zip') > -1:  ##re.compile(r'.*\.(zip|7z|tgz|gz|tar|rar)').match(lch_txt):  ##
	                            install_type = 'zip'
	                        elif lch_txt.find('.jar') > -1:  ##re.compile(r'.*\.(zip|7z|tgz|gz|tar|rar)').match(lch_txt):  ##
	                            install_type = 'exe'
	                        flch.close()
	                        if install_type == 'rundirectly' :
	                            _install = unicode('<a href="../lch/'+ _progname +u'.lch" title=\'Tiesiogiai paleisti "'+progname+u'"\' > \
	                            <img src="../images/rundirectly.png"  alt=\'Tiesiogiai paleisti "'+progname+'"\' align="right" border="0"></a>')
	                        elif install_type == 'exe' :
	                            _install = '<a href="../lch/'+ _progname +u'.lch" title=\'Įdiegti "'+progname+'"\' > \
	                            <img src="../images/install_smaller.png"  alt=\''+u'Įdiegti "'+progname+'"\' align="right" border="0"></a>'
	                        elif install_type == 'zip' :
	                            _install = unicode('<a href="../lch/'+ _progname +u'.lch" title=\'Išpakuoti "'+progname+u'"\' > \
	                            <img src="../images/install_zip.png"  alt=\'Išpakuoti "'+progname+'"\' align="right" border="0"></a>')
	                        elif install_type == 'jar' :
	                            _install = unicode('<a href="../lch/'+ _progname +u'.lch" title=\'Instaliuoti (java start) "'+progname+u'"\' > \
	                            <img src="../images/install_jar.gif"  alt=\'Instaliuoti (java start) "'+progname+'"\' align="right" border="0"></a>')
	                        #elif  install_file_found == False: _install = ''
	                        #end if targetos == 'w'    
	               
	                img_path_fname = img_root + _progname 
	                imgtype = ''
	                if imgExists(_progname+".png") != '' :  imgtype = '.png'
	                elif imgExists(_progname+".gif") != '' : imgtype = '.gif'
	                elif imgExists(_progname+".jpg") != '' : imgtype = '.jpg'
	                
	                if imgtype  != ''  : img_html = "<img src ='" +img_root+imgExists(_progname+imgtype)+ "' align = 'left'>  "
	                else: img_html = '<span id="missing: "'+ _progname+'"></span>'
	                if targetbrowser == 'kmeleon':
##	                    if _progname == 'geogebra':
##	                        print progwww, lang
	                    progwww = linkify_4kmeleon(progwww);
	                _title =  "<span class='progname'><a  href = \""+ progwww + "\"  title='\"" + progname +u"\" svetainė\'>"+ progname +"</a></span>  "

	                _run =  '' 
	                _run_txt = '' 

	                if  targetbrowser == 'welcomecenter':  # LINUX
	                    ##print linuxrun
	                    if not (linuxrun in ['', '-'] or os.find(targetos) ==-1):
	                        if linuxrun.find('file://') ==-1: 
	                            linuxrun = 'run://'+linuxrun
	                        ##else: print 'FILE: ' + linuxrun	
	                        ##_title =  '<span class="progname"><a  href = "run://'+ linuxrun +'" '+ u'  title="paleisti programą &quot;' +  progname +'&quot;"  >' + progname +'</a></span>  '
	                        _run = '<a  href = "' +linuxrun +'" '+ u'  title="paleisti programą &quot;' +  progname +'&quot;"  ><img src="../images/start_'+lang+'.png"  border="0"></a>'
	                        _run_txt = '<a  href = "'+ linuxrun +'" '+ u'  title="paleisti programą &quot;' +  progname +'&quot;"  >'+progname4work +'<span style="font-weight:normal; color:grey"> (paleisti)<span>'+'</a>'
	                    else: _run = '';  _run_txt = progname4work;    
	                    _run_txt = '<b>'+_run_txt+'</b>';    
	                    
	                    _run = _run.replace('run://_', 'run-terminal://')
	                    _run_txt = _run_txt.replace('run://_', 'run-terminal://')
	               #_install = unicode('<a  href = \"run://"+ linuxrun+ u'  title="paleisti programą &quot;' +  progname +'&quot;"  > ' + '<img src="../images/rundirectly.gif align="right" border="0"></a>')
##                    else: _title =  '<span class="progname">'+ progname +'</span>  '   
##    #                img_html = "<img src ='" +img_path_fname+".png"+ "' align = 'left'>  "
##                    _title += ' (<a href="%s">www</a>)' % progwww			    
	                if morehtml != '':
	                    _more = '<a href="'+ morehtml + '"><img  src="../images/info.gif"  title=\'Daugiau informacijos apie "'+progname+'"\' alt=\'Daugiau informacijos apie "'+progname+'"\' align="right" border="0"></a>'
	                else : _more = ''
	                
	                _oslabel = ''
	                if targetos != 'w' and targetos!='l':
	                    if os_alternatives_raw.find('l') >-1 :  _oslabel += '<img src="../images/lin.png" alt="Linux" %s>' % _imgextraformat
	                    if os_alternatives_raw.find('w') >-1 :  _oslabel += '<img src="../images/win.png" alt="Windows" %s> ' % _imgextraformat
	                    
	                localised = localised.strip()
	                if localised != '' : ilocalised = int(localised)
	                _localised = ''
	                if re.match('\d+', localised):
	                    if ilocalised > 88: _localised = u'<img  src="../images/lt.gif"  title="Išversta į lietuvių kalbą" alt="Išversta į lietuvių kalbą" extra="'+localised+'%" align="right" border="0" />' ##'(pilnai sulietuvinta)'
	                    elif ilocalised > 40: _localised = u'<img  src="../images/lt-partly.gif"  title="Dalinai išversta į lietuvių kalbą" alt="Dalinai išversta į lietuvių kalbą" extra="'+localised+'%" align="right" border="0" />' ##'(dalinai sulietuvinta)'

	                _www_txt = '<a href="%s">%s</a>' % (progwww,  progname4work) 
			#if targetbrowser == 'welcomecenter': _imgextraformat = ' style="align:right"';

	                _www = '<a href="%s"><img src="../images/www.png" %s></a>' %  (progwww, _imgextraformat)
	                _www4list = _www #for list in firefox (as original will be deprecated)

	                if targetbrowser == 'firefox' or targetbrowser == 'kmeleon':
	                    _www = ''; _www_txt = ''
	                else: _www4list = ''; _www += '<br>';
	                #_more = ''
	                
	                
	                _header_extras =  _install + _run + _download + _www + _oslabel + _more + _localised ## + "&nbsp;" +"&nbsp;" #+"<br />"
	                _header = img_html + _header_extras  + _title 
	              
	                if targetbrowser == 'welcomecenter': # LINUX
	                    _header = _www + img_html    + _localised +   _run_txt   #+"&nbsp;&nbsp;" +"<br />"           # _run + 
	                    _header_extras = _run + _www + _more + _localised 
	                    
	                          #"<table width='90%' style='display:inline' > <tr width='90%'>  <td>"+ _title +"</td>    <td align='right'>"+_install+"</td></tr></table> <br />"
	                _header = '<a id="'+_progname+'" name="'+_progname+'"></a>' + _header + '<br />'  #anchor
	                
	                #print "<div class ='program'> %s &nbsp %s <br> %s </div>"  % (_header, _install, about)
	                if about.strip() == '...':
	                    _prev_header += _header
	                    ##"&nbsp  <hr style='width:80%; height:1px; color:darkgreen;'> "
	                else:
	                    about = about.strip(' -')
	                    about = about.replace('--', '<br />')
	                    about =  filter_linkify(about)
	                    about = filter_os(about)
	                    ##about = "<div  style='float:left; position:relative;'>  "+img_html +"</div>" + about
	                    category_out +=  "<div class ='program'> "+ _prev_header + _header + "<div style=''> "+'&nbsp;' + about+" </div></div>"
	                    
	                    if targetbrowser == 'welcomecenter': category_out += '<hr>'
	                    _prev_header = ''
	                     #fields1 = 'usefor, catname, progname, _progname, progwww, localised, importance'
	                    outli_html = _header_extras +_www4list + '<a href="%s.html#%s">%s</a> ' % (pageName, _progname, progname4work)
	                    #
	                    outtr_html = '<tr> <td> %s<a href="%s.html#%s"><img src="../images/go.png" border="0"></a> </td>  <td> %s </td>  <td>  %s%s </td>  </tr>' % ( progname4work,  pageName, _progname,  catname_current,   _www4list.replace(_imgextraformat, 'border="0"')        ,    _header_extras.replace(_imgextraformat, 'border="0"') )
	                    if catname_last != catname_current: 
	                        outli_html = "<h2>%s</h2>" % catname_current + outli_html
	                        catname_last = catname_current
	                    dkeys = fields1.split(', ')+['outli_html', 'outtr_html']
	                    dfields = [usefor, catname_current, progname, _progname, progwww, localised, importance]+[outli_html, outtr_html]
	                    d_ = {}
	                    for i in range(len(dkeys)):  d_[dkeys[i]] = dfields[i];  #print d_
	                    outlist[lang].append( d_)


        if len(category_progs) > 0: out += category_out   #print last category          #give rendered contents (if there are any)

        catlist_html = ' | '.join(['<a href="#%s">%s</a>' % ( latinize(c), c.replace(' ', '&nbsp;') )  for c in  pagecatlist])
        out = '<div id="catlist" class="submenu" >' +catlist_html +' </div>'+ '<div id="proglist"> ' + out + '</div>';
        putftextU( 'raw_content/'+lang + '/'+pageName+'.html', out)
        
    outlist_html =   '<hr class="tiny">'.join(listofdict_filterkey(outlist[lang], 'outli_html'))  
    outlist_table_html = '\n'.join(listofdict_filterkey(outlist[lang], 'outtr_html'))  
    jsroot = '../js/'
    jstsortroot = jsroot+'standardista_table_sorting/'
    sort_table_js = '''
    		<script type='text/javascript' src='%s/common.js'></script>
		<script type='text/javascript' src='%s/css.js'></script>
		<script type='text/javascript' src='%s/standardista-table-sorting.js'></script>
		
	
    ''' % (jstsortroot, jstsortroot, jstsortroot)
    filter_table_form = '''
       <form class = "filter" id="filterform"> <b>Paie&scaron;ka:</b>&nbsp;<input id ="searchfilter" type ="text" onkeyup="filterTable_byName(this, 'list')"/> </form>
       
    '''
    filter_table_js = '	 <script type="text/javascript" src="%s/filterTable.js"/>' % jsroot
    outlist_table_html = sort_table_js + '<table id = "list" class="sortable filterable  autostripe"><thead><tr><th>Pavadinimas</th><th>Kategorija</th><th>Funkcijos</th> </tr></thead> <tbody> %s </tbody></table>'   % outlist_table_html
    outlist_html = ''
    if targetbrowser == 'firefox': outlist_table_html =  filter_table_form  + outlist_table_html + filter_table_js
    else: outlist_html = _(u' <b>Paieškai naudotike "Ctrl+F" kombinaiciją</b><br> ')
    outlist_html += _(u' Spustelėję stulpelio antraštę pasirinkite rikiavimo tvarką<hr>')+outlist_html
    outlist_html = outlist_table_html
    putftextU( 'raw_content/'+lang + '/listall.html', outlist_html) 



if targetos == 'w':
    print '\nUNUSED INSTALLABLES: '
    installable_files_set = set(installable_files)
    installable_files_used_set = set(installable_files_used)
    unused_installables_list =list(installable_files_set - installable_files_used_set )
    unused_installables_list.sort()
    pprint.pprint (unused_installables_list )

##print '\nNEW LAUNCHER FILES: '
##pprint.pprint (new_lch_list)

#pprint.pprint(img_fnames)
#pprint.pprint(found_imgs)

##print out


## CALL template-wrapper
import wrap_into_design_templates
