def get_sorted_id(self):
     # get ids from sorted merged file
     logger.info("Begin method get_sorted_id")
     id_array = []
     fpath1 = os.path.join('.', DIR_NAME, mergedSortedResultFile)
     with open(fpath1) as f1:
         lines = (line.rstrip()
                  for line in f1)  # All lines including the blank ones
         lines = (line for line in lines if line)  # Non-blank lines
         f1.readline()  # skip header
         for line in lines:
             ids = line.split('|')[0]
             key = ids + "\n"
             if key in id_array:
                 logger.info(
                     "Id " + ids +
                     ", already exists in the id's array. Will not be added a second time."
                 )
             else:
                 id_array.append(key)
     file_id_array = []
     file_id_array.append("FormattedID\n")
     logger.info("List of Ids to be promoted: \n" + str(id_array))
     if id_array:
         file_id_array.extend(id_array)
         og_utils.write_file(sortedIdFile, file_id_array)
     else:
         warn_msg = "No stories(US) or defects(D) available for promotion."
         logger.info(warn_msg)
         sys.stdout.write("\n" + warn_msg)
         sys.stdout.flush()
     logger.info("End method get_sorted_id")
     return id_array
 def get_sorted_verified_in_build(self):
     # get verified_in_build from sorted merged file
     logger.info("Begin method get_sorted_verified_in_build.")
     build_list = self.extract_all_builds()
     if build_list:
         list_to_examine = copy.deepcopy(build_list)
         promote_builds = self.get_only_highest_builds(list_to_examine)
         if promote_builds:
             og_utils.write_file(verifiedInBuildFile, promote_builds)
     else:
         warn_msg = "No builds availble for promotion."
         sys.stdout.write("\n" + warn_msg)
         sys.stdout.flush()
     logger.info("End method get_sorted_verified_in_build.")
 def get_ignored_ids(self, id_array):
     logger.info("Begin method get_ignored_ids")
     ignore_ids = []
     file_ignore_ids = []
     file_ignore_ids.append("FormattedID\n")
     for curr_id in self.all_ids:
         check_string = curr_id + "\n"
         if check_string not in id_array:
             ignore_ids.append(check_string)
     if ignore_ids:
         ignore_ids.sort(key=lambda x: x[0])
         file_ignore_ids.extend(ignore_ids)
     og_utils.write_file("ignore_ids.csv", file_ignore_ids)
     logger.info("List of Ids that will not be promoted are: " +
                 str(ignore_ids))
     logger.info("End method get_ignored_ids")
     return ignore_ids
    def sanitize_output_result(self, file_to_clean, sanitizeSortedResultFile,
                               ignore_file):
        logger.info("Begin method sanitize_output_result.")
        ignore_array_file = []
        sanitized_file_array = []
        sanitized_file_array.append(finalHeader + '\n')
        ignore_array_file.append(finalHeader + '\n')
        with open(file_to_clean) as f1:
            f1.readline()  # skip header
            lines = (line.rstrip()
                     for line in f1)  # All lines including the blank ones
            lines = (line for line in lines if line)  # Non-blank lines
            for line in lines:
                id = line.split('|')[0]
                self.all_ids.add(id)
                verifiedInBuild = line.split('|')[1]
                name = line.split('|')[2]
                split_verifiedInBuild = re.split('[> <]', verifiedInBuild)
                artifact_name = None
                for value in split_verifiedInBuild:
                    if self.check_if_string_is_artifact(value):
                        artifact_name = self.clean_artifact(value)
                if artifact_name:
                    line_passed = id + "|" + artifact_name + "|" + name + "\n"
                    logger.debug("Line passed is: " + line_passed)
                    sanitized_file_array.append(line_passed)
                else:
                    ignored_line = id + "|" + verifiedInBuild + "|" + name + "\n"
                    logger.info("Line ignored is: " + ignored_line)
                    ignore_array_file.append(ignored_line)

        if ignore_array_file:
            ignore_array_file.sort(key=lambda x: x[0])
            filepath = os.path.join('.', DIR_NAME, ignore_file)
            og_utils.write_file(filepath, ignore_array_file)

        if sanitized_file_array:
            filepath2 = os.path.join('.', DIR_NAME, sanitizeSortedResultFile)
            og_utils.write_file(filepath2, sanitized_file_array)

        logger.info("End method sanitize_output_result.")
예제 #5
0
def main(argv):
    logger.info("Begin main method.")
    logger.info("Python version: "+str(platform.python_version()))
    print(platform.python_version())
    environment = None
    config_file = None
    story_type = None
    rally_query =None
    entity_name = None

    if len(sys.argv) < 2:
        usage()
        sys.exit(1)

    try:
        opts, args = getopt.getopt(argv, "h:c:e:t:", ["help=", "config_file=", "environment=", "type="])
    except getopt.GetoptError as exc:
        print(exc.msg)
        usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit(0)

        elif opt in ("-c", "--config_file"):
            config_file = arg
        elif opt in ("-e", "--environment"):
            environment = arg
        elif opt in ("-t", "--type"):
            story_type = arg

    create_log_file()
    start = timeit.default_timer()
    try:
        validate_platform_clear_screen()
        start_message="Start Process of Retrieving data from Rally for promotion."
        logger.info(start_message)
        print("\n"+start_message+"\n")
        validate_inputs(config_file, environment, story_type)
        rally, projects, workspace = get_rally_projects(config_file)
        entity_name = set_entity(story_type)
        entity_dict = get_file_data_based_on_entity(entity_name)
        query_file = entity_dict['q_file']
        if os.path.isfile(query_file) is False:
            err_msg = "File [" + query_file + "] is not present."
            raise AttributeError(err_msg)

        query_file_map = og_utils.load_json(query_file)
        if environment in query_file_map:
            rally_query = query_file_map[environment]
        else:
            error_message = "There is no entry for " + environment + " in the file " + query_file
            raise AttributeError(error_message)

        data_array, raw_data_array = get_rally_entity_data(projects, rally, entity_name, workspace, rally_query)
        #print(data_array)
        og_utils.write_file(entity_dict['stageFile'], data_array)
        file_split_data_array, split_data_array = split_data_on_field(raw_data_array)
        #og_utils.write_file(entity_dict['finalFile'], file_split_data_array)
        sorted_file_array = create_sorted_file(split_data_array)
        filepath = os.path.join('.',DIR_NAME, entity_dict['finalSortedFile'])
        og_utils.write_file(filepath, sorted_file_array)

        exit_status = 0
        exit_message = 'Success'

    except Exception as ex:
        if str(ex):
            print (str(ex) + "\n")
        logger.exception(ex)
        exit_status = 1
        exit_message = 'Failed'
        exc_type, exc_obj, exc_tb = sys.exc_info()
        traceback.print_tb(exc_tb)

    finally:
        stop = timeit.default_timer()
        total_time = stop - start

        print("\nEnd Process of Retrieving data from Rally for promotion.\n")

        logger.info(
            "Script execution status [" + exit_message + "], time taken [" + str(datetime.timedelta(seconds=total_time)) + "]")
        sys.exit(exit_status)