annotate sat_website/utils.py @ 1:a49aa1b823f6

added SàT archive download link (detect the last version)
author Goffi <goffi@goffi.org>
date Sun, 29 Jul 2012 01:52:27 +0200
parents
children 31d196cf3b34
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
3 """
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
4 SàT website: Salut à Toi's presentation website
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Copyright (C) 2012 Jérôme Poisson (goffi@goffi.org)
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
6
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
7 This file is part of SàT website.
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
8
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
9 SàT website is free software: you can redistribute it and/or modify
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
10 it under the terms of the GNU Affero General Public License as published by
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
11 the Free Software Foundation, either version 3 of the License, or
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
12 (at your option) any later version.
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
13
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
14 Foobar is distributed in the hope that it will be useful,
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
17 GNU Affero General Public License for more details.
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
18
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
19 You should have received a copy of the GNU Affero General Public License
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
20 along with Foobar. If not, see <http://www.gnu.org/licenses/>.
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
21 """
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
22
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from os.path import basename,realpath,join
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from django.conf import settings
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
25
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
26 def get_latest_sat():
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
27 """Return a tuple with download path of latest SàT version, and version number"""
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
28 try:
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
29 path = settings.SAT_LINK_PATH
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
30 real_path = realpath(path)
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
31 filename = basename(real_path)
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
32 version = filename[4:-8] #filename must be in the form of sat-version.tar.bz2
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
33 if hasattr(settings, "SAT_DL_PATH"):
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
34 dl_path = settings.SAT_DL_PATH
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
35 else:
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
36 dl_path = join(settings.SAT_DL_PREFIX, filename)
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
37 except AttributeError:
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
38 return (None, None)
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
39
a49aa1b823f6 added SàT archive download link (detect the last version)
Goffi <goffi@goffi.org>
parents:
diff changeset
40 return (dl_path, version)