예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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))
예제 #4
0
 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
예제 #5
0
파일: __init__.py 프로젝트: mvo5/snapcraft
    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)
예제 #6
0
    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)
예제 #7
0
    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)
예제 #8
0
파일: __init__.py 프로젝트: mvo5/snapcraft
 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
예제 #9
0
    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
예제 #10
0
    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
예제 #11
0
파일: __init__.py 프로젝트: mvo5/snapcraft
    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
예제 #12
0
    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)
예제 #13
0
    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)
예제 #14
0
    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)
예제 #15
0
    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)
예제 #16
0
파일: __init__.py 프로젝트: mvo5/snapcraft
    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()
예제 #17
0
    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))
예제 #18
0
    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))
예제 #19
0
파일: __init__.py 프로젝트: mvo5/snapcraft
    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)
예제 #20
0
파일: __init__.py 프로젝트: mvo5/snapcraft
    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))