-
-
Save jn7163/97169e612a1b74703458fcea34b425d6 to your computer and use it in GitHub Desktop.
Cache all packages from OpenWrt trunk repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#coding=utf-8 | |
# | |
# Openwrt Package Grabber | |
# | |
# Copyright (C) 2014 http://www.shuyz.com | |
# | |
import urllib2 | |
import re | |
import os | |
# the url of package list page, end with "/" | |
baseurl = 'http://downloads.openwrt.org/snapshots/trunk/ar71xx/packages/' | |
# which directory to save all the packages, end with "/" | |
savedir = './download/' | |
if not os.path.exists(savedir): | |
os.makedirs(savedir) | |
print 'fetching package list from ' + baseurl | |
content = urllib2.urlopen(baseurl, timeout=15).read() | |
print 'packages list ok, analysing...' | |
pattern = r'<a href="(.*?)">' | |
items = re.findall(pattern, content) | |
cnt = 0 | |
for item in items: | |
if item == '../': | |
continue | |
else: | |
cnt += 1 | |
print 'downloading item %d: '%(cnt) + item | |
if os.path.isfile(savedir + item): | |
print 'file exists, ignored.' | |
else: | |
rfile = urllib2.urlopen(baseurl + item) | |
with open(savedir + item, "wb") as code: | |
code.write(rfile.read()) | |
print 'done!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment