コード例 #1
0
ファイル: ccl_op.py プロジェクト: hujun-GitHub/CountCodeLines
def modify_after_pay(line):
    print('ccl_op.modify_after_pay:' + line)
    arr_line = line.split("_")
    filename = arr_line[0] + '.ccl'
    year = arr_line[1]
    month = arr_line[2]
    day = arr_line[3]
    file_type = arr_line[5]
    print('读取ccl文件:' + filename)
    file = codecs.open("../" + filename, 'r', encoding=file_op.get_encoding("../" + filename))
    file.seek(0)
    file_lines = file.readlines()

    print('根据当前点击这行的年月日、文件类型去确定修改文件的哪一行:')
    for index in range(len(file_lines)):
        print('第{}行:{}'.format(index, str(file_lines[index])))
        arr = file_lines[index].split(',')
        if arr[0] == year and arr[1] == month and arr[2] == day and arr[7].find(file_type) != -1:
            print('修改之前:' + str(arr))
            file_lines[index] = '{},{},{},{},{},{},{},{}'.format(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], 1, arr[7])
            print('修改之后:' + str(file_lines[index]))
    print('回写文件')
    file = open("../" + filename, 'w', encoding='utf8')
    file.writelines(file_lines)
    file.flush()
    # 不关闭,就不能读
    file.close()
    print('ccl_op.modify_after_pay over')
コード例 #2
0
ファイル: ccl_op.py プロジェクト: hujun-GitHub/CountCodeLines
def count_ccl(ccl_file_curr_user, git_base_path, suffix):
    file_exist = os.path.exists(ccl_file_curr_user)
    if not file_exist:
        print('程序员ccl文件不存在,创建文件。' + ccl_file_curr_user)
        file = open(ccl_file_curr_user, 'w', encoding='utf8')
        file.close()
    ccl_code_total = 0
    ccl_newline_total = 0
    ccl_comment_total = 0
    for filename in os.listdir(git_base_path):
        filename = git_base_path + '/' + filename
        if os.path.isfile(filename) and filename.endswith('.ccl'):
            # print('处理文件:' + filename)
            f = codecs.open(filename, 'r', encoding=file_op.get_encoding(filename))
            f.seek(0)
            file_lines = f.readlines()
            for line in file_lines:
                if len(line.strip()) == 0:
                    continue
                col = line.split(',')
                if col[7].find(suffix) >= 0:
                    ccl_newline_total += int(col[3])
                    ccl_comment_total += int(col[4])
                    ccl_code_total += int(col[5])
    return ccl_code_total, ccl_comment_total, ccl_newline_total
コード例 #3
0
ファイル: ccl_op.py プロジェクト: hujun-GitHub/CountCodeLines
def write_user_ccl(ccl_file_curr_user, push_code, push_newline, push_comment, suffix):
    file = codecs.open(ccl_file_curr_user, 'r', encoding=file_op.get_encoding(ccl_file_curr_user))
    file.seek(0)
    file_lines = file.readlines()
    last_year = 0
    last_month = 0
    last_day = 0
    old_push_code = 0
    old_push_newline = 0
    old_push_comment = 0
    pay_status = 0
    file_type = ''
    if len(file_lines) > 0:
        print('file_lines='+str(file_lines))
        index_last_line = file_op.find_last_line_index(file_lines, suffix)
        print("index_last_line=" + str(index_last_line))
        if index_last_line is not None:
            col = file_lines[index_last_line].split(',')
            last_year = col[0]
            last_month = col[1]
            last_day = col[2]
            old_push_comment = int(col[4])
            old_push_newline = int(col[3])
            old_push_code = int(col[5])
            pay_status = col[6]
            file_type = col[7]
    curr_year = datetime.datetime.now().year
    curr_month = datetime.datetime.now().month
    curr_day = datetime.datetime.now().day
    print('suffix = {} file_type={}'.format(suffix, file_type))
    if curr_year == int(last_year) and curr_month == int(last_month) and curr_day == int(last_day) and file_type.find(suffix) >= 0:
        file_lines[index_last_line] = '{},{},{},{},{},{},{},{}\r'.format(
            curr_year, curr_month, curr_day, old_push_newline + push_newline, old_push_comment + push_comment, old_push_code + push_code, pay_status, suffix)
    else:
        add_line = '{},{},{},{},{},{},{},{}\r'.format(curr_year, curr_month, curr_day, push_newline, push_comment, push_code, 0, suffix)
        # \n系统会转成\r\n,下一次又转一次,所有换行会越来越多,用\r就不会转了。
        file_lines.append(add_line)
    print("ccl文件修改后为:" + str(file_lines))
    file = open(ccl_file_curr_user, 'w', encoding='utf8')
    file.writelines(file_lines)
    file.flush()
    # 不关闭,就不能读
    file.close()
コード例 #4
0
    def make_main_ui(self):
        # 遍历以ccl文件(以后这个是要改的),展示所有程序员push代码的记录。
        upper_folder = os.path.abspath(os.path.join(os.getcwd(), ".."))
        index_line = 0
        cost_money = 0
        left_money = 0
        print(upper_folder)
        wx.StaticText(
            self.pnl,
            label=
            "成员\t\t\t\t年\t\t月\t\t日\t\t空白行\t\t注释行\t\t代码行\t\t代码总行数\t\t代码类型\t\t是否付款",
            pos=(30, 80),
            size=(1300, 30))
        dic_code_total = {}
        for filename in os.listdir(upper_folder):
            if os.path.isfile(upper_folder + '/' +
                              filename) and filename.endswith('.ccl'):
                f = codecs.open(upper_folder + '/' + filename,
                                'r',
                                encoding=file_op.get_encoding(upper_folder +
                                                              '/' + filename))
                f.seek(0)
                fl = f.readlines()
                # 遍历文件里每一条记录。
                for index in range(len(fl)):
                    if len(fl[index].strip()) == 0:
                        continue
                    cost_money += self.create_ui_line(filename, fl[index],
                                                      index_line,
                                                      dic_code_total)
                    index_line += 1
                left_money = 10000 - cost_money

        st = wx.StaticText(self.pnl,
                           label="奖池剩余奖金:" + str(left_money),
                           pos=(25, 25))

        font = st.GetFont()
        font.PointSize += 10
        st.SetFont(font)
コード例 #5
0
    def on_pay(self, event):

        if not self.validate_pay():

            return

        line = event.EventObject.GetName()
        arr_line = line.split("\t")

        filename = 'data_' + arr_line[0] + '.txt'
        year = arr_line[1]
        month = arr_line[2]
        day = arr_line[3]

        file = codecs.open("../" + filename,
                           'r',
                           encoding=file_op.get_encoding("../" + filename))
        file.seek(0)
        file_lines = file.readlines()
        # 根据当前点击这行的年月日去确定修改文件的哪一行。

        for index in range(len(file_lines)):
            l = file_lines[index].split(',')
            if l[0] == year and l[1] == month and l[2] == day:
                file_lines[index] = '{},{},{},{},{},{},{}\n'.format(
                    l[0], l[1], l[2], l[3], l[4], l[5], 1)

        # 写入文件
        file = open("../" + filename, 'w', encoding='utf8')
        file.writelines(file_lines)
        file.flush()
        # 不关闭,就不能读
        file.close()

        wx.MessageBox("支付状态修改成功!")

        self.Destroy()
        frm = PayFrame(None, title='支付小工具')
        frm.Show()
コード例 #6
0
    if not file_exist:
        print('程序员count文件不存在,创建文件。' + file_name_curr_user)
        file = open(file_name_curr_user, 'w', encoding='utf8')
        file.close()

    print('遍历所有*.ccl文件, 计算工作者提交的代码总量。')
    code_txt_total = 0
    newline_txt_total = 0
    comment_txt_total = 0
    for filename in os.listdir(git_base_path):
        filename = git_base_path + '/' + filename
        if os.path.isfile(filename) and filename.endswith('.ccl'):
            print('处理文件:' + filename)
            f = codecs.open(filename,
                            'r',
                            encoding=file_op.get_encoding(filename))
            f.seek(0)

            file_lines = f.readlines()
            for line in file_lines:
                if len(line.strip()) == 0:
                    continue
                col = line.split(',')
                newline_txt_total += int(col[3])
                comment_txt_total += int(col[4])
                code_txt_total += int(col[5])

    print('txt贡献代码行数为:' + str(code_txt_total))
    push_code = code_total - code_txt_total
    push_newline = newline_total - newline_txt_total
    push_comment = comment_total - comment_txt_total
コード例 #7
0
                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(十六进制)的字符,
    # 所以我们就会遇到很多不可思议的问题,比如,网页第一行可能会显示一个“?”,
    # 明明正确的程序一编译就报出语法错误,等等。
    # 可以使用 Sublime Text 编辑器-文件-保存编码-utf-8

    f = codecs.open('data.txt', 'r', encoding=file_op.get_encoding('data.txt'))
    f.seek(0)
    fl = f.readlines()
    s = fl[-1]
    #print(s)

    l = s.split(',')
    lastyear = l[0]
    lastmonth = l[1]
    lastday = l[2]
    lastcodeline = l[3]

    year = datetime.datetime.now().year
    month = datetime.datetime.now().month
    day = datetime.datetime.now().day