Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python 3 support #853

Merged
merged 1 commit into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ install:
python:
- "2.7.6"
- "2.7"
- "3.6"
script:
- make
notifications:
Expand Down
2 changes: 1 addition & 1 deletion plexus/grainlog/grain.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _build_indices(self):
self._roles_idx = defaultdict(list)

for s in self.d.get('servers', []):
server_name = s.keys()[0]
server_name = list(s.keys())[0]
data = s[server_name]
if not isinstance(data, dict):
# sometimes we get a string like
Expand Down
2 changes: 1 addition & 1 deletion plexus/grainlog/tests/test_grain.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_by_role(self):
class ServerTest(unittest.TestCase):
def test_keys(self):
s = Server('foo', dict(a="b"))
self.assertEqual(s.keys(), ["a"])
self.assertEqual(list(s.keys()), ["a"])

def test_apps(self):
s = Server('foo', dict(apps=['one', 'two', 'three']))
Expand Down
6 changes: 3 additions & 3 deletions plexus/grainlog/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def test_get(self):
def test_post(self):
request = self.factory.post(reverse('grainlog-raw-update'))

with open('test_data/grains.json') as f:
request.FILES['payload'] = SimpleUploadedFile("grains.json",
f.read())
with open('test_data/grains.json', 'rb') as f:
request.FILES['payload'] = SimpleUploadedFile(
"grains.json", f.read())
request.user = self.anon
response = GrainLogListView.as_view()(request)
self.assertEqual(response.status_code, 302)
11 changes: 6 additions & 5 deletions plexus/main/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.contrib import admin

from models import Application, ApplicationAlias, ApplicationContact
from models import Contact, Alias, Technology, Note
from models import Location, OSFamily, OperatingSystem, IPAddress
from models import ServerContact
from plexus.main.models import Server
from plexus.main.models import (
Application, ApplicationAlias, ApplicationContact,
Contact, Alias, Technology, Note,
Location, OSFamily, OperatingSystem, IPAddress,
ServerContact, Server
)


for c in [Location, OSFamily, OperatingSystem, IPAddress,
Expand Down
45 changes: 29 additions & 16 deletions plexus/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,53 @@

from django.contrib.auth.models import User
from django.db import models
from django.utils.encoding import python_2_unicode_compatible, smart_text

from plexus.grainlog.models import GrainLog


@python_2_unicode_compatible
class Location(models.Model):
name = models.CharField(max_length=256)
details = models.TextField(blank=True, default=u"")

def __unicode__(self):
def __str__(self):
return self.name

def get_absolute_url(self):
return "/location/%d/" % self.id


@python_2_unicode_compatible
class OSFamily(models.Model):
name = models.CharField(max_length=256)

class Meta:
ordering = ['name', ]

def __unicode__(self):
def __str__(self):
return self.name

def get_absolute_url(self):
return "/os/%d/" % self.id


@python_2_unicode_compatible
class OperatingSystem(models.Model):
family = models.ForeignKey(OSFamily)
version = models.CharField(max_length=256)

class Meta:
ordering = ['version', ]

def __unicode__(self):
return unicode(self.family) + " " + self.version
def __str__(self):
return smart_text(self.family) + " " + self.version

def get_absolute_url(self):
return "/os/%d/%d/" % (self.family.id, self.id)


@python_2_unicode_compatible
class Server(models.Model):
name = models.CharField(max_length=256)
primary_function = models.TextField(blank=True, default=u"")
Expand All @@ -60,7 +65,7 @@ class Server(models.Model):
class Meta:
ordering = ['name', ]

def __unicode__(self):
def __str__(self):
return self.name

def get_absolute_url(self):
Expand Down Expand Up @@ -105,21 +110,23 @@ def aliases(self):
return Alias.objects.filter(ip_address__server=self)


@python_2_unicode_compatible
class IPAddress(models.Model):
ipv4 = models.CharField(max_length=256)
mac_addr = models.CharField(max_length=256, null=True, blank=True)
server = models.ForeignKey(Server)

def __unicode__(self):
def __str__(self):
return self.ipv4


@python_2_unicode_compatible
class Contact(models.Model):
name = models.CharField(max_length=256)
email = models.CharField(max_length=256, default="")
phone = models.CharField(max_length=256, default="")

def __unicode__(self):
def __str__(self):
return self.name

def get_absolute_url(self):
Expand All @@ -134,6 +141,7 @@ def active_applications(self):
application__deprecated=False)]


@python_2_unicode_compatible
class Alias(models.Model):
hostname = models.CharField(max_length=256)
ip_address = models.ForeignKey(IPAddress, null=True)
Expand All @@ -155,7 +163,7 @@ class Alias(models.Model):
class Meta:
ordering = ['hostname', ]

def __unicode__(self):
def __str__(self):
return self.hostname

def status_css_class(self):
Expand Down Expand Up @@ -214,13 +222,15 @@ def get_absolute_url(self):
return "/alias/%d/" % self.id


@python_2_unicode_compatible
class Technology(models.Model):
name = models.CharField(max_length=256)

def __unicode__(self):
def __str__(self):
return self.name


@python_2_unicode_compatible
class Application(models.Model):
name = models.CharField(max_length=256)
description = models.TextField(blank=True, default=u"")
Expand All @@ -238,7 +248,7 @@ class Application(models.Model):
class Meta:
ordering = ['name', ]

def __unicode__(self):
def __str__(self):
return self.name

def pmt_feed_url(self):
Expand Down Expand Up @@ -302,34 +312,37 @@ def upcoming(self):
return (datetime.now() + timedelta(weeks=4)).date() > self.end


@python_2_unicode_compatible
class ApplicationAlias(models.Model):
application = models.ForeignKey(Application)
alias = models.ForeignKey(Alias)

def __unicode__(self):
return unicode(self.application) + " -> " + unicode(self.alias)
def __str__(self):
return smart_text(self.application) + " -> " + smart_text(self.alias)


@python_2_unicode_compatible
class ApplicationContact(models.Model):
application = models.ForeignKey(Application)
contact = models.ForeignKey(Contact)

class Meta:
order_with_respect_to = 'application'

def __unicode__(self):
return unicode(self.application) + ": " + unicode(self.contact)
def __str__(self):
return smart_text(self.application) + ": " + smart_text(self.contact)


@python_2_unicode_compatible
class ServerContact(models.Model):
server = models.ForeignKey(Server)
contact = models.ForeignKey(Contact)

class Meta:
order_with_respect_to = 'server'

def __unicode__(self):
return unicode(self.server) + ": " + unicode(self.contact)
def __str__(self):
return smart_text(self.server) + ": " + smart_text(self.contact)


class Note(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion plexus/main/templatetags/plexustags.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def aliases(name):
@register.simple_tag
def server_grain(grains, server):
try:
grain = filter(lambda s: s.name == server, grains)[0]
grain = list(filter(lambda s: s.name == server, grains))[0]
return grain
except IndexError:
return None
3 changes: 0 additions & 3 deletions plexus/main/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
# flake8: noqa
from test_models import *
from test_views import *
Loading