Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
def doc(apppath, outdir, style='py-appscript', options=[]):
    """Render XHTML files listing a scriptable application/scripting addition's classes and commands.
		apppath : str -- name or path to application/path to scripting addition
		outdir : str -- the directory to write the dictionary to (will be created if it doesn't already exist)
		style : str -- keyword formatting style ('py-appscript', 'rb-appscript' or 'applescript')
		options : list of str -- formatting options (zero or more of: 'collapse', 'showall')
		Result : bool -- False if no terminology was found and no file was written; else True
	"""
    terms = aeteparser.parseapp(findapp.byname(apppath), style)
    return renderdictionary(terms, outdir, style, options)
Ejemplo n.º 4
0
def doc(apppath, outdir, style='py-appscript', options=[]):
	"""Render XHTML files listing a scriptable application/scripting addition's classes and commands.
		apppath : str -- name or path to application/path to scripting addition
		outdir : str -- the directory to write the dictionary to (will be created if it doesn't already exist)
		style : str -- keyword formatting style ('py-appscript', 'rb-appscript' or 'applescript')
		options : list of str -- formatting options (zero or more of: 'collapse', 'showall')
		Result : bool -- False if no terminology was found and no file was written; else True
	"""
	terms = aeteparser.parseapp(findapp.byname(apppath), style)
	return renderdictionary(terms, outdir, style, options)
Ejemplo n.º 5
0
	def test_find(self):
		for val, res in [
			['/Applications/iCal.app', '/Applications/iCal.app'],
			['ical.app', '/Applications/iCal.app'],
			['ICAL.APP', '/Applications/iCal.app'],
			['ICAL', '/Applications/iCal.app'],
		]:
			self.assertEqual(res, findapp.byname(val))
		self.assertEqual('/Applications/TextEdit.app', findapp.bycreator(b'ttxt'))
		self.assertEqual('/System/Library/CoreServices/Finder.app', findapp.byid('com.apple.finder'))
		self.assertRaises(findapp.ApplicationNotFoundError, findapp.byname, 'NON-EXISTENT-APP')
Ejemplo n.º 6
0
 def test_find(self):
     for val, res in [
         ["/Applications/iCal.app", "/Applications/iCal.app"],
         ["ical.app", "/Applications/iCal.app"],
         ["ICAL.APP", "/Applications/iCal.app"],
         ["ICAL", "/Applications/iCal.app"],
     ]:
         self.assertEqual(res, findapp.byname(val))
     self.assertEqual("/Applications/TextEdit.app", findapp.bycreator("ttxt"))
     self.assertEqual("/System/Library/CoreServices/Finder.app", findapp.byid("com.apple.finder"))
     self.assertRaises(findapp.ApplicationNotFoundError, findapp.byname, "NON-EXISTENT-APP")
Ejemplo n.º 7
0
def doc(apppath, outfile, style='py-appscript', options=[], template=None):
	"""Render an XHTML file listing a scriptable application/scripting addition's classes and commands.
		apppath : str -- name or path to application/path to scripting addition
		outfile : str -- the file to write
		style : str -- keyword formatting style ('py-appscript', 'rb-appscript' or 'applescript')
		options : list of str -- formatting options (zero or more of: 'collapse', 'showall')
		template : str -- custom HTML template to use
		Result : bool -- False if no terminology was found and no file was written; else True
	"""
	terms = aeteparser.parseapp(findapp.byname(apppath), style)
	result = renderdictionary(terms, style, options, template)
	if result:
		f = open(outfile, 'w')
		f.write(str(result))
		f.close()
	return bool(result)
Ejemplo n.º 8
0
def doc(apppath, outfile, style='py-appscript', options=[], template=None):
    """Render an XHTML file listing a scriptable application/scripting addition's classes and commands.
		apppath : str -- name or path to application/path to scripting addition
		outfile : str -- the file to write
		style : str -- keyword formatting style ('py-appscript', 'rb-appscript' or 'applescript')
		options : list of str -- formatting options (zero or more of: 'collapse', 'showall')
		template : str -- custom HTML template to use
		Result : bool -- False if no terminology was found and no file was written; else True
	"""
    terms = aeteparser.parseapp(findapp.byname(apppath), style)
    result = renderdictionary(terms, style, options, template)
    if result:
        f = open(outfile, 'w')
        f.write(str(result))
        f.close()
    return bool(result)
Ejemplo n.º 9
0
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()
Ejemplo n.º 10
0
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()
Ejemplo n.º 11
0
def doc(path, file, style='appscript', options=[], template=None):
	"""Render an XHTML file listing a scriptable application's classes and commands.
		path : str -- name or path to application
		file : str -- HTML file's destination.
		style : str -- keyword formatting style ('appscript' or 'applescript')
		options : list of str -- formatting options ([] or ['collapse'])
		template : str -- custom HTML template to use
	"""
	if path.endswith('.sdef'):
		terms = sdefparser.parsefile(path, style)
	elif path.endswith('.aete'):
		terms = aeteparser.parsefile(path, style)
	else:
		terms = aeteparser.parseapp(findapp.byname(path), style)
	if terms.suites():
		if template:
			tpl = Template(renderTemplate, template)
		else:
			tpl = _template
		result = encodeNonASCII(tpl.render(terms, typerenderers[style](), options))
		f = open(expanduser(file), 'w')
		f.write(str(result))
		f.close()
Ejemplo n.º 12
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()
Ejemplo n.º 13
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()
Ejemplo n.º 14
0
def doc(path, file, style='appscript', options=[], template=None):
    """Render an XHTML file listing a scriptable application's classes and commands.
		path : str -- name or path to application
		file : str -- HTML file's destination.
		style : str -- keyword formatting style ('appscript' or 'applescript')
		options : list of str -- formatting options ([] or ['collapse'])
		template : str -- custom HTML template to use
	"""
    if path.endswith('.sdef'):
        terms = sdefparser.parsefile(path, style)
    elif path.endswith('.aete'):
        terms = aeteparser.parsefile(path, style)
    else:
        terms = aeteparser.parseapp(findapp.byname(path), style)
    if terms.suites():
        if template:
            tpl = Template(renderTemplate, template)
        else:
            tpl = _template
        result = encodeNonASCII(
            tpl.render(terms, typerenderers[style](), options))
        f = open(expanduser(file), 'w')
        f.write(str(result))
        f.close()