]> git.phdru.name Git - dotfiles.git/blob - bin/browser_stack.py
Initial import
[dotfiles.git] / bin / browser_stack.py
1 #! /usr/bin/env python
2
3 import os, shutil
4 browser_stack = os.path.expanduser('~/.config/.browser-stack')
5
6 def get_stack():
7     try:
8         with open(browser_stack, 'rU') as stack_file:
9             return stack_file.readlines()
10     except IOError: # No such file
11         return []
12
13 def save_stack(stack):
14     os.umask(0066) # octal -rw-------
15     with open(browser_stack+'.tmp', 'w') as stack_file:
16         stack_file.writelines(stack)
17     shutil.copy(browser_stack+'.tmp', browser_stack)
18     os.remove(browser_stack+'.tmp')
19
20 def set_current_browser():
21     stack = get_stack()
22     if stack:
23         os.environ['BROWSER'] = stack[0].strip()