Esempio n. 1
0
    def revisions(self, path, max_revisions):
        """
        Get the list of revisions.

        :param path: the path to target.
        :type  path: ``str``

        :param max_revisions: the maximum number of revisions.
        :type  max_revisions: ``int``

        :return: A list of revisions.
        :rtype: ``list`` of :class:`Revision`
        """
        mtime = os.path.getmtime(path)
        key = hashlib.sha1(str(mtime).encode()).hexdigest()[:7]
        return [
            Revision(
                key=key,
                author_name="Local User",  # Don't want to leak local data
                author_email="-",  # as above
                date=int(mtime),
                message="None",
                files=[],
            )
        ]
Esempio n. 2
0
def test_store_relative_paths(tmpdir):
    """
    Test that the store command works when absolute paths are used for the targets..
    """
    config = DEFAULT_CONFIG
    cache_path = pathlib.Path(tmpdir) / ".wily"
    target_path = str(pathlib.Path(tmpdir) / "foo" / "bar.py")
    cache_path.mkdir()
    config.cache_path = cache_path
    config.path = tmpdir
    _TEST_STATS = {"operator_data": {"test": {target_path: {"metric1": 1}}}}
    _TEST_REVISION = Revision(
        key="12345",
        author_name="Anthony Shaw",
        author_email="*****@*****.**",
        date="17/01/1990",
        message="my changes",
    )
    fn = cache.store(config, ARCHIVER_GIT, _TEST_REVISION, _TEST_STATS)
    with open(fn) as cache_item:
        result = json.load(cache_item)
        assert isinstance(result, dict)
        if sys.platform == "win32":
            assert "foo\\bar.py" in result["operator_data"]["test"].keys()
        else:
            assert "foo/bar.py" in result["operator_data"]["test"].keys()
Esempio n. 3
0
    def revisions(self, path, max_revisions):
        """
        Get the list of revisions.

        :param path: the path to target.
        :type  path: ``str``

        :param max_revisions: the maximum number of revisions.
        :type  max_revisions: ``int``

        :return: A list of revisions.
        :rtype: ``list`` of :class:`Revision`
        """
        if self.repo.is_dirty():
            raise DirtyGitRepositoryError(self.repo.untracked_files)

        revisions = []
        for commit in self.repo.iter_commits(
            self.current_branch, max_count=max_revisions
        ):
            rev = Revision(
                key=commit.name_rev.split(" ")[0],
                author_name=commit.author.name,
                author_email=commit.author.email,
                date=commit.committed_date,
                message=commit.message,
            )
            revisions.append(rev)
        return revisions
Esempio n. 4
0
    def find(self, search: str) -> Revision:
        """
        Search a string and return a single revision.

        :param search: The search term.
        :type  search: ``str``

        :return: An instance of revision.
        :rtype: Instance of :class:`Revision`
        """
        commit = self.repo.commit(search)
        tracked_files, tracked_dirs = get_tracked_files_dirs(self.repo, commit)
        if not commit.parents:
            added_files = tracked_files
            modified_files = []
            deleted_files = []
        else:
            added_files, modified_files, deleted_files = whatchanged(
                commit, self.repo.commit(commit.hexsha + "~1"))

        return Revision(
            key=commit.name_rev.split(" ")[0],
            author_name=commit.author.name,
            author_email=commit.author.email,
            date=commit.committed_date,
            message=commit.message,
            tracked_files=tracked_files,
            tracked_dirs=tracked_dirs,
            added_files=added_files,
            modified_files=modified_files,
            deleted_files=deleted_files,
        )
Esempio n. 5
0
 def revisions(self, path, max_revisions):
     return [
         Revision(
             key="12345",
             author_name="Local User",  # Don't want to leak local data
             author_email="-",  # as above
             date=12_345_679,
             message="None",
         )
     ]
Esempio n. 6
0
File: state.py Progetto: Kilo59/wily
 def fromdict(d):
     """Instantiate from a dictionary."""
     rev = Revision(
         key=d["key"],
         author_name=d["author_name"],
         author_email=d["author_email"],
         date=d["date"],
         message=d["message"],
     )
     operators = d["operators"]
     return IndexedRevision(revision=rev, operators=operators)
Esempio n. 7
0
    def revisions(self, path: str, max_revisions: int) -> List[Revision]:
        """
        Get the list of revisions.

        :param path: the path to target.
        :type  path: ``str``

        :param max_revisions: the maximum number of revisions.
        :type  max_revisions: ``int``

        :return: A list of revisions.
        :rtype: ``list`` of :class:`Revision`
        """
        if self.repo.is_dirty():
            raise DirtyGitRepositoryError(self.repo.untracked_files)

        revisions = []
        for commit in self.repo.iter_commits(self.current_branch,
                                             max_count=max_revisions,
                                             reverse=True):
            tracked_files, tracked_dirs = get_tracked_files_dirs(
                self.repo, commit)
            if not commit.parents or not revisions:
                added_files = tracked_files
                modified_files = []
                deleted_files = []
            else:
                added_files, modified_files, deleted_files = whatchanged(
                    commit, self.repo.commit(commit.hexsha + "~1"))

            logger.debug(
                f"For revision {commit.name_rev.split(' ')[0]} found:")
            logger.debug(f"Tracked files: {tracked_files}")
            logger.debug(f"Tracked directories: {tracked_dirs}")
            logger.debug(f"Added files: {added_files}")
            logger.debug(f"Modified files: {modified_files}")
            logger.debug(f"Deleted files: {deleted_files}")

            rev = Revision(
                key=commit.name_rev.split(" ")[0],
                author_name=commit.author.name,
                author_email=commit.author.email,
                date=commit.committed_date,
                message=commit.message,
                tracked_files=tracked_files,
                tracked_dirs=tracked_dirs,
                added_files=added_files,
                modified_files=modified_files,
                deleted_files=deleted_files,
            )
            revisions.append(rev)
        return revisions[::-1]
Esempio n. 8
0
 def revisions(self, path, max_revisions):
     return [
         Revision(
             key="12345",
             author_name="Local User",  # Don't want to leak local data
             author_email="-",  # as above
             date=12_345_679,
             message="None",
             tracked_files=[],
             tracked_dirs=[],
             added_files=[],
             modified_files=[],
             deleted_files=[],
         )
     ]
Esempio n. 9
0
 def fromdict(d):
     """Instantiate from a dictionary."""
     rev = Revision(
         key=d["key"],
         author_name=d["author_name"],
         author_email=d["author_email"],
         date=d["date"],
         message=d["message"],
         tracked_files=d["tracked_files"] if "tracked_files" in d else [],
         tracked_dirs=d["tracked_dirs"] if "tracked_dirs" in d else [],
         added_files=d["added_files"] if "added_files" in d else [],
         modified_files=d["modified_files"]
         if "modified_files" in d else [],
         deleted_files=d["deleted_files"] if "deleted_files" in d else [],
     )
     operators = d["operators"]
     return IndexedRevision(revision=rev, operators=operators)
Esempio n. 10
0
def test_store_twice(tmpdir):
    """ Test that you can't write the same revision twice """
    config = DEFAULT_CONFIG
    cache_path = pathlib.Path(tmpdir) / ".wily"
    cache_path.mkdir()
    config.cache_path = cache_path
    target_path = str(pathlib.Path(tmpdir) / "foo" / "bar.py")
    _TEST_STATS = {"operator_data": {"test": {target_path: {"metric1": 1}}}}
    _TEST_REVISION = Revision(
        key="12345",
        author_name="Anthony Shaw",
        author_email="*****@*****.**",
        date="17/01/1990",
        message="my changes",
    )
    fn = cache.store(config, ARCHIVER_GIT, _TEST_REVISION, _TEST_STATS)
    with pytest.raises(RuntimeError):
        cache.store(config, ARCHIVER_GIT, _TEST_REVISION, _TEST_STATS)
Esempio n. 11
0
def test_store_basic(tmpdir):
    config = DEFAULT_CONFIG
    cache_path = pathlib.Path(tmpdir) / ".wily"
    cache_path.mkdir()
    config.cache_path = cache_path
    target_path = str(pathlib.Path(tmpdir) / "foo" / "bar.py")
    _TEST_STATS = {"operator_data": {"test": {target_path: {"metric1": 1}}}}
    _TEST_REVISION = Revision(
        key="12345",
        author_name="Anthony Shaw",
        author_email="*****@*****.**",
        date="17/01/1990",
        message="my changes",
    )
    fn = cache.store(config, ARCHIVER_GIT, _TEST_REVISION, _TEST_STATS)
    with open(fn) as cache_item:
        result = json.load(cache_item)
        assert isinstance(result, dict)
        assert result == _TEST_STATS
Esempio n. 12
0
    def find(self, search):
        """
        Search a string and return a single revision.

        :param search: The search term.
        :type  search: ``str``

        :return: An instance of revision.
        :rtype: Instance of :class:`Revision`
        """
        commit = self.repo.commit(search)

        return Revision(
            key=commit.name_rev.split(" ")[0],
            author_name=commit.author.name,
            author_email=commit.author.email,
            date=commit.committed_date,
            message=commit.message,
            files=list(commit.stats.files.keys()),
        )