2012-05-01 16:56:09 +02:00
|
|
|
"""
|
|
|
|
djeuscan.helpers
|
|
|
|
"""
|
|
|
|
|
2012-05-01 21:15:55 +02:00
|
|
|
from distutils.version import StrictVersion, LooseVersion
|
|
|
|
|
2012-05-01 16:56:09 +02:00
|
|
|
|
|
|
|
def xint(i):
|
2012-05-01 21:15:55 +02:00
|
|
|
"""
|
|
|
|
Tries to cast to int, fallbacks to 0
|
|
|
|
"""
|
2012-05-01 16:56:09 +02:00
|
|
|
try:
|
|
|
|
return int(i)
|
|
|
|
except Exception:
|
|
|
|
return 0
|
2012-05-01 21:15:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
def version_key(version):
|
|
|
|
version = version.version
|
|
|
|
try:
|
|
|
|
return StrictVersion(version)
|
|
|
|
# in case of abnormal version number, fall back to LooseVersion
|
|
|
|
except ValueError:
|
|
|
|
return LooseVersion(version)
|
|
|
|
|
|
|
|
|
|
|
|
def packages_from_names(data):
|
|
|
|
"""
|
|
|
|
Returns a list of Package objects from a string of names
|
|
|
|
"""
|
2012-05-05 10:02:17 +02:00
|
|
|
|
|
|
|
from djeuscan.models import Package
|
|
|
|
|
2012-05-01 21:15:55 +02:00
|
|
|
packages = []
|
|
|
|
data = data.replace("\r", "")
|
|
|
|
|
|
|
|
for pkg in data.split('\n'):
|
|
|
|
if '/' in pkg:
|
|
|
|
cat, pkg = pkg.split('/')
|
|
|
|
packages.extend(Package.objects.filter(category=cat, name=pkg))
|
|
|
|
else:
|
|
|
|
packages.extend(Package.objects.filter(name=pkg))
|
|
|
|
return packages
|