Mercurial > public > sg101
view downloads/management/commands/dlorphan.py @ 693:ad69236e8501
For issue #52, update many 3rd party Javascript libraries.
Updated to jquery 1.10.2, jquery ui 1.10.3.
This broke a lot of stuff.
- Found a newer version of the jquery cycle all plugin (3.0.3).
- Updated JPlayer to 2.4.0.
- Updated to MarkItUp 1.1.14. This also required me to add multiline attributes
set to true on various buttons in the markdown set.
- As per a stackoverflow post, added some code to get multiline titles in
a jQuery UI dialog. They removed that functionality but allow you to put it
back.
Tweaked the MarkItUp preview CSS to show blockquotes in italic.
Did not update TinyMCE at this time. I'm not using the JQuery version and this
version appears to work ok for now.
What I should do is make a repo for MarkItUp and do a vendor branch thing so
I don't have to futz around diffing directories to figure out if I'll lose
changes when I update.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 04 Sep 2013 19:55:20 -0500 |
parents | 264b08bce8b8 |
children |
line wrap: on
line source
"""dlorphan - a management command to remove orphaned downloads files.""" from optparse import make_option import os from django.core.management.base import NoArgsCommand from django.conf import settings from downloads.models import Download, PendingDownload class Command(NoArgsCommand): help = "Finds and optionally deletes orphan downloads files" option_list = NoArgsCommand.option_list + ( make_option('--delete', action='store_true', dest='delete', default=False, help='Delete orphan files'), ) def handle_noargs(self, **options): """Find and optionally delete orphan downloads files.""" delete = options.get('delete', False) orphans = set() missing_pending = [] missing_dls = [] dls_dir = os.path.join(settings.MEDIA_ROOT, 'downloads') # find the set of all files in the downloads area for root, dirs, files in os.walk(dls_dir, followlinks=True): for name in files: orphans.add(unicode(os.path.join(root, name), 'utf-8')) # examine the pending downloads: for dl in PendingDownload.objects.iterator(): try: orphans.remove(dl.file.path) except KeyError: missing_pending.append(dl) # examine the downloads: for dl in Download.objects.iterator(): try: orphans.remove(dl.file.path) except KeyError: missing_dls.append(dl) if orphans and delete: for path in orphans: self.stdout.write("Deleting: {}\n".format(path)) os.remove(path) elif orphans: self.stdout.write("Orphan files:\n") for orphan in orphans: self.stdout.write("{}\n".format(orphan)) if missing_pending: self.stdout.write("PendingDownloads with missing files:\n") for dl in missing_pending: self.stdout.write("{}\n".format(dl)) if missing_dls: self.stdout.write("Downloads with missing files:\n") for dl in missing_dls: self.stdout.write("{}\n".format(dl)) empty_dirs = [] # check for empty directories after deletions for root, dirs, files in os.walk(dls_dir, followlinks=True): if not len(dirs) and not len(files): empty_dirs.append(root) if empty_dirs and delete: for path in empty_dirs: self.stdout.write("Deleting empty dir: {}\n".format(path)) os.removedirs(path) elif empty_dirs: self.stdout.write("Empty directories:\n") for d in empty_dirs: self.stdout.write("{}\n".format(d))