@@ -31,8 +31,8 @@ def dir_path(path):
31
31
32
32
33
33
def build_archive (input_dir , destination_dir , archive_basename ):
34
- input_files = os .listdir (args . input )
35
- print (f"packing mithril distribution { args . version } - { args . target } with files: { input_files } " )
34
+ input_files = os .listdir (input_dir )
35
+ print (f"packing { archive_basename } with files: { input_files } " )
36
36
37
37
if platform .system () == "Windows" :
38
38
import zipfile
@@ -53,10 +53,10 @@ def build_archive(input_dir, destination_dir, archive_basename):
53
53
return archive_name
54
54
55
55
56
- def check_archive (archive , original_input_dir ):
56
+ def check_archive (archive_path , original_input_dir ):
57
57
print (f"checking archive ..." )
58
58
test_dir = "./unpack-test"
59
- shutil .unpack_archive (archive , test_dir )
59
+ shutil .unpack_archive (archive_path , test_dir )
60
60
original_checksum = sha256sum (original_input_dir )
61
61
archive_content_checksum = sha256sum (test_dir )
62
62
if original_checksum != archive_content_checksum :
@@ -69,23 +69,30 @@ def check_archive(archive, original_input_dir):
69
69
shutil .rmtree (test_dir )
70
70
71
71
72
- def compute_sha256_checksum (archive ):
72
+ def compute_sha256_checksum (archive_path ):
73
73
print (f"computing archive checksum..." )
74
- archive_checksum = sha256sum (archive )
75
- checksum_filename = f"{ archive } .sha256"
74
+ archive_checksum = sha256sum (archive_path )
75
+ checksum_filename = f"{ archive_path } .sha256"
76
76
with open (checksum_filename , "x" ) as f :
77
77
f .write (archive_checksum )
78
78
79
79
80
+ def main (args ):
81
+ archive_path = build_archive (args .input , args .dest , archive_basename = f"mithril-{ args .version } -{ args .target } " )
82
+ check_archive (archive_path , args .input )
83
+ compute_sha256_checksum (archive_path )
84
+
85
+
80
86
if __name__ == '__main__' :
81
- parser = argparse .ArgumentParser ()
87
+ parser = argparse .ArgumentParser (
88
+ prog = "Mithril distribution packager" ,
89
+ description = "Package the files in the given '--input' dir in a .tar.gz (linux, macOs) or .zip (windows)"
90
+ " plus add a file with the value the sha256 of the generated package."
91
+ )
82
92
parser .add_argument ("--input" , type = dir_path , help = "input folder which content will be archived" , required = True )
83
93
parser .add_argument ("--dest" , type = dir_path , help = "destination folder for the archive, default to current folder" ,
84
94
default = "./" )
85
95
parser .add_argument ("--version" , help = "version of the distribution to package" , required = True )
86
96
parser .add_argument ("--target" , help = "target os & architecture of the package" , required = True )
87
- args = parser .parse_args ()
88
97
89
- archive_path = build_archive (args .input , args .dest , archive_basename = f"mithril-{ args .version } -{ args .target } " )
90
- check_archive (archive_path , args .input )
91
- compute_sha256_checksum (archive_path )
98
+ main (parser .parse_args ())
0 commit comments