updater: support delete operation

This commit is contained in:
Felix Yan 2016-12-08 14:04:04 +08:00
parent d4c2da4185
commit 9eb1dbda70
No known key found for this signature in database
GPG Key ID: 786C63F330D7CB92
1 changed files with 17 additions and 0 deletions

View File

@ -10,6 +10,12 @@ if __name__ == "__main__":
nargs="+",
help='Add one or more new domain(s) (implies -s)',
)
parser.add_argument(
'-d', '--delete',
metavar="DOMAIN",
nargs="+",
help='Remove one or more new domain(s) (implies -s)',
)
parser.add_argument(
'-s', '--sort',
action='store_true',
@ -33,6 +39,17 @@ if __name__ == "__main__":
print("New domain added: " + domain)
lines.append(new_line)
if options.delete:
options.sort = True
for domain in options.delete:
target_line = "server=/%s/114.114.114.114\n" % domain
if target_line not in lines:
print("Failed to remove domain " + domain + ": not found.")
else:
print("Domain removed: " + domain)
lines.remove(target_line)
if options.sort:
lines.sort(key=lambda x: x.lstrip("#"))