Skip to content

Instantly share code, notes, and snippets.

@mkorpela
Created January 20, 2012 11:57
Show Gist options
  • Save mkorpela/1647044 to your computer and use it in GitHub Desktop.
Save mkorpela/1647044 to your computer and use it in GitHub Desktop.
Finding unused Robot Framework user keywords
import sys
from robotide.controller.chiefcontroller import ChiefController
from robotide.controller.commands import NullObserver
from robotide.controller.filecontrollers import DirectoryController
from robotide.namespace import Namespace
from robotide.spec.iteminfo import LibraryKeywordInfo
from robotide.usages.commands import FindUsages
def construct_chief_controller(datapath):
namespace = Namespace()
chief = ChiefController(namespace)
chief.load_data(datapath, NullObserver())
return chief, namespace
if __name__ == '__main__':
chief, namespace = construct_chief_controller(sys.argv[1])
print 'finding unused User Keywords..'
for keyword_info in namespace.get_all_keywords([df.data for df in chief.datafiles \
if not isinstance(df, DirectoryController)]):
if not isinstance(keyword_info, LibraryKeywordInfo) and keyword_info.name:
try:
chief.execute(FindUsages(keyword_info.name, keyword_info=keyword_info)).next()
except StopIteration:
print 'Source: %s Keyword: "%s"' % (keyword_info.item.source, keyword_info.name)
print 'find end'
@didier-lhermenier
Copy link

Is this project still being followed?
I try to do the same thing but under python 3!
Is there an updated project that would do the same today?

@mkorpela
Copy link
Author

mkorpela commented Jan 6, 2022

RIDE should have this functionality for the past 8-10 years

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment