summaryrefslogtreecommitdiff
path: root/netaddr/cli.py
diff options
context:
space:
mode:
authorJakub Stasiak <jakub@stasiak.at>2020-06-17 19:05:45 +0200
committerJakub Stasiak <jakub@stasiak.at>2020-06-17 19:05:45 +0200
commit297ac7081f76224fb194a7b5350e6d129c328eb4 (patch)
tree33f20c1c7b29bac1026f76be6f9247f8a5be529c /netaddr/cli.py
parent036fc2f39ed55aa0a4e709473bb6d5f7d3b2ef4a (diff)
parent5b2807ff91640c959dc358334f626cea0e28778c (diff)
downloadnetaddr-next-master.tar.gz
Merge branch 'rel-0.7.x'next-master
Diffstat (limited to 'netaddr/cli.py')
-rwxr-xr-xnetaddr/cli.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/netaddr/cli.py b/netaddr/cli.py
new file mode 100755
index 0000000..c97eab9
--- /dev/null
+++ b/netaddr/cli.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+#-----------------------------------------------------------------------------
+# Copyright (c) 2008 by David P. D. Moss. All rights reserved.
+#
+# Released under the BSD license. See the LICENSE file for details.
+#-----------------------------------------------------------------------------
+"""an interactive shell for the netaddr library"""
+
+import os
+import sys
+import netaddr
+from netaddr import *
+
+# aliases to save some typing ...
+from netaddr import IPAddress as IP, IPNetwork as CIDR
+from netaddr import EUI as MAC
+
+def main():
+ argv = sys.argv[1:]
+
+ banner = "\nnetaddr shell %s - %s\n" % (netaddr.__version__, __doc__)
+ exit_msg = "\nShare and enjoy!"
+ rc_override = None
+
+ try:
+ try:
+ # ipython >= 0.11
+ from IPython.terminal.embed import InteractiveShellEmbed
+ ipshell = InteractiveShellEmbed(banner1=banner, exit_msg=exit_msg)
+ except ImportError:
+ # ipython < 0.11
+ from IPython.Shell import IPShellEmbed
+ ipshell = IPShellEmbed(argv, banner, exit_msg, rc_override)
+ except ImportError:
+ sys.stderr.write('IPython (http://ipython.scipy.org/) not found!\n')
+ sys.exit(1)
+
+ ipshell()
+
+
+if __name__ == '__main__':
+ main()