Example #1
0
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
Example #2
0
    def create(self):
        if self._path is None or self._path == '':
            raise Exception('Cannot create writer without path')

        fileops.make(self._path, fileops.FileType.DIRECTORY)
        fileops.make(self._get_datafile_path(), fileops.FileType.FILE)
        Writers.add_writer(fileops.get_basename(self._path))
        self._write_datafile()
Example #3
0
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)
Example #4
0
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)
Example #5
0
def package(savePaths: list, configFilePath: str=None, layout: str=None):
    """
    The parent function that handles the package subparser call. Loads the
    configuration file and packages into the provided paths

    Arguments:
    savePaths: list - A list of paths to package into
    configFilePath: str - The Alternate configuration file specified by the user
    layout: str - The specific package layout to load
    """
    load_config_file(path=configFilePath)
    global config

    # Ensure layout is provided
    if len(config) > 1 and layout is None:
        raise Exception('Error: Must choose a package layout using --layout')
    if len(config) > 1 and not layout in config:
        raise Exception('Error: {} is an invalid layout'.format(layout))

    if len(config) == 1: layout = list(config.keys())[0]
    for path in savePaths:
        fileops.make(path, FileType.DIRECTORY)
        package_into_path(path, config[layout])