diff options
Diffstat (limited to 'python/gentoo_www/views.py')
-rw-r--r-- | python/gentoo_www/views.py | 205 |
1 files changed, 0 insertions, 205 deletions
diff --git a/python/gentoo_www/views.py b/python/gentoo_www/views.py deleted file mode 100644 index 9984309..0000000 --- a/python/gentoo_www/views.py +++ /dev/null @@ -1,205 +0,0 @@ -# Copyright 1998-2015 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 - -from django.shortcuts import render, get_object_or_404, HttpResponseRedirect -from django.conf import settings - -from gentoo_www.models import SiteSettings, Layout, Pages, SubPages, Sponsors, Posts - -import feedparser -import urllib3 -import re - -# drv_libxml2 have a error with feedparser we work around it for now -feedparser.PREFERRED_XML_PARSERS.remove('drv_libxml2') - -def default_TmpDict(pagerequest): - site = get_object_or_404(SiteSettings) - page = get_object_or_404(Pages, nav1 = pagerequest) - pages = Pages.objects.all() - if page.SubMenu: - subpages = SubPages.objects.filter(PageId = page.PageId) - else: - subpages = False - contact = get_object_or_404(SubPages, nav2 = 'contact') - TmpDict = {'site' : site} - TmpDict['page'] = page - TmpDict['pages'] = pages - TmpDict['subpages'] = subpages - TmpDict['contact'] = contact - TmpDict['smappages'] = SubPages.objects.all() - return TmpDict - -def home(request): - pagerequest = 'home' - TmpDict = default_TmpDict(pagerequest) - - showposts = 5 - posts = Posts.objects.all() - sponsors = Sponsors.objects.all() - pp = feedparser.parse('https://planet.gentoo.org/rss20.xml') - planetposts = [] - i = 0 - for ppost in pp['entries']: - if i is showposts: - break - attr = {} - attr['author'] = ppost['author'] - attr['url'] = ppost['link'] - attr['title'] = ppost['title'] - attr['published'] = ppost['published'] - planetposts.append(attr) - i = i + 1 - gp = feedparser.parse('https://security.gentoo.org/glsa/feed.rss') - glsaposts = [] - i = 0 - for gpost in gp['entries']: - if i is showposts: - break - split_title = re.split(': ', gpost['title']) - attr = {} - attr['id'] = split_title[0] - attr['url'] = gpost['link'] - attr['title'] = split_title[1] + ': ' + split_title[2] - attr['severity'] = 'normal' - glsaposts.append(attr) - i = i + 1 - - pkp = feedparser.parse('https://packages.gentoo.org/feed/') - packageposts = [] - i = 0 - for ppost in pkp['entries']: - if i is showposts: - break - split_title = re.split(': ', ppost['title']) - attr = {} - attr['url'] = ppost['links'][0]['href'] - attr['atom'] = re.sub('<span class="cpvstr">', '', re.sub('</span>', '', split_title[0])) - attr['atom_p'] = attr['atom'] - attr['description'] = re.sub('<span class="description">', '', re.sub('</span>', '', split_title[1])) - packageposts.append(attr) - i = i + 1 - - wp = feedparser.parse('https://wiki.gentoo.org/index.php?title=Special:NewPages&feed=rss&hidebots=1&hideredirs=1&limit=50&offset=&namespace=0&username=&tagfilter=') - wikiposts = [] - i = 0 - for wpost in wp['entries']: - if i is showposts: - break - attr = {} - attr['author'] = wpost['author'] - attr['url'] = wpost['link'] - attr['title'] = wpost['title'] - wikiposts.append(attr) - i = i + 1 - TmpDict['posts'] = posts - TmpDict['sponsors'] = sponsors - TmpDict['planetposts'] = planetposts - TmpDict['glsaposts'] = glsaposts - TmpDict['packageposts'] = packageposts - TmpDict['wikiposts'] = wikiposts - return render(request, 'pages/' + pagerequest + '/index.html', TmpDict) - -def downloads(request): - pagerequest = 'downloads' - http = urllib3.PoolManager() - archlist = [] - #FIXME get arch list from db - archlist.append('amd64') - archlist.append('x86') - #archlist.append('ia64') - downloads_dict = {} - for arch in archlist: - # Stage3 - r = http.request('GET', 'http://distfiles.gentoo.org/releases/' + arch + '/autobuilds/latest-stage3.txt') - rlines = re.split('\n', r.data.decode('utf-8')) - attr2 = {} - i = 0 - stage3list = [] - for line in rlines: - if line == '': - break - if i >= 2: - attr = {} - attr['tag'] = '' - attr['defaultstage'] = False - attr['title'] = 'Stage 3' - split1 = re.split(' ', line) - attr['size'] = split1[1] - attr['link'] = split1[0] - split2 = re.split('/', split1[0], maxsplit=1) - attr['date'] = split2[0] - if '/' in split2[1]: - split3 = re.split('/', split2[1]) - stage3id = re.split('-' + attr['date'] + '.tar.bz2', re.split('stage3-', split3[1])[1])[0] - else: - stage3id = re.split('-' + attr['date'] + '.tar.bz2', re.split('stage3-', split2[1])[1])[0] - if re.search('nomultilib', stage3id): - attr['tag'] = 'no multilib' - elif re.search('uclibc', stage3id): - attr['tag'] = 'uclibc' - elif re.search('x32', stage3id): - attr['tag'] = 'X32' - else: - if arch == 'x86': - if re.search('i686', stage3id): - attr['defaultstage'] = True - attr['tag'] = 'i686' +'|' + attr['tag'] - if re.search('i486', stage3id): - attr['tag'] = 'i486' +'|' + attr['tag'] - else: - attr['tag'] = False - else: - attr['tag'] = False - attr['defaultstage'] = True - if re.search('hardened', stage3id): - attr['title'] = 'Hardened ' + attr['title'] - attr['defaultstage'] = False - attr['id'] = stage3id - stage3list.append(attr) - i = i + 1 - attr2['stage3s'] = stage3list - # cd's - r = http.request('GET', 'http://distfiles.gentoo.org/releases/' + arch + '/autobuilds/latest-iso.txt') - rlines = re.split('\n', r.data.decode('utf-8')) - isolist = [] - i = 0 - for line in rlines: - if line == '': - break - if i >= 2: - attr = {} - split1 = re.split(' ', line) - attr['size'] = split1[1] - attr['link'] = split1[0] - split2 = re.split('/', split1[0], maxsplit=1) - attr['date'] = split2[0] - if re.search('/', split2[1]): - split3 = re.split('/', split2[1]) - if re.search('/', split2[1]): - split3 = re.split('/', split2[1]) - cdid = re.split('-' + attr['date'] + '.iso', split3[1])[0] - else: - cdid = re.split('-' + attr['date'] + '.iso', split2[1])[0] - if re.search('minimal', cdid): - attr['id'] = 'minimal' - attr['title'] = 'Minimal Installation CD' - elif re.search('admincd', cdid): - attr['id'] = 'admincd' - attr['title'] = 'Admin CD' - else: - attr['id'] = '' - attr['title'] = '' - isolist.append(attr) - i = i +1 - attr2['isos'] = isolist - attr2['arch'] = arch - if arch == 'amd64': - attr2['aka'] = 'x86_64' - else: - attr2['aka'] = False - downloads_dict[arch] = attr2 - TmpDict = default_TmpDict(pagerequest) - print(downloads_dict) - TmpDict['downloadsinfo'] = downloads_dict - return render(request, 'pages/' + pagerequest + '/index.html', TmpDict) |