Package lib :: Package text :: Module progress
[hide private]
[frames] | no frames]

Source Code for Module lib.text.progress

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2014 Edward d'Auvergne                                        # 
 4  #                                                                             # 
 5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
 6  #                                                                             # 
 7  # This program is free software: you can redistribute it and/or modify        # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation, either version 3 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # This program is distributed in the hope that it will be useful,             # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
19  #                                                                             # 
20  ############################################################################### 
21   
22  # Module docstring. 
23  """Text based progress meters.""" 
24   
25  # Python module imports. 
26  import locale 
27  import sys 
28   
29   
30 -def progress_meter(i, a=250, b=10000, file=sys.stderr):
31 """A simple progress write out (which defaults to the terminal STDERR). 32 33 @param i: The current iteration. 34 @type i: int 35 @keyword a: The step size for spinning the spinner. 36 @type a: int 37 @keyword b: The step size for printing out the progress. 38 @type b: int 39 @keyword file: The file object to write the output to. 40 @type file: file object 41 """ 42 43 # The spinner characters. 44 chars = ['-', '\\', '|', '/'] 45 46 # A spinner. 47 if i % a == 0: 48 file.write('\b%s' % chars[i%4]) 49 if hasattr(file, 'flush'): 50 file.flush() 51 52 # Dump the progress. 53 if i % b == 0: 54 num = locale.format("%d", i, grouping=True) 55 file.write('\b%12s\n' % num)
56