try: values = ','.join(cur.mogrify(arg_list, x) for x in lines) query = "insert into %s %s values " % (args.table_name, db_cols) cur.execute(query + values) # update status updater status_updater.total_added += len(lines) except Exception, e: traceback.print_exc() quit() # update status updater if file_length > 0: status_updater.current_val = os.lseek( infile.fileno(), 0, os.SEEK_CUR) status_updater.update() except Exception, e: traceback.print_exc() quit() status_updater.current_file += 1 status_updater.update() # commit the transaction print "Committing..." conn.commit()
def Redmine_build_bug(self, proj, NEW_PROJECT, PROJ_DICT): """ :param tag: :param start_time: 07-01 :param end_time: 07-31 :return: bug字典,当前时间段bug总数 """ # project = self.redmine.project.get(tag) # start_time = time.strftime('%m-01', time.localtime(time.time())) # end_time = time.strftime('%m-%d', time.localtime(time.time())) start_time = time.strftime('%Y-%m-01', time.localtime( time.time())) + " 08:00:0" end_time = time.strftime('%Y-%m-%d', time.localtime( time.time())) + " 08:00:0" start_time = datetime.datetime.utcfromtimestamp( int(time.mktime(time.strptime( start_time, "%Y-%m-%d %H:%M:%S")))).strftime("%Y-%m-%d") end_time = datetime.datetime.utcfromtimestamp( int(time.mktime(time.strptime( end_time, "%Y-%m-%d %H:%M:%S")))).strftime("%Y-%m-%d") if proj in NEW_PROJECT: # 新建项目,统计所有已创建bug issues_list = self.redmine.issue.filter( project_id=PROJ_DICT[proj]['redmine_project_id'], status_id="*", tracker_id=PROJ_DICT[proj]['redmine_tracker_id'], ) # print(len(issues_list)) issues_list_before = self.redmine.issue.filter( project_id=PROJ_DICT[proj]['redmine_project_id'], status_id="*", tracker_id=PROJ_DICT[proj]['redmine_tracker_id'], created_on='<=' + str(start_time)) created_bug_num = len(issues_list) # 非新建项目,只统计当前月新建bug数量 print("【Redmine】%s 新建bug数量为:%d " % (proj, created_bug_num)) proj_before_bug_num = int(len(issues_list_before)) print("【Redmine】%s %s月份之前新建bug数量为:%d " % (proj, self.MONTH, created_bug_num)) if proj_before_bug_num > 0: connect = DB().conn() cur = connect.cursor() updateTime = datetime.datetime.now() PROJ_BEFORE_BUG = DbSearch().search_proj_before_bug() if proj in PROJ_BEFORE_BUG: sql = 'insert into wbg_proj_before_bug (proj,beforeNum,updateTime) values (%(proj)s,%(beforeNum)s,%(updateTime)s)' value = { 'proj': proj, 'beforeNum': proj_before_bug_num, 'updateTime': updateTime } # print('------------------------') # print(value) cur.execute(sql, value) connect.commit() return created_bug_num else: issues_list = self.redmine.issue.filter( project_id=PROJ_DICT[proj]['redmine_project_id'], status_id="*", tracker_id=PROJ_DICT[proj]['redmine_tracker_id'], created_on='><' + str(start_time) + '|' + str(end_time)) # print(len(issues_list)) created_bug_num = len(issues_list) # 当前新建bug数量 print("【Redmine】%s 新建bug数量为:%d " % (proj, created_bug_num)) return created_bug_num