コード例 #1
0
ファイル: utils.py プロジェクト: lawsofthought/wilhelmproject
def get_experiment_details(exported_archive):
    '''
    Using the settings.cfg file inside the exported wilhelm
    experiments_directory, get the checksum of the source code of the
    Playlist sub class for each experiment listed therein as well as the
    file path names and checksums of the included files.

    This information is useful only to check if the relevant source and stimuli
    files for a given experiment change from one repository version to another.
    If they have changed, we know the experiment has changed.

    Return as dictionary of lists of tuples.
    '''

    experiments_module = python.impfromsource(
        conf.repository_experiments_modulename, exported_archive
    )

    experiments_settings\
    = os.path.join(exported_archive, conf.repository_settings_filename)

    config = configobj.ConfigObj(
        experiments_settings,
        configspec = conf.repository_settings_configspec
        )

    validator = validate.Validator()
    assert config.validate(validator, copy=True)

    experiments_dir = {}
    for class_name, expdict in config['experiments'].items():

        release_note = expdict['release-note']

        experiment_source = inspect.getsource(
            getattr(experiments_module, class_name)
            )

        file_info = dict(
            class_source = sys.checksum(experiment_source)
            )
       
        for filename in expdict['include']:

            file_hash = sys.checksum(
                os.path.join(exported_archive, filename)
            )

            file_info[filename] = file_hash

        experiments_dir[class_name] = dict(
                release_note = release_note, 
                file_info = file_info)

    return experiments_dir
コード例 #2
0
ファイル: utils.py プロジェクト: lawsofthought/wilhelmproject
    def _extracted_archive_check(self):
        ''' Does extraction_dir contain the extracted contents of the archive
        tarball?  '''

        with tarfile.open(self.tarball_path, self.tarfile_method) as tarball:
            checksum_string\
                    = tarball.extractfile(conf.tarball_checksum).read().strip()

        for line in checksum_string.split('\n'):
            relative_filepath, hashsum = line.split()
            fullpath = os.path.join(self.extraction_dir, relative_filepath)
            sys.assert_file_exists(fullpath)
            assert sys.checksum(fullpath) == hashsum

        return True # If we get this far.