def getaetedata(appname): if _osaxpathsbyname.has_key(appname.lower()): return getaete(_osaxpathsbyname[appname.lower()]) elif appname.startswith('eppc://'): return terminology.aetedataforapp(aem.Application(url=appname)) else: return getaete(aem.findapp.byname(appname))
def getaetedata(appname): if _osaxpathsbyname.has_key(appname.lower()): return getaete(_osaxpathsbyname[appname.lower()]) elif appname.startswith('eppc://'): return terminology.aetedataforapp(aem.Application(url=appname)) else: return getaete(aem.findapp.byname(appname))
def __init__(self, osaxname='StandardAdditions', name=None, id=None, creator=None, pid=None, url=None, aemapp=None, terms=True): self._osaxname = osaxname osaxname = osaxname.lower() if osaxname.endswith('.osax'): osaxname = osaxname[:-5] if terms == True: try: osaxpath, terms = _osaxcache[osaxname] except KeyError: raise KeyError, "Scripting addition not found: %r" % self._osaxname if not terms: terms = _osaxcache[osaxname][1] = terminology.tablesforaetes( getaete(osaxpath)) reference.Application.__init__(self, name, id, creator, pid, url, aemapp, terms) try: self.AS_appdata.target.event('ascrgdut').send( 300 ) # make sure target application has loaded event handlers for all installed OSAXen except aem.CommandError, e: if e.number != -1708: # ignore 'event not handled' error raise
def _export(items, styles, plainText, singleHTML, frameHTML, options, outFolder, exportToSubfolders, progress): styleInfo = [(style, kStyleToSuffix[style]) for style in styles] # process each item for i, item in enumerate(items): name, path = item['name'], item['path'] progress.nextitem(name, path) try: aetes = getaete(path) if not bool(aetes): progress.didfail(u"No terminology found.") continue for style, suffix in styleInfo: styleSubfolderName = exportToSubfolders and style or '' if not progress.shouldcontinue(): for item in items[i:]: progress.didfail(u"User cancelled.") progress.nextapp(item['name'], item['path']) progress.didfail(u"User cancelled.") progress.didfinish() return if plainText: outputPath = _makeDestinationFolder( outFolder, styleSubfolderName, exportToSubfolders and 'text', name + suffix + '.txt') progress.nextoutput(u'%s' % outputPath) f = file(outputPath, 'w') try: f.write('\xEF\xBB\xBF') # UTF8 BOM quickdoc.app(path, f, getconverter(style)) except: f.close() raise f.close() if singleHTML or frameHTML: terms = aeteparser.parseaetes(aetes, path, style) if singleHTML: outputPath = _makeDestinationFolder( outFolder, styleSubfolderName, exportToSubfolders and 'html', name + suffix + '.html') progress.nextoutput(u'%s' % outputPath) html = htmldoc.renderdictionary(terms, style, options) f = open(outputPath, 'w') f.write(str(html)) f.close() if frameHTML: outputPath = _makeDestinationFolder( outFolder, styleSubfolderName, exportToSubfolders and 'frame-html', name + suffix) progress.nextoutput(u'%s' % outputPath) htmldoc2.renderdictionary(terms, outputPath, style, options) except Exception, err: from traceback import print_exc from StringIO import StringIO out = StringIO() print_exc(file=out) progress.didfail(u'Unexpected error:/n%s' % out.getvalue()) else: progress.didsucceed()
def app(path, out=sys.stdout, converter=None): """Render raw terminology for application. path : str -- full path to application out : file -- open file object to write to (default: stdout) converter : function -- function to convert AppleScript-style keywords (default: None) """ data = getaete(path) parse(data, QuickDoc(out, converter))
def app(path, out=sys.stdout, converter=None): """Render raw terminology for application. path : str -- full path to application out : file -- open file object to write to (default: stdout) converter : function -- function to convert AppleScript-style keywords (default: None) """ data = getaete(path) parse(data, QuickDoc(out, converter))
def _export(items, styles, plainText, singleHTML, frameHTML, options, outFolder, exportToSubfolders, progress): styleInfo = [(style, kStyleToSuffix[style]) for style in styles] # process each item for i, item in enumerate(items): name, path = item['name'], item['path'] progress.nextitem(name, path) try: aetes = getaete(path) if not bool(aetes): progress.didfail(u"No terminology found.") continue for style, suffix in styleInfo: styleSubfolderName = exportToSubfolders and style or '' if not progress.shouldcontinue(): for item in items[i:]: progress.didfail(u"User cancelled.") progress.nextapp(item['name'], item['path']) progress.didfail(u"User cancelled.") progress.didfinish() return if plainText: outputPath = _makeDestinationFolder(outFolder, styleSubfolderName, exportToSubfolders and 'text', name + suffix + '.txt') progress.nextoutput(u'%s' % outputPath) f = file(outputPath, 'w') try: f.write('\xEF\xBB\xBF') # UTF8 BOM quickdoc.app(path, f, getconverter(style)) except: f.close() raise f.close() if singleHTML or frameHTML: terms = aeteparser.parseaetes(aetes, path, style) if singleHTML: outputPath = _makeDestinationFolder(outFolder, styleSubfolderName, exportToSubfolders and 'html', name + suffix + '.html') progress.nextoutput(u'%s' % outputPath) html = htmldoc.renderdictionary(terms, style, options) f = open(outputPath, 'w') f.write(str(html)) f.close() if frameHTML: outputPath = _makeDestinationFolder(outFolder, styleSubfolderName, exportToSubfolders and 'frame-html', name + suffix) progress.nextoutput(u'%s' % outputPath) htmldoc2.renderdictionary(terms, outputPath, style, options) except Exception, err: from traceback import print_exc from StringIO import StringIO out = StringIO() print_exc(file=out) progress.didfail(u'Unexpected error:/n%s' % out.getvalue()) else: progress.didsucceed()
def dump(apppath, modulepath): """Dump terminology data to Python module. apppath : str -- name or path of application modulepath : str -- path to generated module """ tables = buildtablesforaetes(getaete(findapp.byname(apppath))) atts = zip(('classes', 'enums', 'properties', 'elements', 'commands'), tables) f = file(expanduser(modulepath), 'w') print >> f, 'version = 1.1' print >> f, 'path = %r' % apppath for key, value in atts: if key[0] != '_': print >> f, '\n%s = \\\n' % key, pprint(value, f) f.close()
def dump(apppath, modulepath): """Dump terminology data to Python module. apppath : str -- name or path of application modulepath : str -- path to generated module """ apppath = findapp.byname(apppath) aetes = [aete.data for aete in getaete(apppath) if isinstance(aete, AEDesc) and aete.type == 'aete'] tables = buildtablesforaetes(aetes) atts = zip(('classes', 'enums', 'properties', 'elements', 'commands'), tables) f = file(modulepath, 'w') print >> f, 'version = 1.1' print >> f, 'path = %r' % apppath for key, value in atts: if key[0] != '_': print >> f, '\n%s = \\' % key pprint(value, f) f.close()
def __init__(self, osaxname='StandardAdditions', name=None, id=None, creator=None, pid=None, url=None, aemapp=None, terms=True): self._osaxname = osaxname osaxname = osaxname.lower() if osaxname.endswith('.osax'): osaxname = osaxname[:-5] if terms == True: try: osaxpath, terms = _osaxcache[osaxname] except KeyError: raise KeyError, "Scripting addition not found: %r" % self._osaxname if not terms: terms = _osaxcache[osaxname][1] = terminology.tablesforaetes(getaete(osaxpath)) reference.Application.__init__(self, name, id, creator, pid, url, aemapp, terms) try: self.AS_appdata.target.event('ascrgdut').send(300) # make sure target application has loaded event handlers for all installed OSAXen except aem.CommandError, e: if e.number != -1708: # ignore 'event not handled' error raise
def __call__(self, flags, ref): if not self.helpobj: from appscript import helpsystem self.helpobj = helpsystem.Help(getaete(self.osaxpath), self.osaxpath) return self.helpobj.help(flags, ref)
def __call__(self, flags, ref): if not self.helpobj: from appscript import helpsystem self.helpobj = helpsystem.Help(getaete(self.osaxpath), self.osaxpath) return self.helpobj.help(flags, ref)
def parseapp(path, style='appscript'): return parsestring(getterminology.getaete(path), path, style)
options = ['collapse'] else: options = [] outFolder = (osax.choosefolder('Select folder to write the file%s to:' % (len(appPaths) > 1 and 's' or ''))).path failedApps = [] progbar = ProgressBar('Rendering terminology for:', len(appPaths)) for path in appPaths: progbar.label(splitext(basename(path))[0].encode('macroman', 'replace')[:254]) # ProgressBar is kinda Stone Age progbar.inc() try: # Dump aetes if kRaw in outFormat: targetFolder = join(outFolder, splitext(basename(path))[0]) + ' aetes' # app may have >1 aetes, so dump them into a single folder if not exists(targetFolder): mkdir(targetFolder) for i, aete in enumerate(getaete(path)): f = open(join(targetFolder, str(i)), 'w') f.write(aete) f.close() # Render in quickdoc format if kText in outFormat: f = file(join(outFolder, splitext(basename(path))[0] + '.txt'), 'w') try: f.write('\xEF\xBB\xBF') # UTF8 BOM quickdoc.app(path, f) except: f.close() raise f.close() # Render in HTML format userTemplatePath = join(osax.pathto(osax.kApplicationSupport, osax.kUserDomain).path, 'ASDictionary/AppleScriptTemplate.html')
progbar = ProgressBar('Rendering terminology for:', len(appPaths)) for path in appPaths: progbar.label( splitext(basename(path))[0].encode( 'macroman', 'replace')[:254]) # ProgressBar is kinda Stone Age progbar.inc() try: # Dump aetes if kRaw in outFormat: targetFolder = join( outFolder, splitext(basename(path))[0] ) + ' aetes' # app may have >1 aetes, so dump them into a single folder if not exists(targetFolder): mkdir(targetFolder) for i, aete in enumerate(getaete(path)): f = open(join(targetFolder, str(i)), 'w') f.write(aete) f.close() # Render in quickdoc format if kText in outFormat: f = file(join(outFolder, splitext(basename(path))[0] + '.txt'), 'w') try: f.write('\xEF\xBB\xBF') # UTF8 BOM quickdoc.app(path, f) except: f.close() raise f.close() # Render in HTML format