Esempio n. 1
0
 def validate_pay(self):
     count_code_line_git = file_op.count_code('..')
     count_code_line_txt = file_op.count_code_line_txt('..')
     if count_code_line_txt != count_code_line_git:
         wx.MessageBox("txt代码行数{}和git提交的代码行数{}不一致!无法付款。".format(
             count_code_line_txt, count_code_line_git))
         return False
     return True
def main_process(suffix):
    char_comment = config_ini_op.get_config_value(
        os.path.join(os.getcwd(), 'config.ini'), suffix + '_comment')
    hostname = file_op.get_host_name()
    git_base_path = git_op.get_git_base_path()
    print('===> 计算git根目录下所有{}文件的代码行数'.format(suffix))
    code_total = file_op.count_code(git_base_path, suffix)
    print('代码行数为:' + str(code_total))
    comment_total = file_op.count_comment(git_base_path, suffix, char_comment)
    print('注释行数为:' + str(comment_total))
    newline_total = file_op.count_newline(git_base_path, suffix)
    print('空白行数为:' + str(newline_total))
    if code_total == 0:
        return
    # 在windows平台下,使用系统的记事本以UTF-8编码格式存储了一个文本文件,
    # 但是由于Microsoft开发记事本的团队使用了一个非常怪异的行为来保存UTF-8编码的文件,
    # 它们自作聪明地在每个文件开头添加了0xefbbbf(十六进制)的字符,
    # 所以我们就会遇到很多不可思议的问题,比如,网页第一行可能会显示一个“?”,
    # 明明正确的程序一编译就报出语法错误,等等。
    # 可以使用 Sublime Text 编辑器-文件-保存编码-utf-8
    print('===> 计算ccl文件代码行数')
    ccl_file_curr_user = git_base_path + '/' + hostname + '.ccl'
    ccl_code_total, ccl_comment_total, ccl_newline_total = ccl_op.count_ccl(
        ccl_file_curr_user, git_base_path, suffix)
    print('ccl代码行数为:' + str(ccl_code_total))
    print('ccl注释行数为:' + str(ccl_comment_total))
    print('ccl空白行数为:' + str(ccl_newline_total))
    print('===> 计算程序员提交代码行数(total - ccl)')
    push_code = code_total - ccl_code_total
    print("代码行数:" + str(push_code))
    push_newline = newline_total - ccl_newline_total
    print("空白行数:" + str(push_newline))
    push_comment = comment_total - ccl_comment_total
    print("注释行数:" + str(push_comment))

    print("===> 将程序员提交信息写入ccl文件")
    ccl_op.write_user_ccl(ccl_file_curr_user, push_code, push_newline,
                          push_comment, suffix)
    print("ccl文件信息写入完毕。")
    print("===> 自动git add程序员的ccl文件")
    repo = git.Repo(git_base_path)
    repo.git.add(ccl_file_curr_user)
    print(ccl_file_curr_user + "文件自动add完毕。")

    print("===>将代码行数统计信息写入数据库")
    ccl_op.write_to_db(hostname, suffix, push_code, push_newline, push_comment)
    print("代码行数入库完毕。")
Esempio n. 3
0
system_type = sys.platform
git_base_path = ''
if system_type.startswith('win'):
    git_base_path = os.path.abspath(os.path.join(os.getcwd(), "../../.."))
elif system_type == 'darwin':
    git_base_path = os.path.abspath(os.path.join(sys.MEIPASS, "../../.."))
else:
    print('可能是ubuntu系统,代码没有完成。')
print("git_base_path:" + git_base_path)

while True:  # 使用while True: 循环和 time 库实现简单的程序后台服务
    code_total = 0
    comment_total = 0
    newline_total = 0
    if len(sys.argv) == 1:
        code_total = file_op.count_code(git_base_path)
        comment_total = file_op.count_comment(git_base_path)
        newline_total = file_op.count_newline(git_base_path)
    else:
        for path in sys.argv[1:]:
            if os.path.exists(path):
                code_total = code_total + file_op.count_code(path)
                comment_total += file_op.count_comment(path)
                newline_total += file_op.count_newline(path)
                #all_total += file_op.count_all(path)
            elif path == '-h' or path == '/h':
                print('Usage: count_code_lines [directory name, [...]]')
                exit(1)
            else:
                print('The Directory ' + path + ' do not exist.')
                exit(2)
import file_op


#
print('========+1===')


################### 主程序开始 ###########################
step = 0
sum = 0

while True: # 使用while True: 循环和 time 库实现简单的程序后台服务
    count = 0
    if len(sys.argv) == 1:
        path = os.getcwd()
        count = file_op.count_code(path)
    else:
        for path in sys.argv[1:]:
            if os.path.exists(path):
                count = count + file_op.count_code(path)
            elif path == '-h' or path == '/h':
                print('Usage: count_code_lines [directory name, [...]]')
                exit(1)
            else:
                print('The Directory ' + path +' do not exist.')
                exit(2)

    # 在windows平台下,使用系统的记事本以UTF-8编码格式存储了一个文本文件,
    # 但是由于Microsoft开发记事本的团队使用了一个非常怪异的行为来保存UTF-8编码的文件,
    # 它们自作聪明地在每个文件开头添加了0xefbbbf(十六进制)的字符,
    # 所以我们就会遇到很多不可思议的问题,比如,网页第一行可能会显示一个“?”,