管理主机文件的api
hostsmgr的Python项目详细描述
主机管理器
用于管理主机文件的API
- 免费软件:apache-2.0
- 文档:https://hostsmgr.readthedocs.io。
功能
使用量
fromhostsmgrimportHostsMgrfromhostsmgr.hostsmgrimportguess_hosts_pathfromhostsmgr.conditionsimportAny,All,IPAddress,Host,InlineCommentmgr=HostsMgr()# Load system hosts filemgr.load(guess_hosts_path())# Save hosts to another place (Must open with text mode !)mgr.save(open('/etc/hosts.old','w'))# Save hosts to string with hosts file formathosts_string=mgr.saves()# Find all hosts entries that with 127.0.0.1 addressentries=mgr.find(IPAddress('127.0.0.1'))# Find all entries that contained specific hostentries=mgr.find(Host('localhost'))# Find all entries that contained specificed ip address and host bothentries=mgr.find(IPAddress('127.0.0.1')&Host('localhost'))# Find all entries that contained either hostsentries=mgr.find(Host('ip6-localhost')|Host('localhost'))# Find all entries that contained either hosts, another methodentries=mgr.find(Any(Host('ip6-localhost'),Host('localhost')))# Find all entries that contained both hostsentries=mgr.find(Host('ip6-localhost')&Host('localhost'))# Find all entries that contained both hosts, another methodentries=mgr.find(All(Host('ip6-localhost'),Host('localhost')))# Find all entries that contained target inline commententries=mgr.find(InlineComment('THIS_IS_A_TAG'))# Find only one entry that contained target inline commententries=mgr.find(InlineComment('THIS_IS_A_TAG'),at_most=1)# Remove an entry that found by find()mgr.remove(entry)# Remove all hosts from hosts entriesmgr.remove_hosts(['localhost','ip6-localhost'])# Remove all entries by inline comment exactly matchedmgr.remove_by_inline_comment(InlineComment('TAG_FOR_EXAMPLE'))# Remove all entries by inline comment partial matchedmgr.remove_by_inline_comment(InlineComment('TAG_FOR_EXAMPLE',partial=True))
学分
这个包是用Cookiecutter和PyPackageTemplate项目模板创建的。
历史记录
0.0.1(2018-04-15)
- pypi上的第一个版本。