6 def uncompress_file_to_dir(compressed_file
, uncompress_dir
):
8 extension
= os
.path
.splitext(compressed_file
)[1]
11 os
.mkdir(uncompress_dir
)
12 except FileExistsError
as e
:
15 if extension
== '.gz':
16 tar
= tarfile
.open(compressed_file
)
17 tar
.extractall(uncompress_dir
)
19 elif extension
== '.zip':
20 zip_file
= zipfile
.ZipFile(compressed_file
)
21 zip_file
.extractall(uncompress_dir
)
24 uncompress_dir
= os
.path
.join(uncompress_dir
, os
.listdir(uncompress_dir
)[0])
25 if " " in os
.listdir(uncompress_dir
)[0]:
26 print("replacing whitespace in directory name")
27 os
.rename(os
.path
.join(uncompress_dir
, os
.listdir(uncompress_dir
)[0]),
28 os
.path
.join(uncompress_dir
, os
.listdir(uncompress_dir
)[0].replace(" ", "_")))
30 print("Error: unknown extension " + extension
)
32 return os
.path
.join(uncompress_dir
, os
.listdir(uncompress_dir
)[0])
36 def get_hash(file_path
):
37 sha512
= hashlib
.sha512()
38 with
open(file_path
, 'rb') as f
:
40 data
= f
.read(BUF_SIZE
)
44 return sha512
.hexdigest()
46 def get_file_info(mar_file
, url
):
47 filesize
= os
.path
.getsize(mar_file
)
48 data
= { 'hash' : get_hash(mar_file
),
49 'hashFunction' : 'sha512',
51 'url' : url
+ os
.path
.basename(mar_file
)}
55 def replace_variables_in_string(string
, **kwargs
):
57 for key
, val
in kwargs
.items():
58 new_string
= new_string
.replace('$(%s)'%key
, val
)
62 def make_complete_mar_name(target_dir
, filename_prefix
):
63 filename
= filename_prefix
+ "_complete.mar"
64 return os
.path
.join(target_dir
, filename
)