Skip to content

Commit

Permalink
remove old get_age methods
Browse files Browse the repository at this point in the history
We now use the "age" method in util.py to get relative
dates and times (i.e. 3h hours ago), which uses the arrow
library.

There are two methods in util.py, get_age() and get_age_in_days()
that we dont use anymore, as we use the age() method instead.

pluralize() in util.py is also removed, as the only place we
used this was in the get_ages, and we do other pluralizations
in JS now anyway.

The only other places that get_age() and get_age_in_days() were used
were a handful of methods in models.py, but these were not used anymore
either.
  • Loading branch information
ryanlerch committed May 25, 2017
1 parent bdfd8c9 commit afe5bd8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 48 deletions.
20 changes: 1 addition & 19 deletions bodhi/server/models.py
Expand Up @@ -43,7 +43,7 @@
from bodhi.server.config import config
from bodhi.server.exceptions import BodhiException, LockedUpdateException
from bodhi.server.util import (
avatar as get_avatar, build_evr, flash_log, get_age, get_age_in_days, get_critpath_pkgs,
avatar as get_avatar, build_evr, flash_log, get_critpath_pkgs,
get_nvr, get_rpm_header, header, tokenize)
import bodhi.server.util

Expand Down Expand Up @@ -1824,24 +1824,6 @@ def update_cves(self, cves, session):
self.cves.append(cve)
session.flush()

def get_pushed_age(self):
return get_age(self.date_pushed)

def get_submitted_age(self):
return get_age(self.date_submitted)

def get_pushed_color(self):
age = get_age_in_days(self.date_pushed)
if age == 0 or self.karma < 0:
color = '#ff0000' # red
elif age < 4:
color = '#ff6600' # orange
elif age < 7:
color = '#ffff00' # yellow
else:
color = '#00ff00' # green
return color

def obsolete_if_unstable(self, db):
"""
If an update with pending status(autopush enabled) reaches unstable karma
Expand Down
29 changes: 0 additions & 29 deletions bodhi/server/util.py
Expand Up @@ -18,7 +18,6 @@

from collections import defaultdict
from contextlib import contextmanager
from datetime import datetime
from os.path import join, dirname, basename, isfile
import collections
import functools
Expand Down Expand Up @@ -57,13 +56,6 @@ def header(x):
return u"%s\n %s\n%s\n" % ('=' * 80, x, '=' * 80)


def pluralize(val, name):
"""
Returns name if val == 1, or returns name with an 's' appended to the end if val != 1.
"""
return val == 1 and name or "%ss" % name


def get_rpm_header(nvr, tries=0):
""" Get the rpm header for a given build """

Expand Down Expand Up @@ -113,27 +105,6 @@ def mkmetadatadir(path):
subprocess.check_call(['createrepo_c', '--xz', '--database', '--quiet', path])


def get_age(date):
age = datetime.utcnow() - date
if age.days == 0:
if age.seconds < 60:
return "%d %s" % (age.seconds, pluralize(age.seconds, "second"))
minutes = int(age.seconds / 60)
if minutes >= 60:
hours = int(minutes / 60)
return "%d %s" % (hours, pluralize(hours, "hour"))
return "%d %s" % (minutes, pluralize(minutes, "minute"))
return "%d %s" % (age.days, pluralize(age.days, "day"))


def get_age_in_days(date):
if date:
age = datetime.utcnow() - date
return age.days
else:
return 0


def flash_log(msg):
""" Flash and log a given message """
log.debug(msg)
Expand Down

0 comments on commit afe5bd8

Please sign in to comment.