Esempio n. 1
0
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()
Esempio n. 2
0
def exporttext(appname, style, optstr):
	opts, args = getopt(optstr, 'NHTs:cah')
	opts = dict(opts)
	out = StringIO()
	if _osaxpathsbyname.has_key(appname):
		appname = _osaxpathsbyname[appname]
	else:
		appname = aem.findapp.byname(appname)
	quickdoc.app(appname, out, getconverter(style))
	return out.getvalue()
Esempio n. 3
0
def exporttext(appname, style, optstr):
    opts, args = getopt(optstr, 'NHTs:cah')
    opts = dict(opts)
    out = StringIO()
    if _osaxpathsbyname.has_key(appname):
        appname = _osaxpathsbyname[appname]
    else:
        appname = aem.findapp.byname(appname)
    quickdoc.app(appname, out, getconverter(style))
    return out.getvalue()
Esempio n. 4
0
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()
Esempio n. 5
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, 'objc-appscript', '%s%sGlue' %
                    (exportToSubfolders and 'glues/' or '', objcPrefix), '')
                renderer = osaglue.GlueRenderer(outputPath, objcPrefix)
                if isOSAX:
                    renderer.renderosaxaetes(path, aetes)
                else:
                    renderer.renderappaetes(path, 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())
Esempio n. 6
0
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:
            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)
        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())
Esempio n. 7
0
		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')
			if not exists(userTemplatePath):
				userTemplatePath = join(osax.pathto(osax.kApplicationSupport).path, 'ASDictionary/Template.html')
			if exists(userTemplatePath):
				f = open(userTemplatePath)
				userTemplateHTML = f.read()
				f.close()
			else:
				userTemplateHTML = None
			if kAppscript in outFormat:
Esempio n. 8
0
         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')
 if not exists(userTemplatePath):
     userTemplatePath = join(
         osax.pathto(osax.kApplicationSupport).path,
         'ASDictionary/Template.html')
 if exists(userTemplatePath):
     f = open(userTemplatePath)
     userTemplateHTML = f.read()
Esempio n. 9
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, 'objc-appscript', 
							'%s%sGlue' % (exportToSubfolders and 'glues/' or '', objcPrefix), '')
				renderer = osaglue.GlueRenderer(outputPath, objcPrefix)
				if isOSAX:
					renderer.renderosaxaetes(path, aetes)
				else:
					renderer.renderappaetes(path, 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())