Created
October 7, 2010 17:39
-
-
Save marshall/615508 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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