fancytools.utils package¶
Submodules¶
fancytools.utils.Logger module¶
-
class
fancytools.utils.Logger.Logger(stdout, logfile)[source]¶ writes into log-file and on screen at the same time
>>> import sys >>> import os >>> log_file = file('my_logfile.log', 'w') >>> logger = Logger(sys.stdout, log_file) >>> sys.stdout = logger >>> sys.stderr = logger
every output will also be saved in file, e.g. >>> print ‘hello world’ #every output will also be saved in file hello world
to prove this we read the log file >>> logger.close() >>> log_file = open(‘my_logfile.log’, ‘r’)
>>> logcontent = log_file.read() >>> 'hello world' in logcontent True >>> os.remove('my_logfile.log')
fancytools.utils.StreamSignal module¶
-
class
fancytools.utils.StreamSignal.StreamSignal(stdout='out', parent=None)[source]¶ Bases:
PyQt4.QtCore.QObjectcreate a connectable stdout instance
to write to the shell and a log file:
>>> import tempfile >>> import os
>>> streamOut = StreamSignal('out') >>> streamErr = StreamSignal('err')
create a temporary file
>>> (file_id, log_file) = tempfile.mkstemp() >>> l = open(log_file, 'w')
connect the stream output to the files-write method
>>> streamOut.message.connect(l.write) >>> print 'hello world' hello world >>> l.close()
check whether the printed message is in the file
>>> l = open(log_file, 'r') >>> 'hello world' in l.read() True >>> l.close()
-
message¶
-
fancytools.utils.countLines module¶
fancytools.utils.formatedTime module¶
fancytools.utils.incrementName module¶
-
fancytools.utils.incrementName.incrementName(nameList, name)[source]¶ return a name that is unique in a given nameList through attaching a number to it
>>> l = []
now we will add 3xfoo 2xbar and one klaus to our list:
>>> l.append( incrementName(l,'foo') ) >>> l.append( incrementName(l,'bar') ) >>> l.append( incrementName(l,'foo') ) >>> l.append( incrementName(l,'foo') ) >>> l.append( incrementName(l,'bar') ) >>> l.append( incrementName(l,'klaus') )
>>> print sorted(l) ['bar', 'bar2', 'foo', 'foo2', 'foo3', 'klaus']
fancytools.utils.statusBar module¶
-
fancytools.utils.statusBar.statusBar(step, total, bar_len=20, onlyReturn=False)[source]¶ print a ASCI-art statusbar of variable length e.g.showing 25%:
>>> step = 25 >>> total = 100
>>> print statusBar(step, total, bar_len=20, onlyReturn=True)
[=====o—————]25%
as default onlyReturn is set to False in this case the last printed line would be flushed every time when the statusbar is called to create a the effect of one moving bar