Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: third_party/pexpect/examples/df.py

Issue 1398903002: Add third_party/pexpect (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@end-to-end-test
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/pexpect/examples/chess3.py ('k') | third_party/pexpect/examples/ftp.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3 '''This collects filesystem capacity info using the 'df' command. Tuples of
4 filesystem name and percentage are stored in a list. A simple report is
5 printed. Filesystems over 95% capacity are highlighted. Note that this does not
6 parse filesystem names after the first space, so names with spaces in them will
7 be truncated. This will produce ambiguous results for automount filesystems on
8 Apple OSX.
9
10 PEXPECT LICENSE
11
12 This license is approved by the OSI and FSF as GPL-compatible.
13 http://opensource.org/licenses/isc-license.txt
14
15 Copyright (c) 2012, Noah Spurrier <noah@noah.org>
16 PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
17 PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
18 COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
19 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
20 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
21 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
22 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
23 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
24 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
25 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26
27 '''
28
29 from __future__ import print_function
30
31 from __future__ import absolute_import
32
33 import pexpect
34
35 child = pexpect.spawn ('df')
36
37 # parse 'df' output into a list.
38 pattern = "\n(\S+).*?([0-9]+)%"
39 filesystem_list = []
40 for dummy in range (0, 1000):
41 i = child.expect ([pattern, pexpect.EOF])
42 if i == 0:
43 filesystem_list.append (child.match.groups())
44 else:
45 break
46
47 # Print report
48 print()
49 for m in filesystem_list:
50 s = "Filesystem %s is at %s%%" % (m[0], m[1])
51 # highlight filesystems over 95% capacity
52 if int(m[1]) > 95:
53 s = '! ' + s
54 else:
55 s = ' ' + s
56 print(s)
57
OLDNEW
« no previous file with comments | « third_party/pexpect/examples/chess3.py ('k') | third_party/pexpect/examples/ftp.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698