Hi, You should be running it though the manage.py like: "./manage.py dbclean"
That works for me ... mvh Mikael Syska On Thu, Oct 4, 2012 at 12:15 PM, Mail Admin <[email protected]> wrote: > Hi Baruwa Experts, > > We are running the the python script that is > > /usr/lib/python2.4/site-packages/baruwa/messages/management/commands/dbclean.py > > while running below script we are getting error mentioned in trail mail. > > root# python dbclean.py > > > > Regards, > Pinemail > > > On Thu, Oct 4, 2012 at 3:30 PM, <[email protected]> wrote: >> >> Send Baruwa mailing list submissions to >> [email protected] >> >> To subscribe or unsubscribe via the World Wide Web, visit >> http://lists.baruwa.org/mailman/listinfo/baruwa >> or, via email, send a message with subject or body 'help' to >> [email protected] >> >> You can reach the person managing the list at >> [email protected] >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of Baruwa digest..." >> >> >> Today's Topics: >> >> 1. Cleaning mysql messages table (Mail Admin) >> 2. Re: Cleaning mysql messages table (Andrew Colin Kissa) >> >> >> ---------------------------------------------------------------------- >> >> Message: 1 >> Date: Wed, 3 Oct 2012 19:46:53 +0530 >> From: Mail Admin <[email protected]> >> To: [email protected] >> Subject: [Baruwa] Cleaning mysql messages table >> Message-ID: >> >> <CACGqap+zQKCrNZXAQ17YmSNWsDwtVvm503tZ9UsK12Q18bY=k...@mail.gmail.com> >> Content-Type: text/plain; charset="windows-1252" >> >> Baruwa Experts, >> >> >> >> I need your help in reducing mysql database size in ?messages? table. I >> found one script ( dbclean.py) which is supposed to do the job but somehow >> it is throwing following errors >> >> >> >> File "dbclean.py", line 22, in ? >> >> from django.db import connection >> >> File "/usr/lib/python2.4/site-packages/django/db/__init__.py", line 14, >> in ? >> >> if not settings.DATABASES: >> >> File "/usr/lib/python2.4/site-packages/django/utils/functional.py", line >> 276, in __getattr__ >> >> self._setup() >> >> File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line >> 40, >> in _setup >> >> raise ImportError("Settings cannot be imported, because environment >> variable %s is undefined." % ENVIRONMENT_VARIABLE) >> >> ImportError: Settings cannot be imported, because environment variable >> DJANGO_SETTINGS_MODULE is undefined. >> >> >> >> >> >> *& script look like this from >> /usr/lib/python2.4/site-packages/baruwa/messages/management/commands* >> >> >> >> from django.conf import settings >> >> from django.db import connection >> >> from django.core.management.base import NoArgsCommand >> >> from django.utils.translation import ugettext as _ >> >> >> >> class Command(NoArgsCommand): >> >> "Archive messages and delete from messages table" >> >> help = _("Deletes records older than QUARANTINE_DAYS_TO_KEEP" >> >> " days from the messages table") >> >> >> >> def handle_noargs(self, **options): >> >> #import datetime >> >> #from baruwa.messages.models import Message >> >> #interval = datetime.timedelta(days=60) >> >> #last_date = datetime.datetime.now() - interval >> >> #Message.objects.filter(timestamp__lt=last_date).delete() >> >> days = getattr(settings, 'QUARANTINE_DAYS_TO_KEEP', 10) >> >> >> >> conn = connection.cursor() >> >> conn.execute( >> >> """DELETE FROM messages WHERE id in >> >> (SELECT id FROM archive WHERE timestamp < >> >> DATE_SUB(CURDATE(), INTERVAL %s DAY)) >> >> """ % str(days) >> >> ) >> >> conn.execute( >> >> """INSERT LOW_PRIORITY INTO archive >> >> SELECT * FROM messages WHERE timestamp < >> >> DATE_SUB(CURDATE(), INTERVAL %s DAY) >> >> """ % str(days) >> >> ) >> >> conn.execute( >> >> """DELETE LOW_PRIORITY FROM messages >> >> WHERE timestamp < DATE_SUB(CURDATE(), >> >> INTERVAL %s DAY) >> >> """ % str(days) >> >> ) >> >> conn.execute('OPTIMIZE TABLE messages') >> >> conn.execute('OPTIMIZE TABLE archive') >> >> >> >> >> >> I changed only from ?60? to ?10? so that old entries can be removed from >> database >> >> >> >> >> Baruwa Version - 1.1.1 >> Mailscanner Version - 4.84.3 >> CentOS - 5.7 32 bit >> >> >> Thanks in advance, >> Pinemail. >> -------------- next part -------------- >> An HTML attachment was scrubbed... >> URL: >> <http://lists.baruwa.org/pipermail/baruwa/attachments/20121003/3e783d21/attachment-0001.html> >> >> ------------------------------ >> >> Message: 2 >> Date: Wed, 3 Oct 2012 18:36:00 +0200 >> From: Andrew Colin Kissa <[email protected]> >> To: Baruwa users list <[email protected]> >> Subject: Re: [Baruwa] Cleaning mysql messages table >> Message-ID: <[email protected]> >> Content-Type: text/plain; charset=windows-1252 >> >> >> On 03 Oct 2012, at 4:16 PM, Mail Admin wrote: >> >> > I changed only from ?60? to ?10? so that old entries can be removed from >> > database >> > >> > >> > >> > Baruwa Version - 1.1.1 >> > Mailscanner Version - 4.84.3 >> > CentOS - 5.7 32 bit >> > >> >> How are you running the command ? >> >> -- >> www.baruwa.org >> >> >> >> >> >> >> ------------------------------ >> >> _______________________________________________ >> Keep Baruwa FREE - http://pledgie.com/campaigns/12056 >> >> End of Baruwa Digest, Vol 27, Issue 1 >> ************************************* > > > > _______________________________________________ > Keep Baruwa FREE - http://pledgie.com/campaigns/12056 > _______________________________________________ Keep Baruwa FREE - http://pledgie.com/campaigns/12056

