Skip to content

Commit 54e530c

Browse files
committed
prints host name via -h
1 parent 5739472 commit 54e530c

2 files changed

Lines changed: 37 additions & 14 deletions

File tree

ipython_magic/watermark.ipynb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:0b017c7b1bd605534beb62287fd7916407f3782284c44ee02093a73e4a9896a8"
4+
"signature": "sha256:9c5a9f291a08a3d3ea3459178cdaf482808d62014c15f3542116e57632436f7e"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -198,6 +198,7 @@
198198
" -p PACKAGES, --packages PACKAGES\n",
199199
" prints versions of specified Python modules and\n",
200200
" packages\n",
201+
" -h, --hostname prints the host name\n",
201202
" -m, --machine prints system and machine info\n",
202203
"</pre>"
203204
]
@@ -432,7 +433,14 @@
432433
]
433434
}
434435
],
435-
"prompt_number": 12
436+
"prompt_number": 3
437+
},
438+
{
439+
"cell_type": "markdown",
440+
"metadata": {},
441+
"source": [
442+
"<br>"
443+
]
436444
}
437445
],
438446
"metadata": {}

ipython_magic/watermark.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Sebastian Raschka 2014
33
44
watermark.py
5-
version 1.0.2
5+
version 1.0.3
66
77
88
IPython magic function to print date/time stamps and various system information.
@@ -18,26 +18,33 @@
1818
%watermark
1919
2020
optional arguments:
21-
-d, --date prints current date
22-
-n, --datename prints date with abbrv. day and month names
23-
-t, --time prints current time
24-
-z, --timezone appends the local time zone
25-
-u, --updated appends a string "Last updated: "
26-
-c CUSTOM_TIME, --custom_time CUSTOM_TIME
21+
-a AUTHOR, --author AUTHOR
22+
prints author name
23+
-e AUTHOR_EMAIL, --author_email AUTHOR_EMAIL
24+
prints author name and link to email address
25+
-d, --date prints current date
26+
-n, --datename prints date with abbrv. day and month names
27+
-t, --time prints current time
28+
-z, --timezone appends the local time zone
29+
-u, --updated appends a string "Last updated: "
30+
-c CUSTOM_TIME, --custom_time CUSTOM_TIME
2731
prints a valid strftime() string
28-
-v, --python prints Python and IPython version
29-
-p PACKAGES, --packages PACKAGES
32+
-v, --python prints Python and IPython version
33+
-p PACKAGES, --packages PACKAGES
3034
prints versions of specified Python modules and
3135
packages
32-
-m, --machine prints system and machine info
33-
36+
-h, --hostname prints the host name
37+
-m, --machine prints system and machine info
38+
39+
3440
Examples:
3541
3642
%watermark -d -t
3743
3844
"""
3945
import platform
4046
from time import strftime
47+
from socket import gethostname
4148
from pkg_resources import get_distribution
4249
from multiprocessing import cpu_count
4350

@@ -62,14 +69,15 @@ class WaterMark(Magics):
6269
@argument('-c', '--custom_time', type=str, help='prints a valid strftime() string')
6370
@argument('-v', '--python', action='store_true', help='prints Python and IPython version')
6471
@argument('-p', '--packages', type=str, help='prints versions of specified Python modules and packages')
72+
@argument('-h', '--hostname', action='store_true', help='prints the host name')
6573
@argument('-m', '--machine', action='store_true', help='prints system and machine info')
6674
@line_magic
6775
def watermark(self, line):
6876
"""
6977
IPython magic function to print date/time stamps
7078
and various system information.
7179
72-
watermark version 1.0.2
80+
watermark version 1.0.3
7381
7482
"""
7583
self.out = ''
@@ -101,6 +109,13 @@ def watermark(self, line):
101109
self._get_packages(args.packages)
102110
if args.machine:
103111
self._get_sysinfo()
112+
if args.hostname:
113+
space = ''
114+
if args.machine:
115+
space = ' '
116+
self.out += '\nhost name%s: %s' %(space, gethostname())
117+
118+
104119

105120
print(self.out)
106121

0 commit comments

Comments
 (0)