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')
close()[source]

Does this work or not?

write(text)[source]

fancytools.utils.StreamSignal module

class fancytools.utils.StreamSignal.StreamSignal(stdout='out', parent=None)[source]

Bases: PyQt4.QtCore.QObject

create 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()
flush()[source]
message
setWriteToShell(writeToShell=True)[source]

connect sysout to the qtSignal

write(message)[source]

fancytools.utils.countLines module

fancytools.utils.countLines.countLines(paths, exclude_files_containing=[], exclude_folders_containing=[], exclude_blank_lines=True, exclude_commented_lines=True, count_only_py_files=True)[source]

count and return lines of all *.py files in the given directory/-ies

fancytools.utils.formatedTime module

fancytools.utils.formatedTime.formatedTime(ms)[source]

convert milliseconds in a human readable time

>>> formatedTime(60e3)
'1m'
>>> formatedTime(1000e3)
'16m 40s'
>>> formatedTime(200000123)
'2d 7h 33m 20.123s'

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