Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Updates, preparing for 0.5.9
Browse files Browse the repository at this point in the history
  • Loading branch information
dagwieers committed Mar 28, 2005
1 parent 0f6c50c commit dca0c53
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 30 deletions.
5 changes: 4 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
* 0.5.9
- Make default list total lists (cpu, disk, net)
- Fix clearline ANSI to work on (Debian?) rxvt (Joshua Rodman)
- Fix clearline ANSI to work on older (Debian?) rxvt (Joshua Rodman)
- Improved color/vt100 terminal capabilities logic (Charles Lepple)
- Finally use curses for some of the terminal capabilities logic
- Improvement to non-tty handling for intermediate updates
- Small fix to handle the edge of the counters better
- Prevent keyboard input/echo when running

* 0.5.8
- Added user stats using python-utmp
Expand Down
58 changes: 41 additions & 17 deletions dstat
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
### Copyright 2004 Dag Wieers <dag@wieers.com>

import sys

if sys.version_info < (2, 2):
sys.exit('error: Python 2.2 or later required, try dstat15 instead')

from __future__ import generators
import fcntl, struct, types
import os, sys, re, getopt, time, termios
import os, re, getopt, time, types
import ConfigParser, urlparse, signal, resource
import curses, termios

VERSION = '0.5.9'

Expand Down Expand Up @@ -1256,17 +1261,20 @@ def die(ret, str):
def getwinsize():
if op.nolimit:
return 1024, 1024
# curses.wrapper(lambda s:curses.setupterm())
# return curses.wrapper(lambda s:curses.tigetnum('lines')), curses.wrapper(lambda s:curses.tigetnum('cols'))
try:
s = struct.pack('HHHH', 0, 0, 0, 0)
x = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, s)
return struct.unpack('HHHH', x)[:2]
curses.setupterm()
return curses.tigetnum('lines'), curses.tigetnum('cols')
except:
try:
return int(os.environ['LINES']), int(os.environ['COLUMNS'])
import fcntl, struct, termios
s = struct.pack('HHHH', 0, 0, 0, 0)
x = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, s)
return struct.unpack('HHHH', x)[:2]
except:
return 25, 80
try:
return int(os.environ['LINES']), int(os.environ['COLUMNS'])
except:
return 25, 80

def getcpunr():
cpunr = -1
Expand Down Expand Up @@ -1347,9 +1355,7 @@ def main():

### Check terminal capabilities
if sys.stdout.isatty():
# import curses
# if not curses.wrapper(lambda s:curses.has_colors()):
if os.environ.get('TERM', None) not in ('ansi', 'gnome', 'linux', 'rxvt', 'screen', 'screen-w', 'xterm', 'xterm-color'):
if curses.tigetnum('colors') < 0:
op.color = False
else:
op.color = False
Expand Down Expand Up @@ -1378,10 +1384,6 @@ def main():
if not totlist:
die(8, 'None of the stats you selected are available.')

if not op.nolimit:
if linewidth > cols:
print 'Screen width too small, trimming output.'

### FIXME: Get rid of socket()
if op.output:
import socket
Expand Down Expand Up @@ -1417,6 +1419,9 @@ def main():
if curwidth + o.varwidth() + 1 <= cols:
vislist.append(o)
curwidth = curwidth + o.varwidth() + 1
elif vislist == totlist[:-1] and curwidth + o.varwidth() <= cols:
vislist.append(o)
curwidth = curwidth + o.varwidth() + 1

### Check when to display the header
if op.header:
Expand All @@ -1426,6 +1431,8 @@ def main():
showheader = True

if showheader:
if loop == 0 and totlist != vislist:
print 'Screen width too small, trimming output.'
showheader = False
showtitle(1, totlist, vislist, ansi['darkblue'] + char['space'], ansi['darkblue'] + char['gt'])
showtitle(2, totlist, vislist, ansi['silver'] + char['pipe'], ansi['darkblue'] + char['gt'])
Expand Down Expand Up @@ -1474,6 +1481,15 @@ def main():
### Unbuffered sys.stdout
sys.stdout = os.fdopen(1, 'w', 0)

curses.setupterm()

### Prevent keyboard input
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
new[3] = new[3] & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSADRAIN, new)

### Workaround for python > 2.1 and < 2.3
def enumerate(sequence):
index = 0
Expand All @@ -1489,14 +1505,22 @@ if __name__ == '__main__':
main()
except KeyboardInterrupt, e:
signal.signal(signal.SIGALRM, signal.SIG_DFL)
termios.tcsetattr(fd, termios.TCSADRAIN, old)
print ansi['reset']
except OSError, e:
signal.signal(signal.SIGALRM, signal.SIG_DFL)
termios.tcsetattr(fd, termios.TCSADRAIN, old)
# print e.errno
print
print ansi['reset'] + 'OSError: %s' %e
print ansi['reset'] + 'OSError: %s' % e
sys.exit(7)
# except Exception, e:
# signal.signal(signal.SIGALRM, signal.SIG_DFL)
# termios.tcsetattr(fd, termios.TCSADRAIN, old)
# raise e

signal.signal(signal.SIGALRM, signal.SIG_DFL)
termios.tcsetattr(fd, termios.TCSADRAIN, old)
sys.exit(0)

# vim:ts=4:sw=4
37 changes: 25 additions & 12 deletions dstat15
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
### Copyright 2004 Dag Wieers <dag@wieers.com>

import sys

#if sys.version_info < (1, 5):
# sys.exit('error: Python 1.5 or later required')

#from __future__ import generators
import fcntl, struct, types, string
import os, sys, re, getopt, time, termios
import os, re, getopt, time, types, string
import ConfigParser, urlparse, signal, resource
import curses, termios

VERSION = '0.5.9'

Expand Down Expand Up @@ -1256,17 +1261,20 @@ def die(ret, str):
def getwinsize():
if op.nolimit:
return 1024, 1024
# curses.wrapper(lambda s:curses.setupterm())
# return curses.wrapper(lambda s:curses.tigetnum('lines')), curses.wrapper(lambda s:curses.tigetnum('cols'))
try:
s = struct.pack('HHHH', 0, 0, 0, 0)
x = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, s)
return struct.unpack('HHHH', x)[:2]
curses.setupterm()
return curses.tigetnum('lines'), curses.tigetnum('cols')
except:
try:
return int(os.environ['LINES']), int(os.environ['COLUMNS'])
import fcntl, struct, termios
s = struct.pack('HHHH', 0, 0, 0, 0)
x = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, s)
return struct.unpack('HHHH', x)[:2]
except:
return 25, 80
try:
return int(os.environ['LINES']), int(os.environ['COLUMNS'])
except:
return 25, 80

def getcpunr():
cpunr = -1
Expand Down Expand Up @@ -1347,8 +1355,7 @@ def main():

### Check terminal capabilities
if sys.stdout.isatty():
# import curses
# if not curses.wrapper(lambda s:curses.has_colors()):
# if curses.tigetnum('colors') < 0:
if os.environ.get('TERM', None) not in ('ansi', 'gnome', 'linux', 'rxvt', 'screen', 'screen-w', 'xterm', 'xterm-color'):
op.color = False
else:
Expand Down Expand Up @@ -1417,6 +1424,9 @@ def main():
if curwidth + o.varwidth() + 1 <= cols:
vislist.append(o)
curwidth = curwidth + o.varwidth() + 1
elif vislist == totlist[:-1] and curwidth + o.varwidth() <= cols:
vislist.append(o)
curwidth = curwidth + o.varwidth() + 1

### Check when to display the header
if op.header:
Expand All @@ -1426,6 +1436,8 @@ def main():
showheader = True

if showheader:
if loop == 0 and totlist != vislist:
print 'Screen width too small, trimming output.'
showheader = False
showtitle(1, totlist, vislist, ansi['darkblue'] + char['space'], ansi['darkblue'] + char['gt'])
showtitle(2, totlist, vislist, ansi['silver'] + char['pipe'], ansi['darkblue'] + char['gt'])
Expand Down Expand Up @@ -1506,9 +1518,10 @@ if __name__ == '__main__':
signal.signal(signal.SIGALRM, signal.SIG_DFL)
# print e.errno
print
print ansi['reset'] + 'OSError: %s' %e
print ansi['reset'] + 'OSError: %s' % e
sys.exit(7)

signal.signal(signal.SIGALRM, signal.SIG_DFL)
sys.exit(0)

# vim:ts=4:sw=4

0 comments on commit dca0c53

Please sign in to comment.