2 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
4 # This file is part of the LibreOffice project.
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 # Extract a mar file and uncompress the content
17 from path
import convert_to_native
19 def uncompress_content(file_path
):
20 bzip2
= os
.environ
.get('BZIP2', 'bzip2')
21 file_path_compressed
= file_path
+ ".bz2"
22 os
.rename(file_path
, file_path_compressed
)
23 subprocess
.check_call(["bzip2", "-d", convert_to_native(file_path_compressed
)])
25 def extract_mar(mar_file
, target_dir
):
26 mar
= os
.environ
.get('MAR', 'mar')
27 subprocess
.check_call([mar
, "-C", convert_to_native(target_dir
), "-x", convert_to_native(mar_file
)])
28 file_info
= subprocess
.check_output([mar
, "-t", convert_to_native(mar_file
)])
29 lines
= file_info
.splitlines()
30 prog
= re
.compile("\d+\s+\d+\s+(.+)")
32 match
= prog
.match(line
.decode("utf-8", "strict"))
35 info
= match
.groups()[0]
40 uncompress_content(os
.path
.join(target_dir
, info
))
43 if len(sys
.argv
) != 3:
44 print("Help: This program takes exactly two arguments pointing to a mar file and a target location")
47 mar_file
= sys
.argv
[1]
48 target_dir
= sys
.argv
[2]
49 extract_mar(mar_file
, target_dir
)
51 if __name__
== "__main__":
54 # vim: set shiftwidth=4 softtabstop=4 expandtab: