Module xalt_stack
[hide private]
[frames] | no frames]

Source Code for Module xalt_stack

 1  #!/usr/bin/env python 
 2  # -*- python -*- 
 3   
 4  #----------------------------------------------------------------------- 
 5  # XALT: A tool that tracks users jobs and environments on a cluster. 
 6  # Copyright (C) 2013-2014 University of Texas at Austin 
 7  # Copyright (C) 2013-2014 University of Tennessee 
 8  #  
 9  # This library is free software; you can redistribute it and/or modify 
10  # it under the terms of the GNU Lesser General Public License as 
11  # published by the Free Software Foundation; either version 2.1 of  
12  # the License, or (at your option) any later version.  
13  # 
14  # This library is distributed in the hope that it will be useful, 
15  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
17  # Lesser  General Public License for more details.  
18  # 
19  # You should have received a copy of the GNU Lesser General Public 
20  # License along with this library; if not, write to the Free 
21  # Software Foundation, Inc., 59 Temple Place, Suite 330, 
22  # Boston, MA 02111-1307 USA 
23  #----------------------------------------------------------------------- 
24   
25  from __future__ import print_function 
26  import os, sys, re 
27 -class Stack(object):
28 """ Basic stack class """
29 - def __init__(self):
30 self.__items = []
31 32
33 - def push(self,item):
34 """ method for pushing an item on a stack """ 35 self.__items.append(item)
36
37 - def pop(self):
38 """ method for popping an item from a stack """ 39 v = self.__items.pop() 40 return v
41
42 - def isEmpty(self):
43 """ method to check whether the stack is empty or not """ 44 return (self.__items == [])
45
46 - def contents(self):
47 """ return the contents of the stack as a single text block. """ 48 return "\n".join(self.__items)
49 50 51 pstack = Stack()
52 -def main():
53 pstack.push("A") 54 pstack.push("B") 55 56 pstack.push("C1") 57 pstack.pop() 58 59 pstack.push("C2") 60 pstack.push("D2") 61 pstack.pop() 62 pstack.pop() 63 64 print(pstack.contents())
65 66 67 68 if ( __name__ == '__main__'): main() 69