def last_step(self): for step in reversed(common.COMMAND_ORDER): if os.path.exists( states.get_step_state_file(self.plugin.statedir, step)): return step return None
def mark_done(self, step, state=None): if not state: state = {} with open(states.get_step_state_file(self.plugin.statedir, step), "w") as f: f.write(yaml_utils.dump(state))
def step_timestamp(self, step): try: return os.stat( states.get_step_state_file(self.plugin.statedir, step) ).st_mtime except FileNotFoundError as e: raise errors.StepHasNotRunError(self.name, step) from e
def mark_cleaned(self, step): state_file = states.get_step_state_file(self.plugin.statedir, step) if os.path.exists(state_file): os.remove(state_file) if os.path.isdir(self.plugin.statedir) and not os.listdir(self.plugin.statedir): os.rmdir(self.plugin.statedir)
def latest_step(self): for step in reversed(steps.STEPS): if os.path.exists( states.get_step_state_file(self.plugin.statedir, step)): return step raise errors.NoLatestStepError(self.name)
def mark_cleaned(self, step): state_file = states.get_step_state_file(self.statedir, step) if os.path.exists(state_file): os.remove(state_file) if os.path.isdir(self.statedir) and not os.listdir(self.statedir): os.rmdir(self.statedir)
def check_pull(self): # Check to see if pull needs to be updated state_file = states.get_step_state_file(self.plugin.statedir, steps.PULL) # Not all sources support checking for updates with contextlib.suppress(sources.errors.SourceUpdateUnsupportedError): if self.source_handler.check(state_file): return OutdatedReport(source_updated=True) return None
def next_step(self): next_step = None for step in reversed(common.COMMAND_ORDER): if os.path.exists( states.get_step_state_file(self.plugin.statedir, step)): break next_step = step return next_step
def mark_done(self, step, state=None): if not state: state = {} with open(states.get_step_state_file(self.plugin.statedir, step), 'w') as f: f.write(yaml.dump(state)) # We know we've only just completed this step, so make sure any later # steps don't have a saved state. for step in step.next_steps(): self.mark_cleaned(step)
def mark_done(self, step, state=None): if not state: state = {} index = common.COMMAND_ORDER.index(step) with open(states.get_step_state_file(self.statedir, step), 'w') as f: f.write(yaml.dump(state)) # We know we've only just completed this step, so make sure any later # steps don't have a saved state. if index + 1 != len(common.COMMAND_ORDER): for command in common.COMMAND_ORDER[index + 1:]: self.mark_cleaned(command)
def mark_done(self, step, state=None): if not state: state = {} index = common.COMMAND_ORDER.index(step) with open(states.get_step_state_file( self.plugin.statedir, step), 'w') as f: f.write(yaml.dump(state)) # We know we've only just completed this step, so make sure any later # steps don't have a saved state. if index+1 != len(common.COMMAND_ORDER): for command in common.COMMAND_ORDER[index+1:]: self.mark_cleaned(command)
def update_build(self): if not self.plugin.out_of_source_build: # Use the local source to update. It's important to use # file_utils.copy instead of link_or_copy, as the build process # may modify these files source = sources.Local( self.plugin.sourcedir, self.plugin.build_basedir, copy_function=file_utils.copy, ) if not source.check( states.get_step_state_file(self.plugin.statedir, steps.BUILD) ): return source.update() self._do_build(update=True)
def update_build(self): if not self.plugin.out_of_source_build: # Use the local source to update. It's important to use # file_utils.copy instead of link_or_copy, as the build process # may modify these files source = sources.Local( self.plugin.sourcedir, self.plugin.build_basedir, copy_function=file_utils.copy, ) if not source.check( states.get_step_state_file(self.plugin.statedir, steps.BUILD) ): return source.update() self._do_build()
def test_get_outdated_report(self): # No outdated reports should be available, yet main_part = self.project_config.parts.get_part("main") self.assertFalse(self.cache.get_outdated_report(main_part, steps.PULL)) # Now run the pull step for main lifecycle.execute(steps.PULL, self.project_config, part_names=["main"]) # Change the source on disk, which will make the pull step of main # outdated (to ensure this is the case, manually set the timestamp) open("new-file", "w").close() pull_state_file = states.get_step_state_file(main_part.plugin.statedir, steps.PULL) access_time = os.stat(pull_state_file).st_atime modified_time = os.stat(pull_state_file).st_atime os.utime("new-file", (access_time, modified_time + 1)) # Should still have cached that it's not outdated, though self.assertFalse(self.cache.get_outdated_report(main_part, steps.PULL)) # Now clear that step from the cache, and it should be up-to-date self.cache.clear_step(main_part, steps.PULL) self.assertTrue(self.cache.get_outdated_report(main_part, steps.PULL))
def test_get_outdated_report(self): # No outdated reports should be available, yet main_part = self.project_config.parts.get_part("main") self.assertFalse(self.cache.get_outdated_report(main_part, steps.PULL)) # Now run the pull step for main lifecycle.execute(steps.PULL, self.project_config, part_names=["main"]) # Change the source on disk, which will make the pull step of main # outdated (to ensure this is the case, manually set the timestamp) open("new-file", "w").close() pull_state_file = states.get_step_state_file( main_part.plugin.statedir, steps.PULL ) access_time = os.stat(pull_state_file).st_atime modified_time = os.stat(pull_state_file).st_atime os.utime("new-file", (access_time, modified_time + 1)) # Should still have cached that it's not outdated, though self.assertFalse(self.cache.get_outdated_report(main_part, steps.PULL)) # Now clear that step from the cache, and it should be up-to-date self.cache.clear_step(main_part, steps.PULL) self.assertTrue(self.cache.get_outdated_report(main_part, steps.PULL))
def latest_step(self): for step in reversed(steps.STEPS): if os.path.exists(states.get_step_state_file(self.plugin.statedir, step)): return step raise errors.NoLatestStepError(self.name)
def mark_done(self, step, state=None): if not state: state = {} with open(states.get_step_state_file(self.plugin.statedir, step), "w") as f: f.write(yaml.dump(state))