-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoffline.py
executable file
·36 lines (30 loc) · 1020 Bytes
/
offline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
"""Offline cache editor"""
import argparse
from ids import UserIDs
parser = argparse.ArgumentParser(description='Offline cache editor')
parser.add_argument("cache", help="Required cache file")
parser.add_argument("-a", "--add", nargs=2, metavar=('username', 'uid'),
help="Adds specified username and uid to cache")
parser.add_argument("-d", "--delete", nargs=1, metavar='username|uid',
help="Deletes specified username or uid from cache")
parser.add_argument("-C", "--clear", action='store_true', help="Clears all cache")
args = parser.parse_args()
mapped = UserIDs()
mapped.load(args.cache)
code = 0
# Add specified username and uid to cache
if args.add:
user, uid = args.add[0], args.add[1]
# Deletes specified username or uid from cache
if args.delete:
user = args.delete[0]
if mapped.have(user):
code = mapped.remove(user)
else:
code = 1
#Clears all cache
if args.clear:
mapped.clear()
mapped.close()
exit(code)