Esempio n. 1
0
    def create(self, args):
        """
        Create the skewer that will hold the food.
        :param args: a string containing the size to create
        :return: None
        """

        try:
            # make sure the size is valid
            if len(args) == 0 or int(args[0]) < 1:
                raise SkewerException("Skewer size must be greater than 0")

            size = int(args[0])

            # force close a pre-existing skewer
            if self.skewer != None:
                self.skewer.close()

            self.skewer = Skewer(size)
            print("Skewer created.")
        except SkewerException as e:
            print(e)
            self.skewer = None
        except Exception as e:
            sys.stderr.write(e)
            self.usage()
            return
Esempio n. 2
0
def kebab_create_skewer(kebab, args):
    """
    Create the skewer that will hold the food.
    :param kebab (Kebab): this kebab
    :param args: a string containing the size to create
    :return: None
    """
    try:
        # make sure the capacity is valid
        if len(args) == 0 or int(args[0]) < 1:
            raise SkewerException("Skewer capacity must be greater than 0")

        # convert it from string to int
        capacity = int(args[0])

        # force close a pre-existing skewer
        if kebab.skewer is not None:
            skewer_close(kebab.skewer)

        # now make the skewer
        kebab.skewer = skewer_create(capacity)
        print("Skewer created.")
    except SkewerException as e:
        print(e)
        kebab.skewer = None
    except Exception as e:
        sys.stderr.write(e)
        kebab_usage()
        return
Esempio n. 3
0
 def front(self):
     """
     Gets the name of the front item on the skewer.
     :exception SkewerException: no item was on the skewer
     :return the name of the food item (string) on the front
     """
     
     if not self.top or self.size() == 0: 
         raise SkewerException("Cannot get item from an empty skewer!")
     return self.top.get_item().name
Esempio n. 4
0
def skewer_front(skewer):
    """
    Gets the name of the front item on the skewer.
    :param skewer (Skewer): this skewer
    :exception SkewerException: no item was on the skewer
    :return the name of the food item (string) on the front
    """
    if skewer.top is None:
        raise SkewerException("Cannot get item from an empty skewer!")
    return spot_name(skewer.top)
Esempio n. 5
0
def skewer_create(capacity):
    """
    Create a new empty skewer.
    :param capacity (int): the maximum number of items it can hold
    :exception SkewerException: a capacity less than 1 was specified.
    """
    if capacity < 1:
        raise SkewerException("Cannot create skewer!")

    return Skewer(top=None, capacity=capacity, ui=SkewerUI(capacity))
Esempio n. 6
0
 def remove(self):
     """
     Remove the front item from the skewer.
     :exception: SkewerException: no item was on the skewer
     :return None
     """
     
     if not self.top or self.size() == 0:
         raise SkewerException("Cannot get item from an empty skewer!")
     self.ui.remove()
     self.top = self.top.next
Esempio n. 7
0
def skewer_remove(skewer):
    """
    Remove the front item from the skewer.
    :param skewer (Skewer): this skewer
    :exception: SkewerException: no item was on the skewer
    :return None
    """
    if skewer.top is None:
        raise SkewerException("Cannot get item from an empty skewer!")

    skewer.ui.remove()
    skewer.top = skewer.top.next
Esempio n. 8
0
 def add(self, name):
     """
     Add a food item to the skewer
     :param name: the string name of the food item
     :exception SkewerException: item could not be added.
     :return None
     """
     
     if not self.top or self.top.size() < self.cap:
         self.top = KebabSpot( Food(name), self.top )
         self.ui.add(self.top)
     else:
         raise SkewerException("Cannot add item to a full skewer!")
Esempio n. 9
0
    def __init__(self, capacity):
        """
        Construct a Skewer instance.
        :param capacity: the maximum number of items it can hold
        :exception SkewerException: a capacity less than 1 was specified.
        """
        
        if capacity < 1:
            raise SkewerException("Cannot create skewer!")

        self.top = None
        self.cap = capacity
        self.ui = SkewerUI(self.cap)
Esempio n. 10
0
def skewer_add(skewer, name):
    """
    Add a food item to the skewer
    :param skewer (Skewer): this skewer
    :param name (str): the string name of the food item
    :exception SkewerException: item could not be added.
    :return None
    """
    if skewer.top is None or spot_size(skewer.top) < skewer.capacity:
        skewer.top = spot_create(food_create(name), skewer.top)
        skewer.ui.add(skewer.top)
    else:
        raise SkewerException("Cannot add item to a full skewer!")