管理主机文件的api

hostsmgr的Python项目详细描述


主机管理器 https://img.shields.io/pypi/v/hostsmgr.svghttps://img.shields.io/travis/starofrainnight/hostsmgr.svghttps://ci.appveyor.com/api/projects/status/lx6dwcisa6bolsqw?svg=trueDocumentation StatusUpdates

用于管理主机文件的API

功能

使用量

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))

学分

这个包是用CookiecutterPyPackageTemplate项目模板创建的。

历史记录

0.0.1(2018-04-15)

  • pypi上的第一个版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
主类中的java访问方法   Javalog4j不读取它的log4j。属性文件   雅加达ee通过Java(web应用程序)使用iText/任何其他使用现成数据的库生成PDF报告   lua使用java阅读TeamSpeak 3消息   将日期转换为BST java   java Spring引用ProxyFactoryBean中带有ref的protoyype bean   如何使java只打印一条带有if语句的消息   java如何通过JavaMail从雅虎服务器发送电子邮件?   使用百分比和BigDecimal的java测试   java如何对字符串数组排序   java验证器+MVC+REST::更新问题   java如何阻止eclipse如此频繁地挂起?   java从AsyncTask(片段内)访问TextView   IDEJava:制作可调整大小和拖动的组件