File: anjuta-python-autocomplete.py

package info (click to toggle)
anjuta 2%3A2.32.0.0-5
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 61,524 kB
  • ctags: 29,402
  • sloc: ansic: 207,516; xml: 31,169; cpp: 11,403; sh: 10,749; perl: 7,107; makefile: 3,373; yacc: 1,018; lex: 126; sql: 97; python: 91; java: 6
file content (71 lines) | stat: -rwxr-xr-x 1,767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import getopt
import sys
from rope.base.project import Project 
from rope.contrib import codeassist
from rope.contrib import autoimport
import os

def pathsplit(p, rest=[]):
	(h,t) = os.path.split(p)
	if len(h) < 1: return [t]+rest
	if len(t) < 1: return [h]+rest
	return pathsplit(h,[t]+rest)

def commonpath(l1, l2, common=[]):
	if len(l1) < 1: return (common, l1, l2)
	if len(l2) < 1: return (common, l1, l2)
	if l1[0] != l2[0]: return (common, l1, l2)
	return commonpath(l1[1:], l2[1:], common+[l1[0]])

def relpath(p1, p2):
	(common,l1,l2) = commonpath(pathsplit(p1), pathsplit(p2))
	p = []
	if len(l1) > 0:
	    p = [ '../' * len(l1) ]
	p = p + l2
	return os.path.join( *p )


options, remainder = getopt.getopt(sys.argv[1:], 'o:p:s:r:f:')

for opt, arg in options:
    if opt in ('-o', '--option'):
        option_arg = arg
    elif opt in ('-p', '--project'):
        project_arg = arg
    elif opt == '-s':
        source_code_arg = arg
    elif opt == '-r':
        res_arg = arg
    elif opt == '-f':
        offset_arg = arg

option = option_arg;
projectpath = project_arg
if projectpath.startswith("file://"):
	projectpath = projectpath.replace("file://", "")

proj = Project(projectpath)
proj.pycore._init_python_files()

input = open(source_code_arg, 'r')
source_code = input.read()
respath = relpath(projectpath, res_arg)
res = proj.get_resource(respath)

position = int(offset_arg)

if option == "autocomplete":
	proposals = codeassist.code_assist(proj, source_code, position, resource=res, maxfixes=10)
	proposals = codeassist.sorted_proposals(proposals)

	for proposal in proposals:
		print proposal

elif option == "calltip":
	proposals = codeassist.get_doc(proj, source_code, position, resource=res, maxfixes=10)
	print proposals

proj.close()