@@ -110,7 +110,7 @@ def __init__(
110110 exit (1 )
111111
112112 # Try to read the manifest
113- if os .path .exists (self .manifest_path ):
113+ if os .path .exists (self .manifest_path ) and id == None :
114114 with open (self .manifest_path , "r" ) as file :
115115 manifest = json .loads (file .read ())
116116 self .manifest_version = manifest ["manifest_version" ]
@@ -119,21 +119,21 @@ def __init__(
119119 self .name = manifest ["name" ]
120120 self .author = manifest ["author" ]
121121 self .description = manifest ["description" ]
122- self .version = Version .decode (self . manifest ["version" ])
122+ self .version = Version .decode (manifest ["version" ])
123123
124124 self .dependencies = []
125- for dependency in self . manifest ["dependencies" ]:
125+ for dependency in manifest ["dependencies" ]:
126126 self .dependencies .append (Dependency .decode (dependency ))
127127
128- self .supported_platforms = set ( manifest ["supported_platforms" ])
128+ self .supported_platforms = manifest ["supported_platforms" ]
129129 else :
130130 self .id = id
131131 self .name = name
132132 self .author = author
133133 self .description = description
134134 self .version = version
135135 self .dependencies = dependencies
136- self .supported_platforms = set ( supported_platforms )
136+ self .supported_platforms = supported_platforms
137137 self .validate ()
138138
139139 def set_id (self , id : str ):
@@ -177,16 +177,17 @@ def remove_supported_platform(self, platform: str):
177177 self .supported_platforms .remove (platform )
178178
179179 def validate (self ):
180- assert self .manifest != None
180+ invalid_id = False
181+ for letter in self .id :
182+ if letter .isspace () or letter .isupper ():
183+ invalid_id = True
184+ if not (letter .isascii () or letter in ['-' , '_' ]):
185+ invalid_id = True
181186
182- for c in self .manifest ["id" ]:
183- c : str
184- if c .isascii () and (c .isnumeric () or c .isalpha ()) and (not c .isspace ()):
185- continue
186- else :
187- raise RuntimeError (
188- "Package manifest id must be alphanumeric with no symbols or whitespaces"
189- )
187+ if invalid_id :
188+ raise RuntimeError (
189+ "id must only contain alphanumeric characters, or _ and -"
190+ )
190191
191192 for supported_platform in self .supported_platforms :
192193 if not supported_platform in valid_supported_platforms :
@@ -213,9 +214,9 @@ def write_manifest(self):
213214 manifest ["dependencies" ].append (dependency .encode ())
214215
215216 if self .supported_platforms != None :
216- manifest ["supported_platforms" ] = self .supported_platforms
217+ manifest ["supported_platforms" ] = list ( self .supported_platforms )
217218
218- file .write (json .dumps (manifest ))
219+ file .write (json .dumps (manifest , indent = 2 ))
219220
220221 def pack (self , output_path : str , compression : int = 5 ):
221222 self .write_manifest ()
@@ -229,7 +230,7 @@ def pack(self, output_path: str, compression: int = 5):
229230 if os .path .isdir (packageFilename ):
230231 packageFilename = os .path .join (
231232 output_path ,
232- f"{ self .id } _{ '.' . join ( str ( x ) for x in self .version ) } _{ '-' .join (self .supported_platforms if self .supported_platforms else ["kindleany" ])} .kpkg" ,
233+ f"{ self .id } _{ self .version } _{ '-' .join (self .supported_platforms if self .supported_platforms else ["kindleany" ])} .kpkg" ,
233234 )
234235
235236 if compression == 0 :
@@ -424,7 +425,7 @@ def write_manifest(self):
424425 "url" : artifact .url ,
425426 "version" : Version .encode (artifact .version ),
426427 "dependencies" : [],
427- "supported_platforms" : artifact .supported_platforms ,
428+ "supported_platforms" : list ( artifact .supported_platforms ) ,
428429 }
429430 for dependency in artifact .dependencies :
430431 encoded_artifact ["dependencies" ].append (Dependency .encode (dependency ))
@@ -450,6 +451,7 @@ def get_id():
450451 raise RuntimeError (
451452 "id must only contain alphanumeric characters, or _ and -"
452453 )
454+ return id
453455
454456 parser = argparse .ArgumentParser (
455457 prog = "KPM Helper" ,
@@ -478,7 +480,7 @@ def create_package(args):
478480 break
479481
480482 package = Package (
481- os . path . join ( args .path , "manifest.json" ) ,
483+ args .path ,
482484 id ,
483485 name ,
484486 author ,
@@ -508,9 +510,8 @@ def create_package(args):
508510
509511 # pack
510512 def pack_package (args ):
511- package = Package (os .path .join (args .pkg_path , "manifest.json" ))
512- for platform in args .supported_platform :
513- package .add_supported_platform (platform )
513+ assert (os .path .isdir (args .pkg_path ))
514+ package = Package (args .pkg_path )
514515 package .pack (args .output_path , args .compression )
515516
516517 package_pack_parser = pack_subparsers .add_parser (
@@ -528,13 +529,6 @@ def pack_package(args):
528529 type = int ,
529530 default = 5 ,
530531 )
531- package_pack_parser .add_argument (
532- "--supported_platform" ,
533- help = "Add a supported platform to the manifest" ,
534- action = "append" ,
535- default = [],
536- choices = valid_supported_platforms ,
537- )
538532 package_pack_parser .set_defaults (func = pack_package )
539533
540534 ###
0 commit comments