2010-07-09 46 views
9

我想知道是否有人使用Eclipse Metrics插件與不在Java中的項目(特別是我試圖爲幾個PyDev項目生成代碼指標)有任何運氣。我已經通讀了Metrics項目的演練,但它表示在訪問我的項目的Properties之前我應該​​在Java Perspective中,並且我應該找到Metrics部分。無論我打開哪個視角,我都無法得到我的PyDev項目。任何建議或建議都會很棒。Eclipse中的代碼行PyDev Projects

回答

16

我不知道它是可行的讓插件與PyDev的項目工作,但如果它只是lines-of-code度量你之後,你可以運行這個片段在項目的根目錄:

# prints recursive count of lines of python source code from current directory 
# includes an ignore_list. also prints total sloc 

import os 
cur_path = os.getcwd() 
ignore_set = set(["__init__.py", "count_sourcelines.py"]) 

loclist = [] 

for pydir, _, pyfiles in os.walk(cur_path): 
    for pyfile in pyfiles: 
     if pyfile.endswith(".py") and pyfile not in ignore_set: 
      totalpath = os.path.join(pydir, pyfile) 
      loclist.append((len(open(totalpath, "r").read().splitlines()), 
           totalpath.split(cur_path)[1])) 

for linenumbercount, filename in loclist: 
    print "%05d lines in %s" % (linenumbercount, filename) 

print "\nTotal: %s lines (%s)" %(sum([x[0] for x in loclist]), cur_path) 
+0

那做了什麼,我需要它。謝謝! – 2010-07-09 19:32:12

2

如果你在Linux ...

你看看cloc

它產生相當完整的輸出,並接受幾個選項:

[email protected]:~/Documents/Projects/myProject$ cloc . 
    1840 text files. 
    1566 unique files.           
    9362 files ignored. 

http://cloc.sourceforge.net v 1.53 T=3.0 s (454.3 files/s, 81397.0 lines/s) 
-------------------------------------------------------------------------------- 
Language      files   blank  comment   code 
-------------------------------------------------------------------------------- 
Javascript      709   19190   17283   93862 
Python       333   6278   3399   38398 
C        86   3244   2303   17755 
CSS        122   1786   1592   16856 
HTML        55   784    51   8072 
Bourne Shell      14   651   280   6641 
C/C++ Header      6   301   293   1259 
XML        9    5    0   1153 
PHP        2    88   211   585 
SQL        19   200   127   576 
Bourne Again Shell    2    57    15   494 
make        5    41    19   187 
DOS Batch       1    21    1   133 
-------------------------------------------------------------------------------- 
SUM:       1363   32646   25574   185971 
-------------------------------------------------------------------------------- 

它是在Ubuntu軟件倉庫,以及。

0

在Unix上你可以運行在終端如下:

find . -name '*.py' | xargs cat | egrep "[a-zA-Z0-9_{}]" | wc -l 

如果你想不算評論,你需要一個更好的正則表達式...