@@ -201,18 +201,12 @@ def is_writable(self):
201
201
if self .archive_type == self .ArchiveType .Unknown :
202
202
return False
203
203
204
- if not os .access (self .path , os .W_OK ):
205
- return False
206
-
207
- return True
204
+ return bool (os .access (self .path , os .W_OK ))
208
205
209
206
def seems_to_be_a_comic_archive (self ):
210
207
"""Returns a boolean as to whether the file is a comic archive"""
211
208
212
- if (self .is_zip ()) and (self .get_number_of_pages () > 0 ):
213
- return True
214
-
215
- return False
209
+ return bool ((self .is_zip ()) and (self .get_number_of_pages () > 0 ))
216
210
217
211
def get_page (self , index ):
218
212
"""Returns an image(page) from an archive"""
@@ -292,11 +286,13 @@ def read_metadata(self):
292
286
self .metadata = ComicInfoXml ().metadata_from_string (raw_metadata )
293
287
294
288
# validate the existing page list (make sure count is correct)
295
- if len (self .metadata .pages ) != 0 :
296
- if len (self .metadata .pages ) != self .get_number_of_pages ():
297
- # pages array doesn't match the actual number of images we're seeing
298
- # in the archive, so discard the data
299
- self .metadata .pages = []
289
+ if (
290
+ len (self .metadata .pages ) != 0
291
+ and len (self .metadata .pages ) != self .get_number_of_pages ()
292
+ ):
293
+ # pages array doesn't match the actual number of images we're seeing
294
+ # in the archive, so discard the data
295
+ self .metadata .pages = []
300
296
301
297
if len (self .metadata .pages ) == 0 :
302
298
self .metadata .set_default_page_list (self .get_number_of_pages ())
@@ -316,19 +312,18 @@ def read_raw_metadata(self):
316
312
def write_metadata (self , metadata ):
317
313
"""Write the metadata to the archive"""
318
314
319
- if metadata is not None :
320
- self .apply_archive_info_to_metadata (metadata , calc_page_sizes = True )
321
- md_string = ComicInfoXml ().string_from_metadata (metadata )
322
- write_success = self .archiver .write_archive_file (
323
- self .ci_xml_filename , md_string
324
- )
325
- if write_success :
326
- self .has_md = True
327
- self .metadata = metadata
328
- self .reset_cache ()
329
- return write_success
330
-
331
- return False
315
+ if metadata is None :
316
+ return False
317
+ self .apply_archive_info_to_metadata (metadata , calc_page_sizes = True )
318
+ md_string = ComicInfoXml ().string_from_metadata (metadata )
319
+ write_success = self .archiver .write_archive_file (
320
+ self .ci_xml_filename , md_string
321
+ )
322
+ if write_success :
323
+ self .has_md = True
324
+ self .metadata = metadata
325
+ self .reset_cache ()
326
+ return write_success
332
327
333
328
def remove_metadata (self ):
334
329
"""Remove the metadata from the archive if present"""
@@ -347,12 +342,15 @@ def has_metadata(self):
347
342
348
343
if self .has_md is None :
349
344
350
- if not self .seems_to_be_a_comic_archive ():
345
+ if (
346
+ not self .seems_to_be_a_comic_archive ()
347
+ or self .seems_to_be_a_comic_archive ()
348
+ and self .ci_xml_filename
349
+ not in self .archiver .get_archive_filename_list ()
350
+ ):
351
351
self .has_md = False
352
- elif self .ci_xml_filename in self .archiver .get_archive_filename_list ():
353
- self .has_md = True
354
352
else :
355
- self .has_md = False
353
+ self .has_md = True
356
354
return self .has_md
357
355
358
356
def apply_archive_info_to_metadata (self , metadata , calc_page_sizes = False ):
@@ -362,12 +360,12 @@ def apply_archive_info_to_metadata(self, metadata, calc_page_sizes=False):
362
360
363
361
if calc_page_sizes :
364
362
for page in metadata .pages :
365
- idx = int (page ["Image" ])
366
363
if (
367
364
"ImageSize" not in page
368
365
or "ImageHeight" not in page
369
366
or "ImageWidth" not in page
370
367
):
368
+ idx = int (page ["Image" ])
371
369
data = self .get_page (idx )
372
370
if data is not None :
373
371
try :
@@ -380,11 +378,6 @@ def apply_archive_info_to_metadata(self, metadata, calc_page_sizes=False):
380
378
except IOError :
381
379
page ["ImageSize" ] = str (len (data ))
382
380
383
- else :
384
- if "ImageSize" not in page :
385
- data = self .get_page (idx )
386
- page ["ImageSize" ] = str (len (data ))
387
-
388
381
def metadata_from_filename (self , parse_scan_info = True ):
389
382
"""Attempts to get the metadata from the filename"""
390
383
@@ -403,9 +396,8 @@ def metadata_from_filename(self, parse_scan_info=True):
403
396
metadata .year = fnp .year
404
397
if fnp .issue_count != "" :
405
398
metadata .issueCount = fnp .issue_count
406
- if parse_scan_info :
407
- if fnp .remainder != "" :
408
- metadata .scanInfo = fnp .remainder
399
+ if parse_scan_info and fnp .remainder != "" :
400
+ metadata .scanInfo = fnp .remainder
409
401
410
402
metadata .isEmpty = False
411
403
0 commit comments