Merge lp:~sil2100/langpack-o-matic/multi_merge into lp:langpack-o-matic

Proposed by Łukasz Zemczak
Status: Merged
Merged at revision: 545
Proposed branch: lp:~sil2100/langpack-o-matic/multi_merge
Merge into: lp:langpack-o-matic
Diff against target: 96 lines (+47/-31)
1 file modified
merge-tarballs (+47/-31)
To merge this branch: bzr merge lp:~sil2100/langpack-o-matic/multi_merge
Reviewer Review Type Date Requested Status
Martin Pitt (community) Approve
Review via email: mp+271954@code.launchpad.net

Commit message

Modify the merge-tarballs to merge in multiple tarballs together, not limited to 2. This is useful for cases such as ubuntu-touch 15.04 series where we need to merge vivid full, vivid delta and the overlay.

Description of the change

Modify the merge-tarballs to merge in multiple tarballs together, not limited to 2. This is useful for cases such as ubuntu-touch 15.04 series where we need to merge vivid full, vivid delta and the overlay.

To post a comment you must log in.
Revision history for this message
Martin Pitt (pitti) wrote :

Some nits wrt. the temp dir cleanup. Thanks!

review: Needs Fixing
546. By Łukasz Zemczak

Try to deal with the issues rised by Martin

547. By Łukasz Zemczak

Fix indent

Revision history for this message
Łukasz Zemczak (sil2100) wrote :

How about something like this for now?

Revision history for this message
Martin Pitt (pitti) wrote :

OK, thanks. I still hate that code (it's massively inefficient and hard to understand -- not your fault, but mine back then), but let's unblock this for now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'merge-tarballs'
2--- merge-tarballs 2011-07-21 13:08:42 +0000
3+++ merge-tarballs 2015-09-22 16:18:04 +0000
4@@ -2,45 +2,61 @@
5
6 # this is part of langpack-o-matic, by Martin Pitt <martin.pitt@canonical.com>
7 #
8-# (C) 2005 Canonical Ltd.
9+# (C) 2005-2015 Canonical Ltd.
10 #
11-# Merge two translation tarballs.
12+# Merge multiple translation tarballs.
13
14-[ "$1" -a "$2" -a "$3" ] || {
15- echo "Usage: $0 <input tarball 1> <input tarball 2> <output tarball>" >&2
16+[ $# -lt 3 ] && {
17+ echo "Usage: $0 <input tarball 1> <input tarball 2> ... <input tarball n> <output tarball>" >&2
18 exit 1
19 }
20
21-T1=$(mktemp -d)
22-T2=$(mktemp -d)
23-
24-trap "rm -rf $T1 $T2" 0 1 2 3 13 15
25-
26-tar -C $T1 -xz < "$1"
27-tar -C $T2 -xz < "$2"
28-
29-TOP1="$T1/$(ls "$T1")"
30-TOP2="$T2/$(ls "$T2")"
31-
32-if echo "$3" | grep -q '^/'; then
33+TD=$(mktemp -d)
34+# initial trap for script interruption
35+trap "rm -rf $TD" 0 1 2 3 13 15
36+
37+# extract the first tarball - all others will be merged sequentially into that one
38+tar -C $TD -xz < "$1"
39+shift 1
40+TOPD="$TD/$(ls "$TD")"
41+cp "$TOPD/mapping.txt" "$TOPD/mapping.txt.merged"
42+MAIN=`pwd`
43+
44+TS=$(mktemp -d)
45+trap "rm -rf $TD $TS" 0 1 2 3 13 15
46+
47+while [ "$#" != "1" ]; do
48+ tar -C $TS -xz < "$1"
49+ TOPS="$TS/$(ls "$TS")"
50+
51+ # copy PO and POT files
52+ cd "$TOPS"
53+ find \( -name "*.po" -o -name "*.pot" \) -exec install -D -m 644 '{}' "$TOPD/{}" \;
54+
55+ # timestamp
56+ cp "$TOPS/timestamp.txt" "$TOPD"
57+
58+ # append domain maps
59+ cat "$TOPS/mapping.txt" >> "$TOPD/mapping.txt"
60+
61+ shift 1
62+ cd $MAIN
63+ rm -rf $TS/*
64+done
65+
66+# merge the domain maps
67+sort -u "$TOPD/mapping.txt.merged" > "$TOPD/mapping.txt"
68+
69+rmdir $TS
70+
71+if echo "$1" | grep -q '^/'; then
72 # absolute path
73- OUT="$3"
74+ OUT="$1"
75 else
76 # relative path
77- OUT="$(pwd)/$3"
78+ OUT="$(pwd)/$1"
79 fi
80
81-# copy PO and POT files
82-cd "$TOP2"
83-find \( -name "*.po" -o -name "*.pot" \) -exec install -D -m 644 '{}' "$TOP1/{}" \;
84-
85-# timestamp
86-cp "$TOP2/timestamp.txt" "$TOP1"
87-
88-# merge domain maps
89-cat "$TOP1/mapping.txt" "$TOP2/mapping.txt" | sort -u > "$TOP1/mapping.txt.merged"
90-mv "$TOP1/mapping.txt.merged" "$TOP1/mapping.txt"
91-
92-# create new tarball
93-cd "$T1"
94+cd "$TD"
95 tar c . | gzip -9 > "$OUT"
96+

Subscribers

People subscribed via source and target branches