Created
October 5, 2013 16:46
-
-
Save flyfire/6843172 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding:utf-8 -*- | |
import sys | |
import urllib | |
import os | |
from shutil import copyfile | |
HOSTS_URL='https://smarthosts.googlecode.com/svn/trunk/hosts' | |
LOCAL_HOSTS='/etc/hosts' | |
def main(): | |
#backup hosts | |
copyfile(LOCAL_HOSTS,'hosts.bak') | |
with open(LOCAL_HOSTS,'aw') as hosts: | |
hosts.write(os.linesep) | |
for line in urllib.urlopen(HOSTS_URL): | |
hosts.write(line.strip()+os.linesep) | |
print 'Success!' | |
if __name__ == '__main__': | |
if len(sys.argv) > 1: | |
HOSTS_URL = sys.argv[1] | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment