def package_case(caseName: str, caseDir: str, cases: list, namingScheme:str, incrementor: int): """ Packages a specific case type into the given directory, splitting input and output into their own directories. Arguments: caseName: str - The name of the case type to package caseDir: str - The directory to package the case into cases: list - The list of possible cases to package namingScheme: str - The naming scheme to follow for each file. Possible variables are {input_output},{caseType},{number} """ inputPath = fileops.join_path(caseDir, 'input') outputPath = fileops.join_path(caseDir, 'output') fileops.make(inputPath, FileType.DIRECTORY) fileops.make(outputPath, FileType.DIRECTORY) for case in [c for c in cases if c.get_case_string() == caseName]: inputNamingDict = _generate_case_naming_dict('input', caseName, case.caseNumber, incrementor) outputNamingDict = _generate_case_naming_dict('output', caseName, case.caseNumber, incrementor) inputFilePath = fileops.join_path(inputPath, namingScheme.format(**inputNamingDict)) outputFilePath = fileops.join_path(outputPath, namingScheme.format(**outputNamingDict)) fileops.write_file(inputFilePath, case.inputContents) fileops.write_file(outputFilePath, case.outputContents) incrementor += 1 return incrementor
def get_all_cases(problemNumber=None): """ Resolves the cases directory from the definitions file and delegates to _get_all_cases :return: {problemNumber: [Case]} """ return _get_all_cases(fileops.join_path(PathMapper._rootPath, Definitions.get_value('test_directory')), problemNumber=problemNumber)
def load_config_file(path=None): """ Loads the config file into the global config variable Keyword Arguments: path: str - The path to load the config from (default: conf/packages.json) """ if path is None: path = fileops.join_path(PathMapper.get_config_path(), CONFIGURATION_FILE) global config config = fileops.get_json_dict(path)
def package_type(packagePath: str, cases: list, packageType: dict, compressionDict: dict, typeName: str): """ Packages a specific case type by first making the directory that it belongs in, then packaging its cases, then compressing its cases Arguments: packagePath: str - The path that the user wants the package to go cases: list - The list of cases that need to be package packageType: dict- The configuration file dictionary of package types that need to be made compressionDict: dict - The dictionary corresponding to the compression settings from the config file """ incrementor = 0 for case in packageType['cases']: casePath = fileops.join_path(packagePath, typeName) fileops.make(casePath, FileType.DIRECTORY) incrementor = package_case(case, casePath, cases, packageType['naming'], incrementor) compress_case(case, casePath, compressionDict)
def package_into_path(path: str, layoutDict: dict): """ Follows the users provided configuration file to package all cases into the provided path. Delegates most functionality to other functions. Arguments: path: str - The path to package into layoutDict: dict - The dict provided by the user's configuration """ # Look through all cases... for problemNumber, caseList in case.get_all_cases().items(): # Make the directories for the problem numbers problemDirName = Definitions.get_value('solution_naming').format( **dict(problem=problemNumber)) problemPath = fileops.join_path(path, problemDirName) fileops.make(problemPath, FileType.DIRECTORY) # Go through each type in the config file and package it for packageTypeName, packageType in layoutDict[TYPES_KEY].items(): package_type(problemPath, caseList, packageType, _get_compression_from_layout_dict(layoutDict), packageTypeName)
def _get_config_path(cls): return fileops.join_path(PathMapper._rootPath, cls.JSON_FILE)
def load_from_folder(cls, folderName): """ Loads a writer from their folder utilizing the pathmapper """ return cls.load_from_path(fileops.join_path(PathMapper._rootPath, folderName))
def _get_sub_path(self, path) -> str: return fileops.join_path(self._path, path)
def get_definitions_filepath(cls): """ Gets the filepath of the definitions file based on the path mapper """ return fileops.join_path(PathMapper.get_config_path(), Definitions.DEFINITIONS_FILE)
def get_mapped_path(cls, path): """ Returns the root path appended with the provided path """ return fileops.join_path(cls._rootPath, path)
def get_config_path(cls): """ Returns the full configuration directory path """ return fileops.join_path(cls._rootPath, cls.CONFIG_DIR)
def get_variables_filepath(cls): """ Gets the filepath of the variables file based on a given path mapper """ return fileops.join_path(PathMapper.get_config_path(), Variables.VARIABLES_FILE)
def get_languages_filepath(cls): """ Gets the filepath of the languages file based on the path mapper """ return fileops.join_path(PathMapper.get_config_path(), Languages.LANGUAGES_FILE)