Beispiel #1
0
def getaetedata(appname):
	if _osaxpathsbyname.has_key(appname.lower()):
		return getappterminology(_osaxpathsbyname[appname.lower()])
	elif appname.startswith('eppc://'):
		return terminology.aetedataforapp(aem.Application(url=appname))
	else:
		return getappterminology(aem.findapp.byname(appname))
Beispiel #2
0
def getaetedata(appname):
    if _osaxpathsbyname.has_key(appname.lower()):
        return getappterminology(_osaxpathsbyname[appname.lower()])
    elif appname.startswith('eppc://'):
        return terminology.aetedataforapp(aem.Application(url=appname))
    else:
        return getappterminology(aem.findapp.byname(appname))
Beispiel #3
0
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 = getappterminology(path)
    parse(data, QuickDoc(out, converter))
Beispiel #4
0
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 = getappterminology(path)
    parse(data, QuickDoc(out, converter))
Beispiel #5
0
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()
Beispiel #6
0
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'.format(apppath))
	for key, value in atts:
		if key[0] != '_':
			f.write('\n{} = \\\n'.format(key))
			pprint(value, f)
	f.close()
Beispiel #7
0
def _export(items, styles, plainText, singleHTML, frameHTML, objcGlue, options,
            outFolder, exportToSubfolders, progress):
    styleInfo = [(style, kStyleToSuffix[style]) for style in styles]
    # process each item
    for i, item in enumerate(items):
        objcPrefix, name, path, isOSAX = item['objcPrefix'], item[
            'name'], item['path'], item['isOSAX']
        progress.nextitem(name, path)
        try:
            try:
                aetes = getappterminology(path)
            except MacOSError, e:
                if e.args[0] != -192:
                    raise
                aetes = []
            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)
            if objcGlue:
                outputPath = _makeDestinationFolder(
                    outFolder, exportToSubfolders and 'objc-appscript' or '',
                    '%s%sGlue' %
                    (exportToSubfolders and 'glues/' or '', objcPrefix), '')
                if isOSAX:
                    objcglue.makeosaxglue(path, objcPrefix, outputPath, aetes)
                else:
                    objcglue.makeappglue(path, objcPrefix, outputPath, aetes)
                progress.nextoutput(u'%s' % outputPath)
        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())
Beispiel #8
0
def _export(items, styles, plainText, singleHTML, frameHTML, objcGlue, options, outFolder, exportToSubfolders, progress):
	styleInfo = [(style, kStyleToSuffix[style]) for style in styles]
	# process each item
	for i, item in enumerate(items):
		objcPrefix, name, path, isOSAX = item['objcPrefix'], item['name'], item['path'], item['isOSAX']
		progress.nextitem(name, path)
		try:
			try:
				aetes = getappterminology(path)
			except MacOSError, e:
				if e.args[0] != -192:
					raise
				aetes = []
			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)
			if objcGlue:
				outputPath = _makeDestinationFolder(outFolder, exportToSubfolders and 'objc-appscript' or '', 
							'%s%sGlue' % (exportToSubfolders and 'glues/' or '', objcPrefix), '')
				if isOSAX:
					objcglue.makeosaxglue(path, objcPrefix, outputPath, aetes)
				else:
					objcglue.makeappglue(path, objcPrefix, outputPath, aetes)
				progress.nextoutput(u'%s' % outputPath)
		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())
Beispiel #9
0
def parseapp(path, style='appscript'):
	return parseaetes(getappterminology(path), path, style)
Beispiel #10
0
def parseapp(path, style='appscript'):
    return parseaetes(getappterminology(path), path, style)