Mercurial > hg > config
annotate python/example/install_and_exec.py @ 808:48ea50d346de
comment re dependency
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 28 Oct 2016 17:10:27 -0700 |
parents | 9cb40c01c10a |
children |
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) |