Skip to content

Instantly share code, notes, and snippets.

@jsoa
Created April 8, 2011 18:55
Show Gist options
  • Save jsoa/910489 to your computer and use it in GitHub Desktop.
Save jsoa/910489 to your computer and use it in GitHub Desktop.
django management command to purge files in limelight
from django.core.management.base import BaseCommand, CommandError
from suds.client import Client
from optparse import make_option
WSDL = "https://soap.llnw.net/PurgeFiles/PurgeService.asmx?WSDL"
class Command(BaseCommand):
help = '''Purge a files from limelight\nUsage: purge_file url [url..] [-r] [-d]'''
option_list = BaseCommand.option_list + (
make_option('-d',
action='store_true',
dest='delete',
default=False,
help='Delete file'),
make_option('-r',
action='store_true',
dest='regex',
default=False,
help='Take arguments as regular expressions'),
)
def handle(self, *args, **options):
url, regex, delete = None, options['regex'], options['delete']
if len(args) == 0:
raise CommandError('Purge Request Error: At least one argument is required.')
try:
purge_files(args, regex, delete)
self.stdout.write("Purge Request Sent.\n")
except Exception, e:
raise CommandError('Purge Request Error: %s' % e)
def purge_files(urls, regex, delete):
"""
Purge files from limelight
"""
client = Client(WSDL)
# Supply the authentication information
auth = client.factory.create('AuthHeader')
auth.Username = '<username>'
auth.Password = '<password>'
client.set_options(soapheaders=auth)
# Create the purge request object
request = client.factory.create('PurgeRequest')
# Supply Email Address and Subject
request.EmailSubject = "Purge File(s)"
request.EmailTo = "<email>"
# Create the Purge Request Entry array
entries = client.factory.create('ArrayOfPurgeRequestEntry')
# Loop all the urls and create the entry
for url in urls:
entry = client.factory.create('PurgeRequestEntry')
# Supply shortname, url, regex and delete arguments
entry.Shortname = '<shortname>'
entry.Url = url
entry.Regex = regex
entry.Delete = delete
# Append the entry
entries.PurgeRequestEntry.append(entry)
request.Entries = entries
# Send the request
client.service.CreatePurgeRequest(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment