因爲bzr info "$branch"
和bzr ls -d "$branch" "$directory"
沒有提供足夠的信息給我,所以我最終對HTTP響應做了一些髒抹掉。
下面的Bash腳本依賴於Launchpads前端Loggerhead的工作。它遞歸地從給定的URL下載。目前,它忽略了*.run
文件。將其另存爲bzrdl
在$PATH
可用的目錄中,並使用bzrdl http://launchpad.net/~ubuntu-branches/ubuntu/oneiric/nvidia-graphics-drivers/oneiric/files/head:/debian/
運行它。所有文件將保存在當前目錄中,確保它是空的以避免衝突。
#!/bin/bash
max_retries=5
rooturl="$1"
if ! [[ $rooturl =~ /$ ]]; then
echo "Usage: ${0##*/} URL"
echo "URL must end with a slash. Example URL:"
echo "http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/oneiric/nvidia-graphics-drivers/oneiric/files/head:/"
exit 1
fi
tmpdir="$(mktemp -d)"
target="$(pwd)"
# used for holding HTTP response before extracting data
tmp="$(mktemp)"
# url_filter reads download URLs from stdin (piped)
url_filter() {
grep -v '\.run$'
}
get_files_from_dir() {
local slash=/
local dir="$1"
# to avoid name collision: a/b/c/ -> a.d/b.d/c.d/
local storedir="${dir//$slash/.d${slash}}"
mkdir -p "$tmpdir/$storedir" "$target/$dir"
local i subdir
for ((i=0; i<$max_retries; i++)); do
if wget -O "$tmp" "$rooturl$dir"; then
# store file list
grep -F -B 1 '<img src="/static/images/ico_file_download.gif" alt="Download File" />' "$tmp" |\
grep '^<a' | cut -d '"' -f 2 | url_filter \
> "$tmpdir/$storedir/files"
IFS=$'\n'
for subdir in $(grep -F -B 1 '<img src="/static/images/ico_folder.gif" ' "$tmp" | \
grep -F '<a ' | rev | cut -d/-f 2 | rev); do
IFS=$' \t\n'
get_files_from_dir "$dir$subdir/"
done
return
fi
done
echo "Failed to download directory listing of: $dir" >> "$tmpdir/errors"
}
download_files() {
local slash=/
local dir="$1"
# to avoid name collision: a/b/c/ -> a.d/b.d/c.d/
local storedir="${dir//$slash/.d${slash}}"
local done=false
local subdir
cd "$tmpdir/$storedir"
for ((i=0; i<$max_retries; i++)); do
if wget -B "$rooturl$dir" -nc -i files -P "$target/$dir"; then
done=true
break
fi
done
$done || echo "Failed to download all files from $dir" >> "$tmpdir/errors"
for subdir in *.d; do
download_files "$dir${subdir%%.d}/"
done
}
get_files_from_dir ''
# make *.d expand to nothing if no directories are found
shopt -s nullglob
download_files ''
echo "TMP dir: $tmpdir"
echo "Errors : $(wc -l "$tmpdir/errors" 2>/dev/null | cut -d ' ' -f 2 || echo 0)"
的臨時目錄和文件事後又沒有刪除,必須手動完成。任何錯誤(故障下載)將被寫入$tmpdir/errors
它證實了工作:
bzrdl http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/oneiric/nvidia-settings/oneiric/files/head:/debian/
隨時糾正任何錯誤或增加改進。
現在我想'--lightweight'和文件大小雖然仍然大約爲280MB(磁盤上的實際大小:61M),但文件大小已經大大減小。我仍然在尋找一種忽略這些文件的替代方法。是否有可能使用類似'bzr cat lp:ubuntu/nvidia-graphics-drivers/debian/control'來從存儲庫檢索某些文件? – Lekensteyn
我相信你也可以直接從Launchpad做到這一點。它不是讓你從存儲庫下載單個文件嗎?但是,是的,看起來像'貓的bzr -d'也應該這樣做,雖然我還沒有嘗試過 –
jalf
我問錯了問題的意見,LP允許個人下載,但因爲我想比較整個目錄,手動下載這些工作太多了。出於某種原因,每次操作嘗試下載完整的樹或東西('的bzr貓LP:Ubuntu的/ NVIDIA顯卡的驅動程序/於Debian/control')。下次我將使用wget。 – Lekensteyn