Skip to content

Instantly share code, notes, and snippets.

@mattdeboard
Created January 19, 2017 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattdeboard/d5b6aecb1d47abf49b0df2cbabd98b8e to your computer and use it in GitHub Desktop.
Save mattdeboard/d5b6aecb1d47abf49b0df2cbabd98b8e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import random
class Follower:
def __init__(self, starting_location, current_victim=None):
# `starting_location` is a string representing a file system path.
self.location = starting_location
self.current_victim = current_victim
self.victims = []
if self.current_victim is not None:
self.victims.append(self.current_victim)
def kill(self):
self.current_victim.dead = True
try:
self.current_victim = self.victims.pop()
except IndexError:
raise IndexError("We're all out of victims!")
class Victim:
def __init__(self, starting_location):
# `starting_location` is a string representing a file system path.
self.location = starting_location
self.dead = False
def move(self):
"""Move to a random location in the file system."""
pass
def infect(self):
return Victim(self.location)
def random_directory(root):
return random.choice(os.listdir(root))
if __name__ == '__main__':
first_victim = Victim(random_directory('~'))
follower = Follower(random_directory('~'), first_victim)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment