X-Git-Url: https://git.sthu.org/?p=sitarba.git;a=blobdiff_plain;f=shbackup;h=0cfc4c74f3a03f5a0d2c846ef7c191f11600770f;hp=977fb5cd35403ccdf4fc41cc172369fa598d0b2d;hb=8a63842725558d8877a933bbd1f5312bb8e6f195;hpb=8bc0914cc0e9ebe9e42c97ce6d85f399e4a2f4da diff --git a/shbackup b/shbackup index 977fb5c..0cfc4c7 100755 --- a/shbackup +++ b/shbackup @@ -57,8 +57,14 @@ class Backup: ", mode: " + self.mode + "]" def colAlignedString(self): - return "%16s %8s %4s" % ( \ - self.date.strftime("%Y-%m-%d %H:%M"), self.epoch, self.mode) + age = datetime.datetime.now() - self.date + total_hours = age.total_seconds()/3600 + if total_hours <= 48: + agestr = "(%s h)" % int(total_hours) + else: + agestr = "(%s d)" % age.days + return "%16s %7s %8s %4s" % ( \ + self.date.strftime("%Y-%m-%d %H:%M"), agestr, self.epoch, self.mode) @staticmethod def getDirName(date, epoch, mode): @@ -286,28 +292,14 @@ class BackupManager: fl = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK) - def readlineNonBlocking(stream): - """Read a line nonblocking. Returns b'' if nothing read.""" - try: - return stream.readline() - except: - return b'' - pass - - # Read stdout and stderr of tarp errmsg = b"" while tarp.poll() == None: rd,wr,ex = select.select([tarp.stdout, tarp.stderr], [], [], 0.05) - if tarp.stdout in rd: - l = readlineNonBlocking(tarp.stdout) - if l != b"": - logging.debug(l[:-1].decode()) - + logging.debug( tarp.stdout.readline()[:-1].decode() ) if tarp.stderr in rd: - errmsg += readlineNonBlocking(tarp.stderr) - + errmsg += tarp.stderr.read() # Get the remainging output of tarp for l in tarp.stdout.readlines():