|
| 1 | +__version__ == '1.0.0' |
| 2 | + |
1 | 3 | """ |
2 | 4 | IPython magic function for printing basic information, such as the current date, time, |
3 | 5 | Python, and IPython version. |
|
23 | 25 | import platform |
24 | 26 | from time import strftime |
25 | 27 | from platform import python_version |
| 28 | +from pkg_resources import get_distribution |
26 | 29 |
|
27 | 30 | import IPython |
28 | 31 | from IPython.core.magic import Magics, magics_class, line_magic |
@@ -37,10 +40,13 @@ class DateMagic(Magics): |
37 | 40 | """ |
38 | 41 | @magic_arguments() |
39 | 42 | @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') |
40 | 44 | @argument('-t', '--time', action='store_true', help='print current time') |
41 | 45 | @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') |
43 | 48 | @argument('-i', '--ipython', action='store_true', help='prints IPython version') |
| 49 | + @argument('-p', '--packages', action=str, help='prints versions of Python modules and packages') |
44 | 50 | @line_magic |
45 | 51 | def date(self, line): |
46 | 52 | """ |
@@ -52,10 +58,16 @@ def date(self, line): |
52 | 58 | out = '' |
53 | 59 | if args.date: |
54 | 60 | out += strftime('%d/%m/%Y') |
| 61 | + elif arts.dateday: |
| 62 | + out += strftime('%a %b %M %Y') |
55 | 63 | if args.time: |
56 | 64 | if out: |
57 | 65 | out += ' ' |
58 | 66 | out += strftime('%H:%M:%S') |
| 67 | + if args.timezone: |
| 68 | + if out: |
| 69 | + out += ' ' |
| 70 | + out += strftime('%Z') |
59 | 71 | if args.python: |
60 | 72 | if out: |
61 | 73 | out += '\n' |
@@ -64,6 +76,10 @@ def date(self, line): |
64 | 76 | if out: |
65 | 77 | out += '\n' |
66 | 78 | 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 |
67 | 83 | if not out: |
68 | 84 | out += strftime('%d/%m/%Y') |
69 | 85 | print(out) |
|