mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-23 20:11:13 +00:00
Git commit hash arg
This commit is contained in:
parent
fbe7759fd7
commit
1bbf720e69
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:72529e8db6a991fa9a1ce25da1f89e9aa64dd9fdffdcdbef3ae0f18098f5ab0a"
|
||||
"signature": "sha256:f60eef12fdb981a16a1ac0578a3dcf7377d991866b8528653a69fd33bf2ba8f9"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -81,6 +81,26 @@
|
|||
],
|
||||
"prompt_number": 1
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"%install_ext ./watermark.py"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"Installed watermark.py. To use it, type:\n",
|
||||
" %load_ext watermark\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 1
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
@ -153,20 +173,18 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<pre>%watermark [-a AUTHOR] [-e AUTHOR_EMAIL] [-d] [-n] [-t] [-z] [-u]\n",
|
||||
" [-c CUSTOM_TIME] [-v] [-p PACKAGES] [-m]\n",
|
||||
"<pre> %watermark [-a AUTHOR] [-d] [-n] [-t] [-z] [-u] [-c CUSTOM_TIME] [-v]\n",
|
||||
" [-p PACKAGES] [-h] [-m] [-g]\n",
|
||||
"\n",
|
||||
" \n",
|
||||
"IPython magic function to print date/time stamps \n",
|
||||
"and various system information.\n",
|
||||
"\n",
|
||||
"watermark version 1.0.2\n",
|
||||
"watermark version 1.1.0\n",
|
||||
"\n",
|
||||
"optional arguments:\n",
|
||||
" -a AUTHOR, --author AUTHOR\n",
|
||||
" prints author name\n",
|
||||
" -e AUTHOR_EMAIL, --author_email AUTHOR_EMAIL\n",
|
||||
" prints author name and link to email address\n",
|
||||
" -d, --date prints current date\n",
|
||||
" -n, --datename prints date with abbrv. day and month names\n",
|
||||
" -t, --time prints current time\n",
|
||||
|
@ -180,6 +198,7 @@
|
|||
" packages\n",
|
||||
" -h, --hostname prints the host name\n",
|
||||
" -m, --machine prints system and machine info\n",
|
||||
" -g, --githash prints current Git commit hash\n",
|
||||
"</pre>"
|
||||
]
|
||||
},
|
||||
|
@ -212,7 +231,7 @@
|
|||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"28/06/2014 16:35:11\n",
|
||||
"29/06/2014 01:19:10\n",
|
||||
"\n",
|
||||
"CPython 3.4.1\n",
|
||||
"IPython 2.1.0\n",
|
||||
|
@ -227,7 +246,7 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 4
|
||||
"prompt_number": 3
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -249,11 +268,11 @@
|
|||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"28/06/2014 16:35:12 \n"
|
||||
"29/06/2014 01:19:11 \n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 5
|
||||
"prompt_number": 4
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -275,11 +294,11 @@
|
|||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"Last updated: Sat Jun 35 2014 16:35:12 EDT\n"
|
||||
"Last updated: Sun Jun 19 2014 01:19:12 EDT\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 6
|
||||
"prompt_number": 5
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -306,7 +325,7 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 7
|
||||
"prompt_number": 6
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -338,7 +357,7 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 8
|
||||
"prompt_number": 7
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -376,7 +395,7 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 9
|
||||
"prompt_number": 8
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
@ -389,7 +408,7 @@
|
|||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"%watermark -a \"John Doe\" -d -v -m "
|
||||
"%watermark -a \"John Doe\" -d -v -m -g"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
@ -398,7 +417,7 @@
|
|||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"John Doe 28/06/2014 \n",
|
||||
"John Doe 29/06/2014 01:20:48 EDT\n",
|
||||
"\n",
|
||||
"CPython 3.4.1\n",
|
||||
"IPython 2.1.0\n",
|
||||
|
@ -409,11 +428,12 @@
|
|||
"machine : x86_64\n",
|
||||
"processor : i386\n",
|
||||
"CPU cores : 2\n",
|
||||
"interpreter: 64bit\n"
|
||||
"interpreter: 64bit\n",
|
||||
"Git hash : fbe7759fd7e0298bf0bd05ea4aac01b87aa8ed25\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 10
|
||||
"prompt_number": 16
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Sebastian Raschka 2014
|
||||
|
||||
watermark.py
|
||||
version 1.0.3
|
||||
version 1.1.0
|
||||
|
||||
|
||||
IPython magic function to print date/time stamps and various system information.
|
||||
|
@ -18,10 +18,9 @@ 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
|
||||
|
@ -35,6 +34,7 @@ Usage:
|
|||
packages
|
||||
-h, --hostname prints the host name
|
||||
-m, --machine prints system and machine info
|
||||
-g, --githash prints current Git commit hash
|
||||
|
||||
|
||||
Examples:
|
||||
|
@ -43,6 +43,7 @@ Examples:
|
|||
|
||||
"""
|
||||
import platform
|
||||
import subprocess
|
||||
from time import strftime
|
||||
from socket import gethostname
|
||||
from pkg_resources import get_distribution
|
||||
|
@ -71,13 +72,14 @@ class WaterMark(Magics):
|
|||
@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')
|
||||
@argument('-g', '--githash', action='store_true', help='prints current Git commit hash')
|
||||
@line_magic
|
||||
def watermark(self, line):
|
||||
"""
|
||||
IPython magic function to print date/time stamps
|
||||
and various system information.
|
||||
|
||||
watermark version 1.0.3
|
||||
watermark version 1.1.0
|
||||
|
||||
"""
|
||||
self.out = ''
|
||||
|
@ -114,6 +116,9 @@ class WaterMark(Magics):
|
|||
if args.machine:
|
||||
space = ' '
|
||||
self.out += '\nhost name%s: %s' %(space, gethostname())
|
||||
if args.githash:
|
||||
self._get_commit_hash(bool(args.machine))
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -154,5 +159,14 @@ class WaterMark(Magics):
|
|||
)
|
||||
|
||||
|
||||
def _get_commit_hash(self, machine):
|
||||
process = subprocess.Popen(['git', 'rev-parse', 'HEAD'], shell=False, stdout=subprocess.PIPE)
|
||||
git_head_hash = process.communicate()[0].strip()
|
||||
space = ''
|
||||
if machine:
|
||||
space = ' '
|
||||
self.out += '\nGit hash%s: %s' %(space, git_head_hash.decode("utf-8"))
|
||||
|
||||
|
||||
def load_ipython_extension(ipython):
|
||||
ipython.register_magics(WaterMark)
|
||||
|
|
Loading…
Reference in New Issue
Block a user