Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45dbc6b

Browse files
committed
ENH : made download update script smarter
The files for 1.4.1 are sorted into sub-folders, this broke the update download script. Fixed the script and made the template a bit smarter to sort downloads by platform.
1 parent 3c8ba04 commit 45dbc6b

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

downloads.tpl.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,20 @@ <h3>Navigation</h3>
3333

3434
<h1>Downloads</h1>
3535

36-
{% for version, description, version_files in files %}
36+
{% for version, description, download_files in files %}
3737
<h2>{{version}} — {{description}}</h2>
3838

39+
{% for platform_name, platform_files in download_files %}
40+
{% if platform_files|length > 0 %}
41+
<h3>{{ platform_name }}</h3>
3942
<ul>
40-
{% for file in version_files %}
41-
<li><a href="https://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-{{version}}/{{file}}">{{file}}</a></li>
43+
{% for path, label in platform_files %}
44+
<li><a href="https://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-{{version}}/{{path}}">{{label}}</a></li>
4245
{% endfor %}
4346
</ul>
47+
{% endif %}
48+
{% endfor %}
49+
4450
{% endfor %}
4551

4652
<h2>Other downloads</h2>

update_downloads.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import sys
1717
import traceback
1818

19+
import cPickle
1920

2021
# CONSTANTS
2122
hostname = 'frs.sourceforge.net'
@@ -63,10 +64,20 @@ def get_hostkey_and_type(hostname):
6364

6465
def get_files_for_version(sftp, version):
6566
sftp.chdir(dir_template.format(version))
66-
return sftp.listdir()
67+
base_files = set(sftp.listdir())
68+
for folder in ('mac', 'windows'):
69+
try:
70+
base_files.remove(folder)
71+
sftp.chdir(dir_template.format(version) + '/' + folder)
72+
base_files |= set(folder + '/' + _ for _ in sftp.listdir())
73+
74+
except KeyError:
75+
continue
76+
return list(base_files)
6777

6878

6979
def get_file_listings(hostname, username, password, hostkey, versions):
80+
7081
files = []
7182

7283
try:
@@ -93,13 +104,23 @@ def generate_download_page(files):
93104
stream.dump(fd)
94105

95106

107+
def split_file_listing(input_list):
108+
source = [(_, _) for _ in input_list if 'tar' in _]
109+
mac = [(_, _.split('/', 1)[-1]) for _ in input_list if 'mac' in _]
110+
win = [(_, _.split('/', 1)[-1]) for _ in input_list if 'win' in _]
111+
return ('Source', source), ('Windows', win), ('OSX', mac)
112+
113+
96114
def main():
97115
versions = get_versions()
98116

99117
username, password = get_username_and_password(hostname)
100118
hostkey, hostkeytype = get_hostkey_and_type(hostname)
101119

102-
files = get_file_listings(hostname, username, password, hostkey, versions)
120+
files = get_file_listings(hostname, username,
121+
password, hostkey, versions)
122+
123+
files = [(a, b, split_file_listing(c)) for a, b, c in files]
103124

104125
generate_download_page(files)
105126

0 commit comments

Comments
 (0)