A fork of pappy proxy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.9 KiB

9 years ago
import crochet
import pappyproxy
import shlex
9 years ago
from pappyproxy.plugin import async_main_context_ids
9 years ago
from pappyproxy.util import PappyException, load_reqlist
9 years ago
from twisted.internet import defer
9 years ago
from pappyproxy.http import Request
9 years ago
@crochet.wait_for(timeout=None)
@defer.inlineCallbacks
def tag(line):
"""
Add a tag to requests.
Usage: tag <tag> [request ids]
You can tag as many requests as you want at the same time. If no
ids are given, the tag will be applied to all in-context requests.
"""
args = shlex.split(line)
if len(args) == 0:
raise PappyException('Tag name is required')
tag = args[0]
if len(args) > 1:
9 years ago
reqids = yield load_reqlist(args[1], False, ids_only=True)
print 'Tagging %s with %s' % (', '.join(reqids), tag)
9 years ago
else:
print "Tagging all in-context requests with %s" % tag
9 years ago
reqids = yield async_main_context_ids()
9 years ago
9 years ago
for reqid in reqids:
req = yield Request.load_request(reqid)
9 years ago
if tag not in req.tags:
9 years ago
req.tags.add(tag)
9 years ago
if req.saved:
yield req.async_save()
else:
print 'Request %s already has tag %s' % (req.reqid, tag)
@crochet.wait_for(timeout=None)
@defer.inlineCallbacks
def untag(line):
"""
Remove a tag from requests
Usage: untag <tag> <request ids>
You can provide as many request ids as you want and the tag will
be removed from all of them. If no ids are given, the tag will
be removed from all in-context requests.
"""
args = shlex.split(line)
if len(args) == 0:
raise PappyException("Tag and request ids are required")
tag = args[0]
ids = []
if len(args) > 1:
9 years ago
reqids = yield load_reqlist(args[1], False, ids_only=True)
print 'Removing tag %s from %s' % (tag, ', '.join(reqids))
9 years ago
else:
9 years ago
print "Removing tag %s from all in-context requests" % tag
9 years ago
reqids = yield async_main_context_ids()
9 years ago
9 years ago
for reqid in reqids:
req = yield Request.load_request(reqid)
9 years ago
if tag in req.tags:
9 years ago
req.tags.discard(tag)
9 years ago
if req.saved:
yield req.async_save()
if ids:
print 'Tag %s removed from %s' % (tag, ', '.join(ids))
@crochet.wait_for(timeout=None)
@defer.inlineCallbacks
def clrtag(line):
"""
Clear all the tags from requests
Usage: clrtag <request ids>
"""
args = shlex.split(line)
if len(args) == 0:
raise PappyException('No request IDs given')
reqs = yield load_reqlist(args[0], False)
for req in reqs:
if req.tags:
9 years ago
req.tags = set()
9 years ago
print 'Tags cleared from request %s' % (req.reqid)
if req.saved:
yield req.async_save()
###############
## Plugin hooks
def load_cmds(cmd):
cmd.set_cmds({
'clrtag': (clrtag, None),
'untag': (untag, None),
'tag': (tag, None),
})
cmd.add_aliases([
#('rpy', ''),
])