Skip to content

Commit b439fc0

Browse files
Zeyue LIANGZeyue LIANG
authored andcommitted
support to check c files
1 parent 55b41a3 commit b439fc0

6 files changed

Lines changed: 133 additions & 15 deletions

File tree

20 KB
Binary file not shown.

‎zeyue/0007/.ropeproject/config.py‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# The default ``config.py``
2+
3+
4+
def set_prefs(prefs):
5+
"""This function is called before opening the project"""
6+
7+
# Specify which files and folders to ignore in the project.
8+
# Changes to ignored resources are not added to the history and
9+
# VCSs. Also they are not returned in `Project.get_files()`.
10+
# Note that ``?`` and ``*`` match all characters but slashes.
11+
# '*.pyc': matches 'test.pyc' and 'pkg/test.pyc'
12+
# 'mod*.pyc': matches 'test/mod1.pyc' but not 'mod/1.pyc'
13+
# '.svn': matches 'pkg/.svn' and all of its children
14+
# 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o'
15+
# 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o'
16+
prefs['ignored_resources'] = [
17+
'*.pyc', '*~', '.ropeproject', '.hg', '.svn', '_svn', '.git',
18+
'__pycache__', '.tox', '.env', 'node_modules', 'bower_components']
19+
20+
# Specifies which files should be considered python files. It is
21+
# useful when you have scripts inside your project. Only files
22+
# ending with ``.py`` are considered to be python files by
23+
# default.
24+
#prefs['python_files'] = ['*.py']
25+
26+
# Custom source folders: By default rope searches the project
27+
# for finding source folders (folders that should be searched
28+
# for finding modules). You can add paths to that list. Note
29+
# that rope guesses project source folders correctly most of the
30+
# time; use this if you have any problems.
31+
# The folders should be relative to project root and use '/' for
32+
# separating folders regardless of the platform rope is running on.
33+
# 'src/my_source_folder' for instance.
34+
#prefs.add('source_folders', 'src')
35+
36+
# You can extend python path for looking up modules
37+
#prefs.add('python_path', '~/python/')
38+
39+
# Should rope save object information or not.
40+
prefs['save_objectdb'] = True
41+
prefs['compress_objectdb'] = False
42+
43+
# If `True`, rope analyzes each module when it is being saved.
44+
prefs['automatic_soa'] = True
45+
# The depth of calls to follow in static object analysis
46+
prefs['soa_followed_calls'] = 0
47+
48+
# If `False` when running modules or unit tests "dynamic object
49+
# analysis" is turned off. This makes them much faster.
50+
prefs['perform_doa'] = True
51+
52+
# Rope can check the validity of its object DB when running.
53+
prefs['validate_objectdb'] = True
54+
55+
# How many undos to hold?
56+
prefs['max_history_items'] = 32
57+
58+
# Shows whether to save history across sessions.
59+
prefs['save_history'] = True
60+
prefs['compress_history'] = False
61+
62+
# Set the number spaces used for indenting. According to
63+
# :PEP:`8`, it is best to use 4 spaces. Since most of rope's
64+
# unit-tests use 4 spaces it is more reliable, too.
65+
prefs['indent_size'] = 4
66+
67+
# Builtin and c-extension modules that are allowed to be imported
68+
# and inspected by rope.
69+
prefs['extension_modules'] = []
70+
71+
# Add all standard c-extensions to extension_modules list.
72+
prefs['import_dynload_stdmods'] = True
73+
74+
# If `True` modules with syntax errors are considered to be empty.
75+
# The default value is `False`; When `False` syntax errors raise
76+
# `rope.base.exceptions.ModuleSyntaxError` exception.
77+
prefs['ignore_syntax_errors'] = False
78+
79+
# If `True`, rope ignores unresolvable imports. Otherwise, they
80+
# appear in the importing namespace.
81+
prefs['ignore_bad_imports'] = False
82+
83+
84+
def project_opened(project):
85+
"""This function is called after opening the project"""
86+
# Do whatever you like here!
336 Bytes
Binary file not shown.

‎zeyue/0007/.ropeproject/history‎

14 Bytes
Binary file not shown.

‎zeyue/0007/.ropeproject/objectdb‎

6 Bytes
Binary file not shown.

‎zeyue/0007/ComputeCodeLines.py‎

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,39 @@
33
"""
44
File: ComputeCodeLines.py
55
Author: Zeyue Liang
6+
Date: September 2, 2015
67
Email: zeyue.liang@gmail.com
78
Github: https://github.com/zeyue
89
Description:
910
A program that can compute code line numbers in a directory.
11+
Usage: change the variable "directory" in the main funtion and launch
12+
the program then.
13+
This program has been tested using some files in C and in Python,
14+
maybe support java as well.
1015
"""
1116

1217
import os
1318

14-
19+
"""
20+
Global variables
21+
"""
1522
file_suffix = "not defined"
1623
inline_comment_syntax = "not defined"
1724
start_comment_syntax = "not defined"
1825
end_comment_syntax = "not defined"
1926
multilineCommentStartFlag = 0
2027
result = {"Code files": 0,
21-
"Total lines": 0,
28+
"No blank lines": 0,
2229
"Code lines": 0,
2330
"Comment lines": 0,
2431
"Blank lines": 0}
2532

2633

34+
"""
35+
Funcitions
36+
"""
37+
38+
2739
def getFilesList(directory):
2840
"""Get files's list in a directory
2941
@@ -97,15 +109,22 @@ def isMultilineComment(string_line):
97109
multilineCommentStartFlag == 0):
98110
multilineCommentStartFlag = 1
99111
# print("one")
112+
if(len(string_line) > commentLen and
113+
string_line[-commentLen:] == end_comment_syntax):
114+
multilineCommentStartFlag = 0
100115
return True
101116
elif(string_line[0:commentLen] != start_comment_syntax and
102117
multilineCommentStartFlag == 1):
103118
# print("two")
119+
if(len(string_line) > commentLen and
120+
string_line[-commentLen:] == end_comment_syntax):
121+
multilineCommentStartFlag = 0
104122
return True
105-
elif(string_line[0:commentLen] == end_comment_syntax and
123+
elif(string_line[-commentLen:] == end_comment_syntax and
106124
multilineCommentStartFlag == 1):
107125
multilineCommentStartFlag = 0
108126
# print("three")
127+
# print(string_line[-commentLen:])
109128
return True
110129
else:
111130
return False
@@ -120,6 +139,10 @@ def countOneFile(full_file_path):
120139
"""
121140
global inline_comment_syntax, start_comment_syntax, end_comment_syntax
122141
global multilineCommentStartFlag
142+
local_result = {"No blank lines": 0,
143+
"Comment lines": 0,
144+
"Code lines": 0,
145+
"Blank lines": 0}
123146
file_suffix = getSuffix(full_file_path)
124147
if(identifyFileType(file_suffix) != "not defined"):
125148
result["Code files"] += 1
@@ -130,17 +153,23 @@ def countOneFile(full_file_path):
130153
for line in lines:
131154
line = line.strip()
132155
if line.strip():
133-
result["Total lines"] += 1
156+
local_result["No blank lines"] += 1
134157
if isInlineComment(line):
135-
result["Comment lines"] += 1
158+
local_result["Comment lines"] += 1
136159
elif isMultilineComment(line):
137-
result["Comment lines"] += 1
160+
local_result["Comment lines"] += 1
138161
else:
139162
# print("Oops...")
140-
result["Code lines"] += 1
163+
local_result["Code lines"] += 1
141164
else:
142-
result["Blank lines"] += 1
143-
print(str(result))
165+
local_result["Blank lines"] += 1
166+
print(full_file_path)
167+
for key in local_result:
168+
print(str(key) + ": " + str(local_result[key]))
169+
result["No blank lines"] += local_result["No blank lines"]
170+
result["Comment lines"] += local_result["Comment lines"]
171+
result["Code lines"] += local_result["Code lines"]
172+
result["Blank lines"] += local_result["Blank lines"]
144173

145174

146175
def countInDirectory(directory):
@@ -159,14 +188,17 @@ def main():
159188
"""main function.
160189
161190
"""
162-
print("Please input a full directory: ")
163-
# directory = input()
164-
directory = "d:\PythonProjects\python\zeyue"
191+
# directory = "d:\PythonProjects\python\zeyue"
192+
directory = "d:/NOTBACKEDUP/python/zeyue"
165193
countInDirectory(directory)
194+
195+
print()
196+
print("Final result in the directory")
197+
print(directory)
166198
for key in result:
167199
print(str(key) + ": " + str(result[key]))
168200

169-
201+
"""
202+
Launch
203+
"""
170204
main()
171-
# if(isMultilineComment("\"\"\"dfadf")):
172-
# print("yes")

0 commit comments

Comments
 (0)