def process_section(self, section_name, b_verbose=False): # this sections' repositories are under this folder section_folder = os.path.abspath(self.config['folders'][section_name]) # get conflict list of the section self.conflict_list = collect_conflicts(section_folder) # filter blank write_this = [conflict for conflict in self.conflict_list if conflict] # no point of writing if no conflict if write_this: with open(section_name + '_' + self.config['operation']['conflict_output_file'], 'wt', encoding='utf-8') as f_out: for conflict in write_this: f_out.write(pprint.pformat(conflict) + '\n') # return value result = self.conflict_list # reset conflict storage self.conflict_list = unique_list.unique_list() return result
def __init__(self, config_filename=False): # prepare configuration self.config = configparser.ConfigParser() if config_filename: config_filename = config_filename else: config_filename = 'reference.cfg' if os.path.exists(config_filename): self.config.read(config_filename) else: raise IOError("Can't find config file %s" % config_filename) # folder self.folder = os.path.abspath(self.config['operation']['folder']) print(self.folder) # comments self.comments = unique_list.unique_list() # initialize from the file if os.path.exists(self.config['operation']['comment_output_file']): with open(self.config['operation']['comment_output_file'], 'rt', encoding='utf-8') as f_in: start_list = f_in.readlines() for item in start_list: self.comments.add(item.strip())
def __init__(self, config_filename=False): # prepare configuration self.config = configparser.ConfigParser() if config_filename: config_filename = config_filename else: config_filename = 'detect_conflict.cfg' if os.path.exists(config_filename): self.config.read(config_filename) else: raise IOError("Can't find config file %s" % config_filename) # to store conflict info self.conflict_list = unique_list.unique_list()
def __init__(self): super(RepoEvalPoundByteCounterExcludingRef, self).__init__() if os.path.exists(self.reference_cfg_filename): self.comments_ref = unique_list.unique_list() self.config_ref = configparser.ConfigParser() self.config_ref.read(self.reference_cfg_filename) reference_comment_filename = self.config_ref['operation']['comment_output_file'] with open(reference_comment_filename, 'r', encoding='utf-8') as f_in: for line in f_in: self.comments_ref.add(line.strip()) else: self.init_reference_cfg_file()
def collect_comments_recursively(path, comments=unique_list.unique_list(), b_verbose=False): for root_path, _, file_names in os.walk(path): if not ignore.is_ignore_path(root_path): for file_name in file_names: if ignore.is_python(file_name): full_path = os.path.join(root_path, file_name) for line in read_python.get_comments_list_from_filename(full_path): comments.add(line) if b_verbose: print('len(comments) =', len(comments)) else: if b_verbose: print('ignore file %s' % file_name) else: if b_verbose: print('ignore path %s' % root_path) return comments
def __init__(self): # header row self.column = unique_list.unique_list() # table body self.index = {}
def convert_git_log_to_table(self, git_log): # column titles == unique file names in the git log column_set = unique_list.unique_list() commits_list = [] eval_dict = {} # one big git log -> list of commits git_log_split_blocks = git_log.split(self.commit_split_token) # remove empty string # TODO : consider git_log.strip(self.commit_split_token).split(self.commit_split_token) # to avoid a special case if not git_log_split_blocks[0]: del git_log_split_blocks[0] temporary_file_list = unique_list.unique_list(['no commit yet']) last_commit_dict = {'subject': 'no commit yet'} # commit loop for git_log_block in git_log_split_blocks: # TODO : refactor into a method? # one commit example: # < commit information > # <int add> <int del> <filename 0> # <int add> <int del> <filename 1> # <int add> <int del> <filename 2> # <int add> <int del> <filename 3> # <blank line> git_log_lines = git_log_block.splitlines() # using git log output as input to python last_commit_dict = self.get_commit_dict(git_log_lines[0]) if isinstance(last_commit_dict, (str, bytes)): # if double quote is wrapping the output from the git log last_commit_dict = self.get_commit_dict( git_log_lines[0].strip('"')) if isinstance(last_commit_dict, (str, bytes)): # if still a str or bytes, try again last_commit_dict = self.get_commit_dict(last_commit_dict) assert isinstance(last_commit_dict, dict), f"git_log_lines[0] = {repr(git_log_lines[0])}\n" \ f"convert_git_log_to_table(): last_commit_dict = {last_commit_dict}" \ f"convert_git_log_to_table(): isinstance(last_commit_dict, dict) = {isinstance(last_commit_dict, dict)}" \ f"convert_git_log_to_table(): type(last_commit_dict) = {type(last_commit_dict)}" # filer using email address # TODO : consider refactoring into a function if last_commit_dict['email'] in self.exclude_email_tuple: last_commit_dict = {} continue # keep note of commits commits_list.append(last_commit_dict) # reset storage for 'files in commit' temporary_file_list = unique_list.unique_list() line = 'could be a merge commit' # process file list for line in git_log_lines[1:]: # lines below the new commit line_strip = line.strip() if line_strip: # a file in the last_commit_dict # get path/filename add__delete__key = line_strip.split() column_key = add__delete__key[2] path, filename = os.path.split(column_key) # check ignore list if not (self.is_ignore_path(path) or self.is_ignore_filename(filename)): # if n files in one commit, evaluation would be 1/n # TODO : simplify data structures # for header of the table column_set.add(column_key) # to count the number of temporary_file_list.add(column_key) # end of files list if temporary_file_list: point = fractions.Fraction(1, len(temporary_file_list)) # build commit count table # loop over files in commit for files_in_commit in temporary_file_list: eval_dict[files_in_commit] = eval_dict.get( files_in_commit, 0) + point # if it is still not a dict if isinstance(last_commit_dict, str): # try to convert it again print(f'last_commit_dict = {repr(last_commit_dict)}') last_commit_dict = ast.literal_eval(last_commit_dict) if not isinstance(last_commit_dict, dict): raise ValueError( f'last_commit_dict = {repr(last_commit_dict)}') last_commit_dict['files'] = temporary_file_list else: print( f'\n{self.get_class_name()}.convert_git_log_to_table() : end of file list but temporary_file_list empty') print(f'line = {line}') print('last_commit_dict =', repr(last_commit_dict)) # total number of commits # to make it the first element # Sorting feature may use this feature column_key = ' total' column_set.add(column_key) eval_dict[column_key] = len(commits_list) return column_set, eval_dict