prints host name via -h

This commit is contained in:
rasbt 2014-06-28 16:35:39 -04:00
parent 5739472a48
commit 54e530cf5b
2 changed files with 37 additions and 14 deletions

View File

@ -1,7 +1,7 @@
{
"metadata": {
"name": "",
"signature": "sha256:0b017c7b1bd605534beb62287fd7916407f3782284c44ee02093a73e4a9896a8"
"signature": "sha256:9c5a9f291a08a3d3ea3459178cdaf482808d62014c15f3542116e57632436f7e"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -198,6 +198,7 @@
" -p PACKAGES, --packages PACKAGES\n",
" prints versions of specified Python modules and\n",
" packages\n",
" -h, --hostname prints the host name\n",
" -m, --machine prints system and machine info\n",
"</pre>"
]
@ -432,7 +433,14 @@
]
}
],
"prompt_number": 12
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<br>"
]
}
],
"metadata": {}

View File

@ -2,7 +2,7 @@
Sebastian Raschka 2014
watermark.py
version 1.0.2
version 1.0.3
IPython magic function to print date/time stamps and various system information.
@ -18,6 +18,10 @@ Usage:
%watermark
optional arguments:
-a AUTHOR, --author AUTHOR
prints author name
-e AUTHOR_EMAIL, --author_email AUTHOR_EMAIL
prints author name and link to email address
-d, --date prints current date
-n, --datename prints date with abbrv. day and month names
-t, --time prints current time
@ -29,8 +33,10 @@ Usage:
-p PACKAGES, --packages PACKAGES
prints versions of specified Python modules and
packages
-h, --hostname prints the host name
-m, --machine prints system and machine info
Examples:
%watermark -d -t
@ -38,6 +44,7 @@ Examples:
"""
import platform
from time import strftime
from socket import gethostname
from pkg_resources import get_distribution
from multiprocessing import cpu_count
@ -62,6 +69,7 @@ class WaterMark(Magics):
@argument('-c', '--custom_time', type=str, help='prints a valid strftime() string')
@argument('-v', '--python', action='store_true', help='prints Python and IPython version')
@argument('-p', '--packages', type=str, help='prints versions of specified Python modules and packages')
@argument('-h', '--hostname', action='store_true', help='prints the host name')
@argument('-m', '--machine', action='store_true', help='prints system and machine info')
@line_magic
def watermark(self, line):
@ -69,7 +77,7 @@ class WaterMark(Magics):
IPython magic function to print date/time stamps
and various system information.
watermark version 1.0.2
watermark version 1.0.3
"""
self.out = ''
@ -101,6 +109,13 @@ class WaterMark(Magics):
self._get_packages(args.packages)
if args.machine:
self._get_sysinfo()
if args.hostname:
space = ''
if args.machine:
space = ' '
self.out += '\nhost name%s: %s' %(space, gethostname())
print(self.out)