更新hosts的python脚本
2020-11-27 11:11
标签:style blog class code int art 更新hosts的python脚本,搜素材,soscw.com 更新hosts的python脚本 标签:style blog class code int art 原文地址:http://blog.csdn.net/bboyfeiyu/article/details/24834511#!/usr/bin/env python
# -*- coding:utf-8 -*-
#author:mrsimple
import sys
import urllib
import os
from shutil import copyfile
HOSTS_URL=‘https://smarthosts.googlecode.com/svn/trunk/hosts‘
LOCAL_HOSTS=‘/etc/hosts‘
def update():
"""update hosts from smarthost"""
# backup hosts file
copyfile(LOCAL_HOSTS,‘hosts.bak‘)
with open(LOCAL_HOSTS,‘aw‘) as hosts:
# 字符串给出当前平台使用的行终止符。例如,Windows使用‘\r\n‘,Linux使用‘\n‘而Mac使用‘\r‘。
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]
update()
上一篇:javafx之CSS初探
下一篇:java File类的基本操作