Created
May 28, 2014 01:32
-
-
Save luxinyan/a9041f942995760f245e to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# -*- coding:utf-8 -*- | |
#author:rikugun | |
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(): | |
"""主函数""" | |
#备份文件 | |
copyfile(LOCAL_HOSTS,'hosts.bak') | |
with open(LOCAL_HOSTS,'aw') as hosts: | |
hosts.write(os.linesep) | |
#转义windowså’Œunixçš„æ¢è¡Œ | |
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