1+ __version__ == '1.0.0'
2+
13"""
24IPython magic function for printing basic information, such as the current date, time,
35Python, and IPython version.
2325import platform
2426from time import strftime
2527from platform import python_version
28+ from pkg_resources import get_distribution
2629
2730import IPython
2831from IPython .core .magic import Magics , magics_class , line_magic
@@ -37,10 +40,13 @@ class DateMagic(Magics):
3740 """
3841 @magic_arguments ()
3942 @argument ('-d' , '--date' , action = 'store_true' , help = 'prints date (default)' )
43+ @argument ('-dd' , '--dateday' , action = 'store_true' , help = 'prints date with abbrv. day and month names' )
4044 @argument ('-t' , '--time' , action = 'store_true' , help = 'print current time' )
4145 @argument ('-s' , '--datetime' , action = 'store_true' , help = 'print current time' )
42- @argument ('-p' , '--python' , action = 'store_true' , help = 'prints Python version' )
46+ @argument ('-z' , '--timezone' , action = 'store_true' , help = 'prints time zone' )
47+ @argument ('-y' , '--python' , action = 'store_true' , help = 'prints Python version' )
4348 @argument ('-i' , '--ipython' , action = 'store_true' , help = 'prints IPython version' )
49+ @argument ('-p' , '--packages' , action = str , help = 'prints versions of Python modules and packages' )
4450 @line_magic
4551 def date (self , line ):
4652 """
@@ -52,10 +58,16 @@ def date(self, line):
5258 out = ''
5359 if args .date :
5460 out += strftime ('%d/%m/%Y' )
61+ elif arts .dateday :
62+ out += strftime ('%a %b %M %Y' )
5563 if args .time :
5664 if out :
5765 out += ' '
5866 out += strftime ('%H:%M:%S' )
67+ if args .timezone :
68+ if out :
69+ out += ' '
70+ out += strftime ('%Z' )
5971 if args .python :
6072 if out :
6173 out += '\n '
@@ -64,6 +76,10 @@ def date(self, line):
6476 if out :
6577 out += '\n '
6678 out += 'IPython %s' % IPython .__version__
79+ if args .packages :
80+ packages = args .packages .split (',' )
81+ for p in packages :
82+ out += '\n %s' % get_distribution (p ).version
6783 if not out :
6884 out += strftime ('%d/%m/%Y' )
6985 print (out )
0 commit comments