Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Eclipse PyDev项目中的代码行_Python_Eclipse_Plugins_Metrics_Pydev - Fatal编程技术网

Python Eclipse PyDev项目中的代码行

Python Eclipse PyDev项目中的代码行,python,eclipse,plugins,metrics,pydev,Python,Eclipse,Plugins,Metrics,Pydev,我想知道是否有人有幸将插件用于非Java项目(特别是我正在尝试为几个PyDev项目生成代码度量)。我已经阅读了Metrics项目的演练,但它表明在访问项目的属性之前,我应该处于Java透视图中,并且应该找到Metrics部分。无论我打开了哪个透视图,我的PyDev项目都不会得到这些。任何建议都很好。我不知道让插件与pydev项目一起工作是否可行,但如果它只是您追求的代码行数,您可以在项目的根目录中运行此代码段: # prints recursive count of lines of pytho

我想知道是否有人有幸将插件用于非Java项目(特别是我正在尝试为几个PyDev项目生成代码度量)。我已经阅读了Metrics项目的演练,但它表明在访问项目的属性之前,我应该处于Java透视图中,并且应该找到Metrics部分。无论我打开了哪个透视图,我的PyDev项目都不会得到这些。任何建议都很好。

我不知道让插件与pydev项目一起工作是否可行,但如果它只是您追求的
代码行数,您可以在项目的根目录中运行此代码段:

# 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)
如果你在Linux中

你看了吗

它产生相当完整的输出,并接受以下几个选项:

borrajax@borrajax-linux:~/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存储库中找到。

在Unix上,您可以从终端运行以下操作:

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

如果你不想计算评论,你需要一个更好的正则表达式…

这正是我所需要的。谢谢