Exemplo n.º 1
0
def shortest_path(source: str, target: str) -> List[Tuple[str, str]]:
    """
    Returns the shortest list of (movie_id, person_id) pairs
    that connect the source to the target.

    If no possible path, returns None.
    """

    proper_path = []

    origin = Actor(source, people)
    destination = Actor(target, people)
    # movies which have had the actor's names extracted
    explored_movies: Set[str] = set()

    # net of connections between actors
    # initalised with all connections to destination
    net = create_nodes(None, destination, explored_movies)

    for node in net:
        if matches(node, origin.movies):
            proper_path = create_path(node)
            # print(proper_path)
            return proper_path
        # keep adding to the end addtional nodes to end of list
        else:
            new_nodes = get_neighbours(node, explored_movies)
            for new_node in new_nodes:
                net.append(new_node)
    # will be empty - satisfies mypy req
    return proper_path
Exemplo n.º 2
0
def get_neighbours(parent: Node, explored_movies: Set[str]) -> List[Node]:
    # the node in the paramater becomes the parent of the neighbours/children
    neighbours = []
    movie_id = parent.movie
    m_data = movies[movie_id]
    # iterate through all actors in this node's movie
    for actor_id in m_data["stars"]:
        if parent.actor._id != actor_id:
            actor = Actor(actor_id, people)
            # make a node for each of this actor's movies
            # so there will be many nodes for this actor, each of a different movie
            neighbours += create_nodes(parent, actor, explored_movies)

    return neighbours
    def create_from_tree(cls,
                         repo,
                         tree,
                         message,
                         parent_commits=None,
                         head=False):
        """Commit the given tree, creating a commit object.
		
		:param repo: Repo object the commit should be part of 
		:param tree: Tree object or hex or bin sha 
			the tree of the new commit
		:param message: Commit message. It may be an empty string if no message is provided.
			It will be converted to a string in any case.
		:param parent_commits:
			Optional Commit objects to use as parents for the new commit.
			If empty list, the commit will have no parents at all and become 
			a root commit.
			If None , the current head commit will be the parent of the 
			new commit object
		:param head:
			If True, the HEAD will be advanced to the new commit automatically.
			Else the HEAD will remain pointing on the previous commit. This could 
			lead to undesired results when diffing files.
			
		:return: Commit object representing the new commit
			
		:note:
			Additional information about the committer and Author are taken from the
			environment or from the git configuration, see git-commit-tree for 
			more information"""
        parents = parent_commits
        if parent_commits is None:
            try:
                parent_commits = [repo.head.commit]
            except ValueError:
                # empty repositories have no head commit
                parent_commits = list()
            # END handle parent commits
        # END if parent commits are unset

        # retrieve all additional information, create a commit object, and
        # serialize it
        # Generally:
        # * Environment variables override configuration values
        # * Sensible defaults are set according to the git documentation

        # COMMITER AND AUTHOR INFO
        cr = repo.config_reader()
        env = os.environ
        default_email = get_user_id()
        default_name = default_email.split('@')[0]

        conf_name = cr.get_value('user', cls.conf_name, default_name)
        conf_email = cr.get_value('user', cls.conf_email, default_email)

        author_name = env.get(cls.env_author_name, conf_name)
        author_email = env.get(cls.env_author_email, default_email)

        committer_name = env.get(cls.env_committer_name, conf_name)
        committer_email = env.get(cls.env_committer_email, conf_email)

        # PARSE THE DATES
        unix_time = int(time())
        offset = altzone

        author_date_str = env.get(cls.env_author_date, '')
        if author_date_str:
            author_time, author_offset = parse_date(author_date_str)
        else:
            author_time, author_offset = unix_time, offset
        # END set author time

        committer_date_str = env.get(cls.env_committer_date, '')
        if committer_date_str:
            committer_time, committer_offset = parse_date(committer_date_str)
        else:
            committer_time, committer_offset = unix_time, offset
        # END set committer time

        # assume utf8 encoding
        enc_section, enc_option = cls.conf_encoding.split('.')
        conf_encoding = cr.get_value(enc_section, enc_option,
                                     cls.default_encoding)

        author = Actor(author_name, author_email)
        committer = Actor(committer_name, committer_email)

        # if the tree is no object, make sure we create one - otherwise
        # the created commit object is invalid
        if isinstance(tree, str):
            tree = repo.tree(tree)
        # END tree conversion

        # CREATE NEW COMMIT
        new_commit = cls(repo, cls.NULL_BIN_SHA, tree, author, author_time,
                         author_offset, committer, committer_time,
                         committer_offset, message, parent_commits,
                         conf_encoding)

        stream = StringIO()
        new_commit._serialize(stream)
        streamlen = stream.tell()
        stream.seek(0)

        istream = repo.odb.store(IStream(cls.type, streamlen, stream))
        new_commit.binsha = istream.binsha

        if head:
            try:
                repo.head.commit = new_commit
            except ValueError:
                # head is not yet set to the ref our HEAD points to
                # Happens on first commit
                import git.refs
                master = git.refs.Head.create(repo,
                                              repo.head.ref,
                                              commit=new_commit)
                repo.head.reference = master
            # END handle empty repositories
        # END advance head handling

        return new_commit
Exemplo n.º 4
0
 def __init__(self, peerid, slog):
     self.peerid = peerid
     Actor.__init__(self, repr(peerid), slog)
Exemplo n.º 5
0
 def __init__(self, name, clock):
     StatusLog.__init__(self, clock)
     Actor.__init__(self, name, self)