Annotation of kupuMPIWG/plone/scanner.py, revision 1.1
1.1 ! dwinter 1: import os, re
! 2:
! 3: IDPATTERN = re.compile(r'\$\Id[^$]*\$')
! 4: JSPATTERN = re.compile(r'(?:string:\$\{portal_url\}/([^."]+.js)")|(?:\<link href="([^."]*.css)")')
! 5: KWS = 'kupu_wysiwyg_support'
! 6: ROOT = os.path.dirname(os.path.dirname(__file__))
! 7:
! 8: def matchFiles(extension, root, paths):
! 9: for dirname in paths:
! 10: dirname = os.path.join(root, dirname)
! 11: files = os.listdir(dirname)
! 12: for f in files:
! 13: if f.endswith(extension):
! 14: yield f, os.path.join(dirname, f)
! 15:
! 16: def getFileData(path):
! 17: fh = open(path, 'rU')
! 18: try:
! 19: return fh.read()
! 20: finally:
! 21: fh.close()
! 22:
! 23: def getKWS(root):
! 24: return os.path.join(root, 'plone', 'kupu_plone_layer', KWS+'.html')
! 25:
! 26: def scanFile(path):
! 27: '''Scan a single file returning all the Id strings it contains'''
! 28: ids = IDPATTERN.findall(getFileData(path))
! 29: return ids
! 30:
! 31:
! 32: def scanKWS(root=ROOT):
! 33: try:
! 34: wysiwyg = scanFile(getKWS(root))
! 35: except:
! 36: return KWS, "cannot open template: run make"
! 37:
! 38: wysiwyg = dict.fromkeys(wysiwyg)
! 39:
! 40: for fname, path in matchFiles('.kupu', root, ('default', 'plone')):
! 41: for id in scanFile(path):
! 42: if id in wysiwyg:
! 43: del wysiwyg[id]
! 44: if wysiwyg:
! 45: return KWS, "template appears to be out of date: run make"
! 46: return KWS, ''
! 47:
! 48: def scanIds(root=ROOT):
! 49: status = {}
! 50: wanted = {}
! 51: for groups in JSPATTERN.findall(getFileData(getKWS(root))):
! 52: for group in groups:
! 53: if group:
! 54: wanted[group] = None
! 55:
! 56: wanted = dict([ (name, None)
! 57: for groups in JSPATTERN.findall(getFileData(getKWS(root)))
! 58: for name in groups if name])
! 59:
! 60: for fname, path in matchFiles('.js', root, ('common', os.path.join('plone', 'kupu_plone_layer'))):
! 61: if fname in wanted:
! 62: for id in scanFile(path):
! 63: status[fname] = id
! 64: res = status.items()
! 65: res.sort()
! 66: return res
! 67:
! 68: if __name__=='__main__':
! 69: print scanKWS('..')
! 70: print scanIds('..')
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>