8 from conf
import config
18 # output: => Requesting ip...
22 "Attempted to display new pending message without closing previous"
24 msg
= "=> %s..." % msg
31 # output: (=> Requesting ip...) done
32 def result(self
, msg
):
35 "Attempted to display result of action without pending message"
39 self
.log("%s %s" % (self
.pending
, msg
))
41 msg
= "%s %s" % (self
.pending
, msg
)
42 print "\r%s" % msg
# workaround for space at the start of the line
46 def display(self
, msg
):
47 if self
.pending
and not self
.dirty
:
53 def err(self
, msg
, log
=True):
54 msg
= "Erratum: %s" % msg
57 print >>sys
.stderr
, "\n%s" % msg
58 else: print >>sys
.stderr
, msg
65 if os
.path
.isfile(config
.logfile
) and \
66 os
.path
.getsize(config
.logfile
) > config
.logfile_size
:
67 shutil
.move(config
.logfile
, "%s.0" % config
.logfile
)
69 t
= time
.strftime("%d.%m.%y %H:%M:%S", time
.gmtime())
71 f
= open(config
.logfile
, 'a')
72 if msg
[-1:] != '\n': msg
+= '\n'
73 f
.write("[%s] %s" % (t
, msg
))
76 self
.err("Could not write to logfile %s" % config
.logfile
, log
=False)
78 def mute(self
, quiet
=False):
81 self
.display("*** Halting output until we need to obtain ip again")
82 sys
.stdin
= open("/dev/null", 'r')
83 sys
.stdout
= open("/dev/null", 'w')
84 sys
.stderr
= open("/dev/null", 'w')
87 def unmute(self
, quiet
=False):
88 if not self
.muted
: return
89 sys
.stdin
= sys
.__stdin
__
90 sys
.stdout
= sys
.__stdout
__
91 sys
.stderr
= sys
.__stderr
__
92 if not quiet
: self
.display("*** Resuming output")