示例#1
0
#!/usr/bin/env python

import os, re, sys

shared_support_path =  os.path.realpath(   os.path.join(  os.path.dirname( os.path.realpath(__file__) ), "..", "..", "..", "SharedSupport"   )   )
sys.path.append( shared_support_path )

import list_statements_matching

routing_line = re.compile(r"(\W+?)(get|post|put|patch|delete)\W(.+)")

for match_object, line, line_number in list_statements_matching.list_statements_matching( os.environ["BB_DOC_PATH"], routing_line ):
	print line,
	print "    " + match_object.group(1) + os.environ["BB_DOC_PATH"] + ":" + str(line_number)
	print
This would make navigating long files (like you have in Ruby on Rails models) much easier, as these
(at least on some of my current projects for work) contain multiple things - permissioning, workflow,
helper methods, etc... but I, as a user, know that I want to look for only things in the permissioning DSL.

This script outputs two lines for each found line. The first line contains your DSL expression,
and the second line contains the absolute path, including line number, to jump to the location in the file.

Select the path in second line and Use File -> Open File By Name to open your file to the specific spot
(or go to that specific spot in the already opened file).

"""

import os, re, sys

shared_support_path =  os.path.realpath(   os.path.join(  os.path.dirname( os.path.realpath(__file__) ), "..", "..", "..", "..", "SharedSupport"   )   )
sys.path.append( shared_support_path )

import list_statements_matching
context_line = re.compile(r"(\W+?)(context|fast_context)\W(.+)")
should_line = re.compile(r"(\W+?)(should)\W(.+)")
test_line = re.compile(r"(\W+?)(test)\W(.+)")

rspec_it_line = re.compile(r"(\W+?)(it)\W(.+)")
rspec_describe_line = re.compile(r"(\W+?)(describe)\W(.+)")

for match_object, line, line_number in list_statements_matching.list_statements_matching(os.environ["BB_DOC_PATH"], context_line, should_line, test_line, rspec_it_line, rspec_describe_line):
	print line,
	print "    " + match_object.group(1) + os.environ["BB_DOC_PATH"] + ":" + str(line_number)
	print