def dump(apppath, modulepath): """Dump application terminology data to Python module. apppath : str -- name or path of application modulepath : str -- path to generated module Generates a Python module containing an application's basic terminology (names and codes) as used by appscript. Call the dump() function to dump faulty aetes to Python module, e.g.: dump('MyApp', '/path/to/site-packages/myappglue.py') Patch any errors by hand, then import the patched module into your script and pass it to appscript's app() constructor via its 'terms' argument, e.g.: from appscript import * import myappglue myapp = app('MyApp', terms=myappglue) Note that dumped terminologies aren't used by appscript's built-in help system. """ apppath = findapp.byname(apppath) tables = buildtablesforaetes(aetesforapp(Application(apppath))) dumptables(tables, apppath, modulepath)
def tablesforaetes(aetes): """Build terminology tables from a list of unpacked aete byte strings. Result : tuple of dict -- (typebycode, typebyname, referencebycode, referencebyname) """ classes, enums, properties, elements, commands = buildtablesforaetes(aetes) return _maketypetable(classes, enums, properties) + _makereferencetable( properties, elements, commands)
def tablesforapp(path=None, url=None): if not _terminologyCache.has_key(path or url): classes, enums, properties, elements, commands = buildtablesforaetes( getaetedata(path, url)) _terminologyCache[path or url] = _makeTypeTable( classes, enums, properties) + _makeReferenceTable( properties, elements, commands) return _terminologyCache[path or url]
def tablesforapp(path=None, url=None): if not _terminologyCache.has_key(path or url): try: aetes = Application(path, url).event('ascrgdte', {'----':0}).send() except Exception, e: # (e.g.application not running) raise RuntimeError, "Can't get terminology for application (%s): %s" % (path or url, e) if not isinstance(aetes, list): aetes = [aetes] #print [aete.data for aete in aetes if aete.type == 'aete'] classes, enums, properties, elements, commands = buildtablesforaetes([aete.data for aete in aetes if aete.type == 'aete']) _terminologyCache[path or url] = _makeTypeTable(classes, enums, properties) + _makeReferenceTable(properties, elements, commands)
def tablesforapp(path=None, url=None): if not _terminologyCache.has_key(path or url): try: aetes = Application(path, url).event('ascrgdte', { '----': 0 }).send() except Exception, e: # (e.g.application not running) raise RuntimeError, "Can't get terminology for application (%s): %s" % ( path or url, e) if not isinstance(aetes, list): aetes = [aetes] #print [aete.data for aete in aetes if aete.type == 'aete'] classes, enums, properties, elements, commands = buildtablesforaetes( [aete.data for aete in aetes if aete.type == 'aete']) _terminologyCache[path or url] = _makeTypeTable( classes, enums, properties) + _makeReferenceTable( properties, elements, commands)
def dump(apppath, modulepath): """Dump terminology data to Python module. apppath : str -- name or path of application modulepath : str -- path to generated module Generates a Python module containing an application's basic terminology (names and codes) as used by appscript. Call the dump() function to dump faulty aetes to Python module, e.g.: dump('MyApp', '/Library/Python/2.5/site-packages/myappglue.py') Patch any errors by hand, then import the patched module into your script and pass it to appscript's app() constructor via its 'terms' argument, e.g.: from appscript import * import myappglue myapp = app('MyApp', terms=myappglue) Note that dumped terminologies aren't used by appscript's built-in help system. """ from pprint import pprint from sys import argv apppath = findapp.byname(apppath) tables = buildtablesforaetes(ae.getappterminology(apppath)) atts = zip(('classes', 'enums', 'properties', 'elements', 'commands'), tables) f = open(modulepath, 'w') f.write('version = 1.1\n') f.write('path = %r\n' % apppath) for key, value in atts: if key[0] != '_': f.write('\n%s = \\\n' % key) pprint(value, f) f.close()
def tablesforaetedata(aetes): """Build terminology tables from a list of unpacked aete byte strings. Result : tuple of dict -- (typebycode, typebyname, referencebycode, referencebyname) """ classes, enums, properties, elements, commands = buildtablesforaetes(aetes) return _makeTypeTable(classes, enums, properties) + _makeReferenceTable(properties, elements, commands)
def tablesforapp(path=None, url=None): if not _terminologyCache.has_key(path or url): classes, enums, properties, elements, commands = buildtablesforaetes(getaetedata(path, url)) _terminologyCache[path or url] = _makeTypeTable(classes, enums, properties) + _makeReferenceTable(properties, elements, commands) return _terminologyCache[path or url]