# HG changeset patch # User Brian Neal # Date 1377303460 18000 # Node ID 161b568491145f8566b20a1a5d808cd2248f9a40 # Parent c83d330cb65f7982d4165ffcd46a24819ee38b83 For Django 1.5: management commands should use self.stdout, etc. for output. Note that I did not update the legacy commands since it is likely I will never run or test these commands again. diff -r c83d330cb65f -r 161b56849114 donations/management/commands/donations_report.py --- a/donations/management/commands/donations_report.py Fri Aug 23 19:02:45 2013 -0500 +++ b/donations/management/commands/donations_report.py Fri Aug 23 19:17:40 2013 -0500 @@ -32,9 +32,9 @@ max_month = 12 if year != today.year else today.month - print ROW_FMT % ('Month', 'Gross', 'Net') + self.stdout.write(ROW_FMT % ('Month', 'Gross', 'Net')) sep = ROW_FMT % ('-' * 10, '-' * 7, '-' * 7) - print sep + self.stdout.write(sep) total_gross = decimal.Decimal() total_net = decimal.Decimal() @@ -54,10 +54,10 @@ d = datetime.date(year=year, month=month, day=1) - print ROW_FMT % (d.strftime('%b %Y'), gross, net) + self.stdout.write(ROW_FMT % (d.strftime('%b %Y'), gross, net)) total_gross += gross total_net += net - print sep - print ROW_FMT % ('Total:', total_gross, total_net) + self.stdout.write(sep) + self.stdout.write(ROW_FMT % ('Total:', total_gross, total_net)) diff -r c83d330cb65f -r 161b56849114 downloads/management/commands/dlcatreport.py --- a/downloads/management/commands/dlcatreport.py Fri Aug 23 19:02:45 2013 -0500 +++ b/downloads/management/commands/dlcatreport.py Fri Aug 23 19:17:40 2013 -0500 @@ -11,13 +11,6 @@ from downloads.models import Category, Download -def print_titles(dls): - """Print out the download titles""" - - for dl in dls: - print dl.title.encode('utf-8') - - class Command(LabelCommand): help = "Produce on standard output a report of all downloads in a category." args = "category-slug" @@ -44,7 +37,7 @@ 'title').select_related() if options.get('titles_only'): - print_titles(downloads) + self.print_titles(downloads) return report = render_to_string('downloads/commands/category_report.html', { @@ -54,5 +47,12 @@ # encode it ourselves since it can fail if you try to redirect output to # a file and any of the content is not ASCII... - print report.encode('utf-8') + self.stdout.write(report.encode('utf-8')) + def print_titles(self, dls): + """Print out the download titles""" + + for dl in dls: + self.stdout.write(dl.title.encode('utf-8')) + + diff -r c83d330cb65f -r 161b56849114 downloads/management/commands/dlwgetcat.py --- a/downloads/management/commands/dlwgetcat.py Fri Aug 23 19:02:45 2013 -0500 +++ b/downloads/management/commands/dlwgetcat.py Fri Aug 23 19:17:40 2013 -0500 @@ -17,7 +17,7 @@ class Command(LabelCommand): help = ("Produce on standard output a bash script that wgets all the files" " in a category. The files are downloaded with a slugified name.") - + args = "category-slug" def handle_label(self, slug, **options): @@ -50,4 +50,4 @@ # encode it ourselves since it can fail if you try to redirect output to # a file and any of the content is not ASCII... - print output.encode('utf-8') + self.stdout.write(output.encode('utf-8'))