def pcs_full(): """ Returns: PCS: object with performance control system, initialized with some files and stuff """ # Change working dir into the temporary directory profiles = stored_profile_pool() pcs_path = tempfile.mkdtemp() os.chdir(pcs_path) commands.init_perun_at(pcs_path, False, {'vcs': { 'url': '../', 'type': 'git' }}) # Construct the PCS object pcs_obj = pcs.PCS(pcs_path) # Initialize git vcs.init('git', pcs_path, {}) # Populate repo with commits repo = git.Repo(pcs_path) # Create first commit file1 = os.path.join(pcs_path, "file1") store.touch_file(file1) repo.index.add([file1]) root = repo.index.commit("root") # Create second commit file2 = os.path.join(pcs_path, "file2") store.touch_file(file2) repo.index.add([file2]) current_head = repo.index.commit("second commit") # Populate PCS with profiles root_profile = Helpers.prepare_profile(pcs_obj, profiles[0], str(root)) commands.add([root_profile], str(root)) chead_profile1 = Helpers.prepare_profile(pcs_obj, profiles[1], str(current_head)) chead_profile2 = Helpers.prepare_profile(pcs_obj, profiles[2], str(current_head)) commands.add([chead_profile1, chead_profile2], str(current_head)) # Assert that we have five blobs: 2 for commits and 3 for profiles pcs_object_dir = os.path.join(pcs_path, ".perun", "objects") number_of_perun_objects = sum( len(os.listdir(os.path.join(pcs_object_dir, sub))) for sub in os.listdir(pcs_object_dir)) assert number_of_perun_objects == 5 yield pcs_obj # clean up the directory shutil.rmtree(pcs_path)
def pcs_with_degradations(): """ """ pool_path = os.path.join(os.path.split(__file__)[0], 'degradation_profiles') profiles = [ os.path.join(pool_path, 'linear_base.perf'), os.path.join(pool_path, 'linear_base_degradated.perf'), os.path.join(pool_path, 'quad_base.perf') ] # Change working dir into the temporary directory pcs_path = tempfile.mkdtemp() os.chdir(pcs_path) commands.init_perun_at(pcs_path, False, {'vcs': {'url': '../', 'type': 'git'}}) # Initialize git vcs.init({}) # Populate repo with commits repo = git.Repo(pcs_path) # Create first commit file1 = os.path.join(pcs_path, "file1") store.touch_file(file1) repo.index.add([file1]) root = repo.index.commit("root") # Create second commit repo.git.checkout('-b', 'develop') file2 = os.path.join(pcs_path, "file2") store.touch_file(file2) repo.index.add([file2]) middle_head = repo.index.commit("second commit") # Create third commit repo.git.checkout('master') file3 = os.path.join(pcs_path, "file3") store.touch_file(file3) repo.index.add([file3]) repo.index.commit("parallel commit") repo.git.merge('--no-ff', 'develop') current_head = str(repo.head.commit) # Populate PCS with profiles jobs_dir = pcs.get_job_directory() root_profile = Helpers.prepare_profile(jobs_dir, profiles[0], str(root)) commands.add([root_profile], str(root)) middle_profile = Helpers.prepare_profile(jobs_dir, profiles[1], str(middle_head)) commands.add([middle_profile], str(middle_head)) head_profile = Helpers.prepare_profile(jobs_dir, profiles[2], str(current_head)) commands.add([head_profile], str(current_head)) yield pcs # clean up the directory shutil.rmtree(pcs_path)
def pcs_with_empty_git(): """ """ # Change working dir into the temporary directory pcs_path = tempfile.mkdtemp() os.chdir(pcs_path) commands.init_perun_at(pcs_path, False, {'vcs': {'url': '../', 'type': 'git'}}) # Initialize git vcs.init({}) yield pcs # clean up the directory shutil.rmtree(pcs_path)
def pcs_with_empty_git(): """ Returns: PCS: object with performance control system initialized with empty git repository """ # Change working dir into the temporary directory pcs_path = tempfile.mkdtemp() os.chdir(pcs_path) commands.init_perun_at(pcs_path, False, {'vcs': { 'url': '../', 'type': 'git' }}) # Construct the PCS object pcs_obj = pcs.PCS(pcs_path) # Initialize git vcs.init('git', pcs_path, {}) yield pcs_obj # clean up the directory shutil.rmtree(pcs_path)
def init(dst, configuration_template='master', **kwargs): """Initializes the performance and version control systems Inits the performance control system at a given directory. Optionally inits the wrapper of the Version Control System that is used as tracking point. :param path dst: path where the pcs will be initialized :param dict kwargs: keyword arguments of the initialization :param str configuration_template: name of the template that will be used for initialization of local configuration """ perun_log.msg_to_stdout("call init({}, {})".format(dst, kwargs), 2) # First init the wrapping repository well vcs_type = kwargs['vcs_type'] vcs_path = kwargs['vcs_path'] or dst vcs_params = kwargs['vcs_params'] # Construct local config vcs_config = {'vcs': {'url': vcs_path, 'type': vcs_type}} # Check if there exists perun directory above and initialize the new pcs try: super_perun_dir = store.locate_perun_dir_on(dst) is_pcs_reinitialized = (super_perun_dir == dst) if not is_pcs_reinitialized: perun_log.warn("There exists super perun directory at {}".format( super_perun_dir)) except NotPerunRepositoryException: is_pcs_reinitialized = False init_perun_at(dst, is_pcs_reinitialized, vcs_config, configuration_template) # If the wrapped repo could not be initialized we end with error. The user should adjust this # himself and fix it in the config. Note that this decision was made after tagit design, # where one needs to further adjust some options in initialized directory. if vcs_type and not vcs.init(vcs_params): err_msg = "Could not initialize empty {0} repository at {1}.\n".format( vcs_type, vcs_path) err_msg += "Either reinitialize perun with 'perun init' or initialize {0} repository" err_msg += "manually and fix the path to vcs in 'perun config --edit'" perun_log.error(err_msg)