updater: support delete operation
This commit is contained in:
parent
d4c2da4185
commit
9eb1dbda70
17
updater.py
17
updater.py
|
@ -10,6 +10,12 @@ if __name__ == "__main__":
|
||||||
nargs="+",
|
nargs="+",
|
||||||
help='Add one or more new domain(s) (implies -s)',
|
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(
|
parser.add_argument(
|
||||||
'-s', '--sort',
|
'-s', '--sort',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
|
@ -33,6 +39,17 @@ if __name__ == "__main__":
|
||||||
print("New domain added: " + domain)
|
print("New domain added: " + domain)
|
||||||
lines.append(new_line)
|
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:
|
if options.sort:
|
||||||
lines.sort(key=lambda x: x.lstrip("#"))
|
lines.sort(key=lambda x: x.lstrip("#"))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue