#!/usr/bin/python # -*- coding: utf8 -*- #====================================================================== #Basisverzeichnis der Library-Dateien hier einstellen. #Es MUSS als Unterverzeichnis im Pfad des Server-Verzeichnisses liegen. Librarybase = u'kicadlib.org/' # Am Ende muss ein '/' stehen. #====================================================================== import os import zipfile import cgi import sqlite3 f = cgi.FieldStorage() cmd = f.getfirst('cmd', None) showimg = f.getfirst('showimg', False) if showimg: showimg = True db = sqlite3.connect('KiCad.sqlite3') c = db.cursor() c.execute('CREATE TABLE IF NOT EXISTS symbols (filename TEXT, datetime TEXT, symbol TEXT)') print """Content-type: text/html KiCad Library-Verwaltung

KiCad Library-Verwaltung

""" print "Server-Basisverzeichnis: %s
Library-Basisverzeichnis: %s
" % (os.getcwd(), Librarybase) print 'Befehle:' print 'Dateien anzeigen (mit Bildern)' print ' - Library-Dateien nach Symbolnamen abscannen' #print ' - In DB eingelesene Library-Dateien auflisten' #print ' - Symbole in DB auflisten' print "
" symbollist = {} # Get the symbol names of the lib file def scanfile(fname, f): print len(f), 'Bytes' for line in f.split('\n'): if line.startswith('DEF '): symbolname = line.split(' ')[1] if symbolname not in symbollist: symbollist[symbolname] = [fname] else: symbollist[symbolname].append(fname) print '-', '', symbolname, '' return True #hack to circumvent filename codings in zip files which create problems def sanitized(s): try: s2 = s.encode('utf8') except: s2 = '' for c in s: if c.isalpha(): s2 += c else: s2 += '?' return s2 #Selector for user commands if cmd == 'show': for root, dirs, files in os.walk(Librarybase): for f in files: print root + '/' + f, '
' if showimg and (f.endswith('.png') or f.endswith('.jpg')): print '
' elif f.endswith('.zip'): print '' if cmd == 'scan': print '

Scanning...

' for root, dirs, files in os.walk(Librarybase): for f in files: fname = root + '/' + f if f.endswith('.lib'): print root + '/' + f, '' print 'OK' if scanfile(fname, open(fname).read()) else 'Error' print '
' elif f.endswith('.zip'): print root + '/' + f, '
' print '' print '

Gefundene Symbole:

' print 'Anzahl Symbole: %i
' % len(symbollist) print '

Liste:

' for i,s in enumerate(sorted(symbollist)): print s, '|', print '
' print '

Dateizuordnung:

' elif cmd == 'listfiles': pass #Not implemented elif cmd == 'listsymbols': pass #Not implemented print """
"""