-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix virtualenvwrapper; rewrite PATH stuff in Python
- Loading branch information
1 parent
f6ed028
commit 247297e
Showing
2 changed files
with
46 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import argparse | ||
import os | ||
import sys | ||
from collections import OrderedDict | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('action', help='either "append" or "prepend"') | ||
parser.add_argument('variable', | ||
help='existing shell variable name (e.g., PATH) containing PATH-type, colon-delimited list (e.g., "/bin:/usr/bin")') | ||
parser.add_argument('value', help='new value to add to the set (optionally if exists)') | ||
#parser.add_argument('--if-exists', help='only modify the existing path variable if the new path exists') | ||
args = parser.parse_args() | ||
|
||
path = os.environ.get(args.variable) | ||
path_split = path.split(':') if path else [] | ||
od = OrderedDict([x, None] for x in path_split) | ||
|
||
action = args.action | ||
value = args.value | ||
if action == 'prepend': | ||
new_od = OrderedDict({value: None}) | ||
new_od.update(od) | ||
od = new_od | ||
elif action == 'append': | ||
od[args.value] = None | ||
else: | ||
print('"action" must be either "append" or "prepend"') | ||
sys.exit(1) | ||
|
||
print(':'.join(od.keys())) |