root/web/cherokee-last-tarball

Revision 1626, 1.4 kB (checked in by alo, 2 months ago)

--

  • Property svn:executable set to *
Line 
1 #!/usr/bin/env python
2
3 # Alvaro Lopez Ortega <alvaro@gnu.org>
4 # http://www.cherokee-project.com
5 #
6
7 import os
8 import re
9
10 LOCAL_PATH = "/var/www/www.cherokee-project.com/download/"
11 URL        = "http://www.cherokee-project.com/download/"
12 REGEX      = 'cherokee-([0-9]+)\.([0-9]+)\.([0-9]+).tar.gz'
13
14 os.chdir(LOCAL_PATH)
15
16 regex  = re.compile(REGEX)
17 newest = ((0,0,0), None)
18
19 def scan_directory (directory):
20     global regex
21     global newest
22    
23     for f in os.listdir(directory):
24         fullpath = os.path.join(directory, f)
25
26         if f != "." and f != ".." and os.path.isdir(fullpath):
27             scan_directory (fullpath)
28
29         match = regex.search (f)
30         if match is not None:
31             greater = False
32             v1, v2, v3 = map (lambda x: int(x), match.groups())
33
34             if (newest[0][0] < v1):
35                 greater = True
36             elif (newest[0][0] == v1):
37                 if (newest[0][1] < v2):
38                     greater = True
39                 elif (newest[0][1] == v2):
40                     if (newest[0][2] < v3):
41                         greater = True
42
43             if greater:
44                 newest = ((v1,v2,v3), fullpath[len(LOCAL_PATH):])
45
46
47 def main():
48     global newest
49
50     scan_directory (LOCAL_PATH)
51     if newest[1] == None:
52         print "Status: 500\r\n\r\n",
53         raise SystemExit
54
55     print "Status: 302\r\n",
56     print "Location: %s%s\r\n\r\n" % (URL, newest[1])
57
58
59 if __name__ == "__main__":
60     main()
Note: See TracBrowser for help on using the browser.