hg-website-test / original / hgscm / apps / www / models.py

from django.db import models
from django.utils import simplejson
from django.conf import settings
import os, re

def get_download(platform, version):
    '''get the download for the right version'''
    f = open(os.path.join(settings.MEDIA_ROOT, "downloads.json"))
    list = simplejson.load(f)
    f.close()
    latest = version == 'latest' or not version
    for entry in list:
        if (latest and entry['latest'] == 'true') or entry['version'] == version:
            for version in entry['versions']:
                if version['identifier'] == platform:
                    return version
def get_download_for_agent(agent, version):
    '''get the download for the right version'''
    f = open(os.path.join(settings.MEDIA_ROOT, "downloads.json"))
    list = simplejson.load(f)
    f.close()
    latest = version == 'latest' or not version
    for entry in list:
        if (latest and entry['latest'] == 'true') or entry['version'] == version:
            for version in entry['versions']:
                if re.search(version['system'], agent):
                    return version

def get_latest_version():
    '''return the latest available version'''
    f = open(os.path.join(settings.MEDIA_ROOT, "downloads.json"))
    list = simplejson.load(f)
    f.close()
    for entry in list:
        if entry['latest'] == 'true':
            return entry['version']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.