Esempio n. 1
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())
Esempio n. 2
0
def export(items, styles, plainText, singleHTML, frameHTML, objcGlue, options, outFolder, exportToSubfolders, progress, info={}):
	styleInfo = [(style, kStyleToSuffix[style]) for style in styles]
	# process each item
	for i, item in enumerate(items):
		sdef = aetes = None
		objcPrefix, name, path = item['objcPrefix'], item['name'], item['path']
		if path == NSBundle.mainBundle().bundlePath():
			continue
		progress.nextitem(name, path)
		try:
			isOSAX = path.lower().endswith('.osax')
			if isOSAX:
				try:
					sdef = ae.copyscriptingdefinition(path)
				except ae.MacOSError, e:
					if e.args[0] == -10827:
						progress.didfail(u"No terminology found.")
						continue
					else:
						raise
			else:
				Application
				aetes = aetesforapp(Application(path))
			if not bool(sdef or 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 and not isOSAX:
					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.renderaetes(aetes, f, makeidentifier.getconverter(style))
					except:
						f.close()
						raise
					f.close()
				if singleHTML or frameHTML:
					if isOSAX:
						terms = sdefparser.parsexml(sdef, path, style)
					else:
						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, info)
			if objcGlue and not isOSAX:
				outputPath = _makeDestinationFolder(outFolder, 
						exportToSubfolders and 'objc-appscript' or '', 
						'%s%sGlue' % (exportToSubfolders and 'glues/' or '', objcPrefix), '')
				objcappscript.makeappglue(path, objcPrefix, outputPath, aetes)
				progress.nextoutput(u'%s' % outputPath)
Esempio n. 3
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())
Esempio n. 4
0
def export(items,
           styles,
           plainText,
           singleHTML,
           frameHTML,
           objcGlue,
           options,
           outFolder,
           exportToSubfolders,
           progress,
           info={}):
    styleInfo = [(style, kStyleToSuffix[style]) for style in styles]
    # process each item
    for i, item in enumerate(items):
        sdef = aetes = None
        objcPrefix, name, path = item['objcPrefix'], item['name'], item['path']
        if path == NSBundle.mainBundle().bundlePath():
            continue
        progress.nextitem(name, path)
        try:
            isOSAX = path.lower().endswith('.osax')
            if isOSAX:
                try:
                    sdef = ae.copyscriptingdefinition(path)
                except ae.MacOSError, e:
                    if e.args[0] == -10827:
                        progress.didfail(u"No terminology found.")
                        continue
                    else:
                        raise
            else:
                Application
                aetes = aetesforapp(Application(path))
            if not bool(sdef or 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 and not isOSAX:
                    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.renderaetes(
                            aetes, f, makeidentifier.getconverter(style))
                    except:
                        f.close()
                        raise
                    f.close()
                if singleHTML or frameHTML:
                    if isOSAX:
                        terms = sdefparser.parsexml(sdef, path, style)
                    else:
                        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, info)
            if objcGlue and not isOSAX:
                outputPath = _makeDestinationFolder(
                    outFolder, exportToSubfolders and 'objc-appscript' or '',
                    '%s%sGlue' %
                    (exportToSubfolders and 'glues/' or '', objcPrefix), '')
                objcappscript.makeappglue(path, objcPrefix, outputPath, aetes)
                progress.nextoutput(u'%s' % outputPath)