annotate python/example/install_and_exec.py @ 828:34e2b07d8cc7

py35
author Jeff Hammel <k0scist@gmail.com>
date Sun, 19 Feb 2017 17:52:45 -0800
parents 9cb40c01c10a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
650
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 """
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 illustrates installation and execution following installation
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 """
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 import os
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import subprocess
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 import sys
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 here = os.path.dirname(os.path.realpath(__file__))
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 try:
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 import gnupg
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 print ("gnupg installed")
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 except ImportError:
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 print ("gnupg not installed")
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 subprocess.check_call(['pip', 'install', 'gnupg'])
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 args = [sys.executable] + sys.argv
9cb40c01c10a illustrate downloading a package and rerunning via exec
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 os.execl(sys.executable, *args)