-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathddgen.py
More file actions
executable file
·60 lines (50 loc) · 2.35 KB
/
Copy pathddgen.py
File metadata and controls
executable file
·60 lines (50 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
import argparse
from ddelta import ddelta
import sys
from os import stat
from time import monotonic
""" ddgen
Given one specific version of a package pkg_v1.deb and a delta container, generate
the target package pkg_v2.deb allowing upload to the destination only the differences
between the old version and the new version.
In the destination is necessary rebuild the current package using dpkg-repack
and this tool for applying the delta container to it.
"""
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='debian package minimization tool for low bandwidth xfers')
parser.add_argument('-s', "--source", default=None, help="Source path from package to be used as original package")
parser.add_argument('-t', "--target", default=None, help="Target path from package to be used as final package")
parser.add_argument('-v', "--verbose", action="store_true", help="Prints a more vebose detail of the process, summary and performance")
args = parser.parse_args()
if args.source and args.target:
init_t = monotonic()
delta_name = ddelta.delta_get_friendly_name(args.source, args.target)
result = ddelta.delta_prepare_ddelta_xfer(args.source, args.target, delta_name)
if args.verbose:
source_size = stat(args.source).st_size
target_size = stat(args.target).st_size
ddelta_xfer = stat(result).st_size
rate = ddelta_xfer / source_size
gain = source_size - ddelta_xfer
gain_rate = '{}'.format('+' if gain > 0 else '-')
print("================= SUMMARY STATS ====================\n\t" \
"- Source Size:\t{} bytes\n\t" \
"- Target Size:\t{} bytes\n\t" \
"- Ddelta Xfer:\t{} bytes\n\t" \
"- Total gain:\t{} bytes\n\t" \
"- Gain rate:\t{}{:.2f}%\n\t" \
"- Time Took:\t{:.2f} seconds\n" \
"================= SUMMARY STATS ====================".format(
source_size,
target_size,
ddelta_xfer,
gain,
gain_rate,
rate * 100,
monotonic() - init_t
))
print(result)
else:
print("Missing arguments for generating package delta: ", args)
sys.exit(1)