Exemplo n.º 1
0
def info_to_dat(xls_path, reply):
    src_xls = excel.xl_rd(xls_path)
    try:
        commit_info_li = src_xls.get_commit_info()
        if not commit_info_li:
            raise Exception
    except Exception:
        print u'不存在需提交内容,请更新"文件提交单.xls"'
        exception.unlock_dat_file(conf.reply)
        exit(1)

    #备份本次提交excel列表,加上时间戳
    now = datetime.datetime.now().strftime('%Y%m%d%H%M')
    try:
        os.rename(xls_path, conf.xls_bak_path + xls_path + '.' + now)
    except WindowsError:
        print u'备份文件提交单出错,请先关闭已打开的"文件提交单.xls"'
        exit(1)
    shutil.copy(conf.template, xls_path)

    #将excel中未提交的文件列表写进数据文件中
    try:
        if reply == '0':
            code_dat = showlist.jsonProcess(conf.code_dat)
            code_dat.add_file(commit_info_li, conf.code_dat)
        sit_dat = showlist.jsonProcess(conf.sit_dat)
        sit_dat.add_file(commit_info_li, conf.sit_dat)
    except:
        print u'写入数据列表失败'
        exception.fallback(conf.reply)
        #exception.dat_fallback()
        #exception.unlock_dat_file()
        exit(1)
Exemplo n.º 2
0
 def show_list(self, ):
     pos_li = self.file_list[-1]
     #new_pos_li = map(self.chg_pos, pos_li)
     #new_pos_li = self.chg_pos(pos_li)
     #print new_pos_li
     print u'尚未提交的内容列表(单项以"x.x"格式、空格为分隔符进行提交,全部提交时可输入"all"):'
     try:
         self.print_list(pos_li)
     except:
         exception.fallback(conf.reply)
         exit(1)
Exemplo n.º 3
0
 def show_list(self, ):
     pos_li = self.file_list[-1]
     #new_pos_li = map(self.chg_pos, pos_li)
     #new_pos_li = self.chg_pos(pos_li)
     #print new_pos_li
     print u'尚未提交的内容列表(单项以"x.x"格式、空格为分隔符进行提交,全部提交时可输入"all"):'
     try:
         self.print_list(pos_li)
     except:
         exception.fallback(conf.reply)
         exit(1)
Exemplo n.º 4
0
def get_file_text(path):
    try:
        file_obj = open(path, 'r')
        file_text = file_obj.read()
    except:
        print u'读取文件' + path + u'失败'
        exception.fallback(conf.reply)
        exit(1)
    else:
        return file_text
    finally:
        file_obj.close()
Exemplo n.º 5
0
def create_msg(commit_info_li):
    #print u'create_msg: ', commit_info_li
    msg_obj = open(conf.log_file, 'w+b')
    msg = ''
    try:
        msg = nest_li_to_str(msg, commit_info_li).encode('gb2312')
        msg_obj.write(msg)
    except:
        print u'注释文件生成失败'
        exception.fallback(conf.reply)
    finally:
        msg_obj.close()
Exemplo n.º 6
0
def get_file_text(path):
    try:
        file_obj = open(path, 'r')
        file_text = file_obj.read()
    except:
        print u'读取文件' + path + u'失败'
        exception.fallback(conf.reply)
        exit(1)
    else:
        return file_text
    finally:
        file_obj.close()
Exemplo n.º 7
0
def copy(file, src_dir, des_dir, reply):
    if reply == '1':
        src_file = src_dir + file
    elif reply == '0':
        src_file = src_dir + os.path.basename(file)
    des_file = des_dir + file
    try:
        shutil.copy(src_file, des_file)
        #print 'copy ' + src_file + ' to ' + des_file
    except:
        print 'copy ' + src_file + ' to ' + des_file + " FAILED"
        exception.fallback(reply)
        exit(1)
Exemplo n.º 8
0
def add_new_file(des_dir, new_add_info):
    new_add_list = map(lambda new_add_info: new_add_info[-1], new_add_info)
    new_add_list_str = join_file(des_dir, new_add_list)
    try:
        svn.svn_opt('add', new_add_list_str)
    except:
        print u'新增文件失败'
        svn.svn_opt('revert', new_add_list_str)
        exception.fallback(conf.reply)
        #exception.dat_fallback()
        #exception.unlock_dat_file()
        exit(1)
    else:
        print 'add OK'
Exemplo n.º 9
0
def ready_for_commit(des_dir, file_info):
    if isinstance(file_info[0], list):
        file_list = map(lambda file_info: file_info[-1], file_info)
    else:
        file_list = file_info
    #print 'file_list, ', file_list
    file_list_str = join_file(des_dir, file_list)
    #print 'file_list_str, ', file_list_str
    svn.svn_opt('update', file_list_str)
    print 'update OK'
    try:
        svn.svn_opt('lock', file_list_str)
    except svn.svnError:
        print u'lock失败,请确认是否有其他人正在操作'
        exception.fallback(conf.reply)
    else:
        print file_list_str, 'lock OK'
Exemplo n.º 10
0
def svn_opt(opt, files, *msg):
    try:
        #if opt == 'commit':
            #print svn[opt] + msg[0] + files.encode('gb2312')
            #print u'提交信息log, ', msg[0]
            #p = subprocess.Popen(svn[opt] + msg[0] + files.encode('gb2312'), stderr = subprocess.STDOUT)
            #log = os.popen(svn[opt] + msg[0] + files.encode('gb2312'))
        #else:
        p = subprocess.Popen(svn[opt] + files.encode('gb2312'), stderr = subprocess.STDOUT) 
        if p.wait() != 0:
            raise svnError
    except IndexError:
        print svn[opt] + u'缺少message信息'
        exception.fallback(conf.reply)
        #exception.dat_fallback()
        #exception.unlock_dat_file()
        exit(1)
Exemplo n.º 11
0
def commit_to_des(des_dir, file_info):
    if isinstance(file_info[0], list):
        file_list = map(lambda file_info: file_info[-1], file_info)
    else:
        file_list = file_info
    #msg = u'本次共提交%d个文件 ' % len(file_list)
    create_msg(file_info)
    file_list_str = join_file(des_dir, file_list)
    #print u'提交文件列表,', file_list_str
    try:
        #svn.svn_opt('commit', file_list_str, msg.encode('gb2312'))
        svn.svn_opt('commit', file_list_str)
    except svn.svnError:
        print u'svn commit失败'
        exception.fallback(conf.reply)
        #exception.dat_fallback()
        #exception.unlock_dat_file()
        exit(1)
Exemplo n.º 12
0
def svn_opt(opt, files, *msg):
    try:
        #if opt == 'commit':
        #print svn[opt] + msg[0] + files.encode('gb2312')
        #print u'提交信息log, ', msg[0]
        #p = subprocess.Popen(svn[opt] + msg[0] + files.encode('gb2312'), stderr = subprocess.STDOUT)
        #log = os.popen(svn[opt] + msg[0] + files.encode('gb2312'))
        #else:
        p = subprocess.Popen(svn[opt] + files.encode('gb2312'),
                             stderr=subprocess.STDOUT)
        if p.wait() != 0:
            raise svnError
    except IndexError:
        print svn[opt] + u'缺少message信息'
        exception.fallback(conf.reply)
        #exception.dat_fallback()
        #exception.unlock_dat_file()
        exit(1)
Exemplo n.º 13
0
    def add_file(self, new_file_list, data_path):
        #将列表转换为字典
        #将原始key_words转换为列表
        new_li = list(map(self.li_to_dict, new_file_list))
        #初始化所有未提交的key_word下标
        pos_li = self.rec_idx(new_li)
        #为新增文件添加时间戳
        now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        for file_info in new_li:
            file_info['author'] = conf.author
            file_info['last_update'] = now

        #删除并替换原记录坐标列表,加入新增的文件列表
        try:
            self.file_list[-1:] = new_li
            pos_li += self.pos_li
            self.file_list.append(sorted(pos_li))
        except:
            print u'列表为空'
            self.file_list = new_li
            self.file_list.append(sorted(pos_li))

        #print 'self.file_list, ', self.file_list

        #转换为json格式的数据
        #print json.dumps(self.file_list, indent = 2)
        #print json.dumps(self.file_list, indent = True)
        #写入新文件
        fp = open(data_path, 'w+b')
        try:
            json.dump(self.file_list, fp, indent = 2)
        except:
            print u'写入数据文件失败'
            exception.fallback(conf.reply)
            #exception.dat_fallback()
            #exception.unlock_dat_file()
            exit(1)
        finally:
            fp.close()
Exemplo n.º 14
0
    def add_file(self, new_file_list, data_path):
        #将列表转换为字典
        #将原始key_words转换为列表
        new_li = list(map(self.li_to_dict, new_file_list))
        #初始化所有未提交的key_word下标
        pos_li = self.rec_idx(new_li)
        #为新增文件添加时间戳
        now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        for file_info in new_li:
            file_info['author'] = conf.author
            file_info['last_update'] = now

        #删除并替换原记录坐标列表,加入新增的文件列表
        try:
            self.file_list[-1:] = new_li
            pos_li += self.pos_li
            self.file_list.append(sorted(pos_li))
        except:
            print u'列表为空'
            self.file_list = new_li
            self.file_list.append(sorted(pos_li))

        #print 'self.file_list, ', self.file_list

        #转换为json格式的数据
        #print json.dumps(self.file_list, indent = 2)
        #print json.dumps(self.file_list, indent = True)
        #写入新文件
        fp = open(data_path, 'w+b')
        try:
            json.dump(self.file_list, fp, indent=2)
        except:
            print u'写入数据文件失败'
            exception.fallback(conf.reply)
            #exception.dat_fallback()
            #exception.unlock_dat_file()
            exit(1)
        finally:
            fp.close()
Exemplo n.º 15
0
    def update_stat(self, ):
        #更新最后修改时间
        now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        pos_li = self.file_list[-1]
        des_pos_li = self.merge_pos()
        for pos in des_pos_li:
            cur_info = self.file_list[int(pos[0][0])]
            cur_info['last_update'] = now

        #删除已提交的坐标
        try:
            #print des_pos_li
            for des_pos in des_pos_li:
                for pos in des_pos:
                    pos = map(lambda x: int(x), pos)
                    pos_li.remove(pos)
        except:
            print u'删除已提交的坐标出错'
            exception.fallback(conf.reply)
            #exception.dat_fallback()
            #exception.unlock_dat_file()
            exit(1)

        #print self.file_list
        file_obj = open(self.des_path, 'w+b')
        try:
            json.dump(self.file_list, file_obj, indent=2)
        except:
            print u'更新数据文件失败'
            exception.fallback(conf.reply)
            #exception.dat_fallback()
            #exception.unlock_dat_file()
            exit(1)

        finally:
            file_obj.close()
Exemplo n.º 16
0
    def update_stat(self, ):
        #更新最后修改时间
        now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        pos_li = self.file_list[-1]
        des_pos_li = self.merge_pos()
        for pos in des_pos_li:
            cur_info = self.file_list[int(pos[0][0])]
            cur_info['last_update'] = now
        
        #删除已提交的坐标
        try:
            #print des_pos_li
            for des_pos in des_pos_li:
                for pos in des_pos:
                    pos = map(lambda x: int(x), pos)
                    pos_li.remove(pos)
        except:
            print u'删除已提交的坐标出错'
            exception.fallback(conf.reply)
            #exception.dat_fallback()
            #exception.unlock_dat_file()
            exit(1)

        #print self.file_list
        file_obj = open(self.des_path, 'w+b')
        try:
            json.dump(self.file_list, file_obj, indent = 2)
        except:
            print u'更新数据文件失败'
            exception.fallback(conf.reply)
            #exception.dat_fallback()
            #exception.unlock_dat_file()
            exit(1)

        finally:
            file_obj.close()
Exemplo n.º 17
0
 def text_opt(self, src_file_text, des_file_text, key_word_list):
     des_text = des_file_text
     if self.opt == u'增加':
         for key_word in key_word_list:
             print u'当前处理:%s' % key_word
             key_text, tag_name = self.get_key_text(src_file_text, key_word)
             try:
                 self.get_key_text(des_file_text, key_word)
             except:
                 pass
             else:
                 print u'目标文件中已存在"%s"' % key_word
                 exception.file_fallback(self.des_path)
                 exception.fallback(conf.reply)
                 sys.exit(1)
             des_text = self.add_to_file(des_text, key_text, tag_name)
             print u'增加%s成功' % key_word
         #替换计数行
         #des_text = self.chg_rec_num(src_file_text, des_text, self.format_str_list[1])
     elif self.opt == u'删除':
         for key_word in key_word_list:
             print u'当前处理:%s' % key_word
             key_text, tag_name = self.get_key_text(des_file_text, key_word)
             des_text = self.del_from_file(des_text, key_text, tag_name)
         #替换计数行
         #des_text = chg_rec_num(src_file_text, des_text, self.format_str_list[1])
     elif self.opt == u'修改':
         for key_word in key_word_list:
             print u'当前处理:%s' % key_word
             src_key_text = self.get_key_text(src_file_text, key_word)[0]
             des_key_text = self.get_key_text(des_file_text, key_word)[0]
             des_text = self.rep_file(des_text, des_key_text, src_key_text)
     else:
         print u'选项设置错误,请检查'
         exit(1)
     return des_text
Exemplo n.º 18
0
 def text_opt(self, src_file_text, des_file_text, key_word_list):
     des_text = des_file_text
     if self.opt == u'增加':
         for key_word in key_word_list:
             print u'当前处理:%s' % key_word
             key_text, tag_name = self.get_key_text(src_file_text, key_word)
             try:
                 self.get_key_text(des_file_text, key_word)
             except:
                 pass
             else:
                 print u'目标文件中已存在"%s"' % key_word
                 exception.file_fallback(self.des_path)
                 exception.fallback(conf.reply)
                 sys.exit(1)
             des_text = self.add_to_file(des_text, key_text, tag_name)
             print u'增加%s成功' % key_word
         #替换计数行
         #des_text = self.chg_rec_num(src_file_text, des_text, self.format_str_list[1])
     elif self.opt == u'删除':
         for key_word in key_word_list:
             print u'当前处理:%s' % key_word
             key_text, tag_name = self.get_key_text(des_file_text, key_word)
             des_text = self.del_from_file(des_text, key_text, tag_name)
         #替换计数行
         #des_text = chg_rec_num(src_file_text, des_text, self.format_str_list[1])
     elif self.opt == u'修改':
         for key_word in key_word_list:
             print u'当前处理:%s' % key_word
             src_key_text = self.get_key_text(src_file_text, key_word)[0]
             des_key_text = self.get_key_text(des_file_text, key_word)[0]
             des_text = self.rep_file(des_text, des_key_text, src_key_text)
     else:
         print u'选项设置错误,请检查'
         exit(1)
     return des_text
Exemplo n.º 19
0
    def file_chg(self):
        des_file_text = get_file_text(self.des_path)
        src_file_text = get_file_text(self.src_path)
        #key_text_list = self.get_key_text_list(self.format_str_list)

        try:
            new_text = self.text_opt(src_file_text, des_file_text,
                                     self.key_word_list)
        except RecNumError:
            print u'计数行有多个相同项无法处理'
            exception.file_fallback(self.des_path)
            exception.fallback(conf.reply)
            #exception.dat_fallback()
            #exception.unlock_dat_file()
            exit(1)
        except TextError:
            print u'有多个相同标签,无法处理'
            exception.file_fallback(self.des_path)
            exception.fallback(conf.reply)
            #exception.dat_fallback()
            #exception.unlock_dat_file()
            exit(1)
        except:
            print self.des_path + u' 操作失败,请检查确认操作内容是否填写错误'
            exception.file_fallback(self.des_path)
            exception.fallback(conf.reply)
            #exception.dat_fallback()
            #exception.unlock_dat_file()
            exit(1)
        else:
            #写入新文件
            new_des_file_obj = open(self.des_path, 'w+b')
            try:
                new_des_file_obj.write(new_text)
            except:
                print u'写入新文件\n' + self.des_path + u'失败'
                exception.file_fallback(self.des_path)
                exception.fallback(conf.reply)
                #exception.dat_fallback()
                #exception.unlock_dat_file()
                exit(1)
            finally:
                new_des_file_obj.close()
Exemplo n.º 20
0
    def file_chg(self):
        des_file_text = get_file_text(self.des_path)
        src_file_text = get_file_text(self.src_path)
        #key_text_list = self.get_key_text_list(self.format_str_list)

        try:
            new_text =  self.text_opt(src_file_text, des_file_text, self.key_word_list)
        except RecNumError:
            print u'计数行有多个相同项无法处理'
            exception.file_fallback(self.des_path)
            exception.fallback(conf.reply)
            #exception.dat_fallback()
            #exception.unlock_dat_file()
            exit(1)
        except TextError:
            print u'有多个相同标签,无法处理'
            exception.file_fallback(self.des_path)
            exception.fallback(conf.reply)
            #exception.dat_fallback()
            #exception.unlock_dat_file()
            exit(1)
        except:
            print self.des_path + u' 操作失败,请检查确认操作内容是否填写错误'
            exception.file_fallback(self.des_path)
            exception.fallback(conf.reply)
            #exception.dat_fallback()
            #exception.unlock_dat_file()
            exit(1)
        else:
            #写入新文件
            new_des_file_obj = open(self.des_path, 'w+b')
            try:
                new_des_file_obj.write(new_text)
            except:
                print u'写入新文件\n' + self.des_path + u'失败'
                exception.file_fallback(self.des_path)
                exception.fallback(conf.reply)
                #exception.dat_fallback()
                #exception.unlock_dat_file()
                exit(1)
            finally:
                new_des_file_obj.close()
Exemplo n.º 21
0
                print u'选项错误,请重新输入'

    #try:
    #打印未提交文件列表
    dat.show_list()

    #获取未提交的文件信息列表
    try:
        cur_commit_info_li = dat.get_commit_info()
        #print 'cur_commit_info_li, ', cur_commit_info_li
        #未提交文件列表,分别为已存在的文件列表和新增文件列表
        new_add_commit_info, other_commit_info = get_file_list(
            cur_commit_info_li)
    except:
        print u'获取未提交的文件信息列表失败'
        exception.fallback(conf.reply)
        exit(1)

    #提交前svn更新、锁定待提交文件
    #print u'新增的未提交文件列表, ', new_add_commit_info
    #print u'已存在的未提交文件列表, ', other_commit_info
    if other_commit_info:
        ready_for_commit(des_dir, other_commit_info)

    #修改目标文件内容
    for commit_info in cur_commit_info_li:
        ret = get_file_info(commit_info)
        #非xml文件直接覆盖
        if ret == 1:
            copy.copy(commit_info[-1], src_dir, des_dir, conf.reply)
        #新增文件直接复制,提交时需先add才能commit