Merge lp:~rvb/maas/cmd-line-bug-1190958 into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 1532
Proposed branch: lp:~rvb/maas/cmd-line-bug-1190958
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 23 lines (+5/-1)
1 file modified
src/maasserver/management/commands/apikey.py (+5/-1)
To merge this branch: bzr merge lp:~rvb/maas/cmd-line-bug-1190958
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+169399@code.launchpad.net

Commit message

Do not print newline if Django.VERSION >= (1.5).

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

This seems unnecessarily fragile. Why not just strip the tuple and then add the newline unconditionally?

review: Needs Information
Revision history for this message
Raphaël Badin (rvb) wrote :

> This seems unnecessarily fragile. Why not just strip the tuple and then add
> the newline unconditionally?

I don't think this is fragile (detecting which version of Django is present seems pretty solid to me). Stripping the resulting string would work but my code has this advantage: when django pre 1.5 is long forgotten, we can simple get rid of the "if statement".

Revision history for this message
Raphaël Badin (rvb) wrote :

In other words, my strategy here is to make Django 1.5 the default expected behaviour and special case for Django.VERSION < 1.5.

Revision history for this message
Gavin Panella (allenap) wrote :

[1]

-        self.stdout.write('\n')
+        # In Django 1.5+, self.stdout.write() adds a newline character at
+        # the end of the message.

Please tell me that Django isn't meddling with the behaviour of
sys.stdout.write()? I assume you mean something else.

[2]

> In other words, my strategy here is to make Django 1.5 the default
> expected behaviour and special case for Django.VERSION < 1.5.

The advantage of Jeroen's idea is that we never need to care, even if
the behaviour changes back again in Django 1.6.

Revision history for this message
Gavin Panella (allenap) wrote :

Ignore [1]; sorry, missed the `self`.

Revision history for this message
Gavin Panella (allenap) wrote :

You might be able to ignore my [2] too; I'm not sure how Jeroen's idea works now. The tuple doesn't need stripping; the newline is added by Django in self.stdout.write().

Revision history for this message
Raphaël Badin (rvb) wrote :

> You might be able to ignore my [2] too; I'm not sure how Jeroen's idea works
> now. The tuple doesn't need stripping; the newline is added by Django in
> self.stdout.write().

You're right… I've done two other branches in the meantime and read Jeroen's comment too quickly…

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

OK, that answers my question.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/management/commands/apikey.py'
2--- src/maasserver/management/commands/apikey.py 2013-05-16 06:32:28 +0000
3+++ src/maasserver/management/commands/apikey.py 2013-06-14 12:18:26 +0000
4@@ -19,6 +19,7 @@
5 convert_string_to_tuple,
6 convert_tuple_to_string,
7 )
8+import django
9 from django.contrib.auth.models import User
10 from django.core.management.base import (
11 BaseCommand,
12@@ -44,7 +45,10 @@
13 def _print_token(self, token):
14 """Write `token` to stdout in the standard format."""
15 self.stdout.write(convert_tuple_to_string(get_creds_tuple(token)))
16- self.stdout.write('\n')
17+ # In Django 1.5+, self.stdout.write() adds a newline character at
18+ # the end of the message.
19+ if django.VERSION < (1, 5):
20+ self.stdout.write('\n')
21
22 def _generate_token(self, user):
23 _, token = user.get_profile().create_authorisation_token()