Skip to content

Instantly share code, notes, and snippets.

@marshall
Created October 7, 2010 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshall/615508 to your computer and use it in GitHub Desktop.
Save marshall/615508 to your computer and use it in GitHub Desktop.
marshall@snake:~/Code/test/test_python
$ python test.py
modules = set(['Android', 'Android.Calendar', 'UI', 'UI.Android']), should be: Android, Android.Calendar, UI, UI.Android
methods = set(['UI.Android.createActivity', 'UI.createLabel']), should be: UI.createLabel, UI.Android.createActivity
import os, sys, re
def extract_from_namespace(name, line):
modules = set()
methods = set()
symbols = re.findall(r'%s\.(\w+)' % name, line)
if len(symbols) == 0:
return modules, methods
for sym in symbols:
sub_symbols = extract_from_namespace("%s.%s" % (name, sym), line)
for module in sub_symbols[0]:
modules.add("%s.%s" % (sym, module))
for method_name in sub_symbols[1]:
method_name = "%s.%s" % (sym, method_name)
methods.add(method_name)
# skip Titanium.version, Titanium.userAgent and Titanium.name since these
# properties are not modules
if sym in ('version','userAgent','name','_JSON','include','fireEvent','addEventListener','removeEven
tListener','buildhash','builddate'):
continue
if sym[0].isupper():
modules.add(sym)
else:
methods.add(sym)
return modules, methods
modules, methods = extract_from_namespace("Ti", "Ti.Android; Ti.Android.Calendar; Ti.UI.Android; Ti.UI.creat
eLabel; Ti.UI.Android.createActivity");
print 'modules = ' + str(modules) + ', should be: Android, Android.Calendar, UI, UI.Android'
print 'methods = ' + str(methods) + ', should be: UI.createLabel, UI.Android.createActivity'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment