From 4bfe9a0ea55a9d90992d418805a9f27fb99161e8 Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Thu, 2 Apr 2020 16:02:31 -0400 Subject: [PATCH] Remove print statements from the management commands --- program/management/commands/addnote.py | 2 +- .../management/commands/check_automation_ids.py | 6 +++--- program/management/commands/createuser.py | 4 ++-- program/management/commands/deleteuser.py | 2 +- program/management/commands/export_showlog.py | 12 ++++++------ program/management/commands/importhosts.py | 2 +- program/management/commands/importnotes.py | 12 ++++++------ program/management/commands/importprogramslots.py | 14 +++++++------- program/management/commands/importshows.py | 10 +++++----- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/program/management/commands/addnote.py b/program/management/commands/addnote.py index 5c0147eb..fafb33fc 100644 --- a/program/management/commands/addnote.py +++ b/program/management/commands/addnote.py @@ -64,4 +64,4 @@ class Command(BaseCommand): raise CommandError(ve.messages[0]) else: note.save() - print 'added note "%s" to "%s"' % (title, timeslot) + self.stdout.write(self.style.SUCCESS, f'added note "{title}" to "{timeslot}"') diff --git a/program/management/commands/check_automation_ids.py b/program/management/commands/check_automation_ids.py index 8bfe1643..825149ea 100644 --- a/program/management/commands/check_automation_ids.py +++ b/program/management/commands/check_automation_ids.py @@ -35,10 +35,10 @@ class Command(NoArgsCommand): multi_id = rd_ids[automation_id]['multi']['id'] if automation_id not in pv_ids and multi_id not in pv_ids: if multi_id < 0: - print '+ %d' % (automation_id) + self.stdout.write(self.style.NOTICE, f'+ {automation_id}') else: - print '+ %d (%d)' % (automation_id, multi_id) + self.stdout.write(self.style.NOTICE, f'+ {automation_id} ({multi_id})') for automation_id in sorted(pv_ids): if automation_id not in rd_ids: - print '-', automation_id \ No newline at end of file + self.stdout.write(self.style.NOTICE, f'- {automation_id}') diff --git a/program/management/commands/createuser.py b/program/management/commands/createuser.py index a78c1014..422c4bff 100644 --- a/program/management/commands/createuser.py +++ b/program/management/commands/createuser.py @@ -21,6 +21,6 @@ class Command(BaseCommand): User.objects.get(username=username) except User.DoesNotExist: User.objects.create_user(username=username, email=email) - print 'user created successfully.' + self.stdout.write(self.style.SUCCESS, 'user created successfully.') else: - print 'User already exists, no need to create.' + self.stdout.write(self.style.NOTICE, 'User already exists, no need to create.') diff --git a/program/management/commands/deleteuser.py b/program/management/commands/deleteuser.py index db2cb60b..a8bb2308 100644 --- a/program/management/commands/deleteuser.py +++ b/program/management/commands/deleteuser.py @@ -20,4 +20,4 @@ class Command(BaseCommand): except User.DoesNotExist: raise 'user does not exist.' else: - print 'user deleted succesfuly.' + self.stdout.write(self.style.SUCCESS, 'user deleted succesfuly.') diff --git a/program/management/commands/export_showlog.py b/program/management/commands/export_showlog.py index 0e26c011..41c20217 100644 --- a/program/management/commands/export_showlog.py +++ b/program/management/commands/export_showlog.py @@ -2,7 +2,7 @@ import codecs import sys -from datetime import date, datetime, time, timedelta +from datetime import datetime from django.core.management.base import BaseCommand, CommandError from program.models import TimeSlot @@ -23,21 +23,21 @@ class Command(BaseCommand): else: raise CommandError('you must provide the year') - print "# Radio Helsinki Sendungslog %d" % year + self.stdout.write(self.style.NOTICE, f"# Radio Helsinki Sendungslog {year}") start = datetime.strptime('%d__01__01__00__00' % (year), '%Y__%m__%d__%H__%M') end = datetime.strptime('%d__01__01__00__00' % (year+1), '%Y__%m__%d__%H__%M') currentDate = None for ts in TimeSlot.objects.filter(end__gt=start, start__lt=end).select_related('schedule').select_related('show'): - if currentDate == None or currentDate < ts.start.date(): + if currentDate is None or currentDate < ts.start.date(): if currentDate: - print "\n" + self.stdout.write('\n') currentDate = ts.start.date() - print currentDate.strftime("## %a %d.%m.%Y:\n") + self.stdout.write(self.style.NOTICE, currentDate.strftime("## %a %d.%m.%Y:\n")) title = ts.show.name if ts.schedule.is_repetition: title += " (WH)" - print " * **%s - %s**: %s" % (ts.start.strftime("%H:%M:%S"), ts.end.strftime("%H:%M:%S"), title) \ No newline at end of file + self.stdout.write(self.style.NOTICE, f' * **{ts.start.strftime("%H:%M:%S")} - {ts.end.strftime("%H:%M:%S")}**: {title}') diff --git a/program/management/commands/importhosts.py b/program/management/commands/importhosts.py index 31f4a3f6..a0b92923 100644 --- a/program/management/commands/importhosts.py +++ b/program/management/commands/importhosts.py @@ -32,4 +32,4 @@ WHERE letzter_termin > current_date AND macher != '' AND titel NOT LIKE 'Musikpr cursor.close() connection.close() - print '%i hosts imported' % counter + self.stdout.write(self.style.SUCCESS, F'{counter} hosts imported') diff --git a/program/management/commands/importnotes.py b/program/management/commands/importnotes.py index f835e37e..91476e6f 100644 --- a/program/management/commands/importnotes.py +++ b/program/management/commands/importnotes.py @@ -36,30 +36,30 @@ WHERE n.sendung_id in (SELECT id FROM sendungen WHERE letzter_termin > current_d try: show = Show.objects.get(name=stitel) except ObjectDoesNotExist: - print 'show with name "%s" not found' % stitel + self.stdout.write(self.style.WARNING, f'show with name "{stitel}" not found') else: try: timeslot = TimeSlot.objects.get(schedule__show=show, start__year=year, start__month=month, start__day=day) except ObjectDoesNotExist: - print 'no timeslot found for sendung "%s" and datum "%s"' % (stitel, datum) + self.stdout.write(self.style.WARNING, f'no timeslot found for sendung "{stitel}" and datum "{datum}"') except MultipleObjectsReturned: - print 'multiple timeslots found for sendung "%s" and datum "%s"' % (stitel, datum) + self.stdout.write(self.style.WARNING, f'multiple timeslots found for sendung "{stitel}" and datum "{datum}"') else: note = Note(timeslot=timeslot, title=ntitel, content=notiz) try: note.validate_unique() except ValidationError: - print 'note already imported for show "%s" and datum "%s"' % (stitel, datum) + self.stdout.write(self.style.WARNING, f'note already imported for show "{stitel}" and datum "{datum}"') else: try: note.save() except: - print 'could not save note "%s" for show "%s" and datum "%s"' % (ntitel, stitel, datum) + self.stdout.write(self.style.ERROR, f'could not save note "{ntitel}" for show "{stitel}" and datum "{datum}"') else: counter += 1 cursor.close() connection.close() - print '%i notes imported' % counter \ No newline at end of file + self.stdout.write(self.style.SUCCESS, f'{counter} notes imported') diff --git a/program/management/commands/importprogramslots.py b/program/management/commands/importprogramslots.py index b6e54227..8ce8a2bd 100644 --- a/program/management/commands/importprogramslots.py +++ b/program/management/commands/importprogramslots.py @@ -48,17 +48,17 @@ WHERE letzter_termin > current_date AND titel NOT LIKE 'Musikprogramm' AND titel try: show = Show.objects.get(name=titel) except ObjectDoesNotExist: - print 'show with name "%s" not found' % titel + self.stdout.write(self.style.NOTICE, f'show with name "{titel}" not found') else: schedule = Schedule(rrule=rrule, byweekday=termin, show=show, dstart=erster_termin, - tstart=tstart, tend=tend, until=letzter_termin) + tstart=tstart, tend=tend, until=letzter_termin) try: schedule.save() counter += 1 except: pass except KeyError: - print 'rhythmus "%i" is not supported for sendung "%s"' % (rhytmus, titel) + self.stdout.write(self.style.NOTICE, f'rhythmus "{rhytmus}" is not supported for sendung "{titel}"') cursor.execute("""SELECT titel, beginn, ende, erster_termin, letzter_termin, rhytmus, termin FROM sendungen @@ -80,19 +80,19 @@ WHERE letzter_termin > current_date AND titel LIKE '%%(Wiederholung)'""") try: show = Show.objects.get(name=titel) except ObjectDoesNotExist: - print 'show with name "%s" not found' % titel + self.stdout.write(self.style.WARNING, f'show with name "{titel}" not found') else: schedule = Schedule(rrule=rrule, byweekday=termin, show=show, dstart=erster_termin, - tstart=tstart, tend=tend, until=letzter_termin, is_repetition=True) + tstart=tstart, tend=tend, until=letzter_termin, is_repetition=True) try: schedule.save() counter += 1 except: pass except KeyError: - print 'rhythmus "%i" is not supported for sendung "%s"' % (rhytmus, titel) + self.stdout.write(self.style.WARNING, f'rhythmus "{rhytmus}" is not supported for sendung "{titel}"') cursor.close() connection.close() - print '%i schedules imported' % counter \ No newline at end of file + self.stdout.write(self.style.SUCCESS, f'{counter} schedules imported') diff --git a/program/management/commands/importshows.py b/program/management/commands/importshows.py index f1353b8a..cff3d434 100644 --- a/program/management/commands/importshows.py +++ b/program/management/commands/importshows.py @@ -41,15 +41,15 @@ ORDER BY titel, beginn, ende""") try: host = Host.objects.get(name=macher) except MultipleObjectsReturned: - print 'multiple hosts with name "%s" found' % macher + self.stdout.write(self.style.NOTICE, f'multiple hosts with name "{macher}" found') except ObjectDoesNotExist: - print 'host with name "%s" not found' % macher + self.stdout.write(self.style.NOTICE, f'host with name "{macher}" not found') else: hosts.append(host) try: show = Show.objects.get(name=titel) - print 'sendung "%s" already imported as show "%s"' % (titel, show) + self.stdout.write(self.style.NOTICE, f'sendung "{titel}" already imported as show "{show}"') except ObjectDoesNotExist: show = Show(broadcastformat=TALK, name=titel, slug=slug, short_description='FIXME', description=beschreibung) @@ -57,7 +57,7 @@ ORDER BY titel, beginn, ende""") show.save() counter += 1 except: - print 'sendung "%s" could not be imported' % titel + self.stdout.write(self.style.NOTICE, f'sendung "{titel}" could not be imported') else: for h in hosts: show.hosts.add(h) @@ -66,4 +66,4 @@ ORDER BY titel, beginn, ende""") cursor.close() connection.close() - print '%i shows imported' % counter + self.stdout.write(self.style.SUCCESS, f'{counter} shows imported') -- GitLab