<s> '''<STR_LIT>''' <EOL> from dbmodels import IssueRef , SeriesRef <EOL> from pluginbookdata import PluginBookData <EOL> from time import strftime <EOL> from utils import sstr , is_number <EOL> import clr <EOL> import db <EOL> import fnameparser <EOL> import log <EOL> import re <EOL> import utils <EOL> from bookdata import BookData <EOL> clr . AddReference ( '<STR_LIT>' ) <EOL> from System . IO import Path <EOL> from System . Security . Cryptography import MD5 <EOL> from System . Text import Encoding <EOL> class ComicBook ( object ) : <EOL> '''<STR_LIT>''' <EOL> CVDBSKIP = '<STR_LIT>' <EOL> def __init__ ( self , crbook , scraper ) : <EOL> '''<STR_LIT>''' <EOL> self . __scraper = scraper ; <EOL> self . __bookdata = PluginBookData ( crbook , scraper ) <EOL> self . __parse_extra_details_from_path ( ) <EOL> series_s = property ( lambda self : self . __bookdata . series_s ) <EOL> issue_num_s = property ( lambda self : self . __bookdata . issue_num_s ) <EOL> volume_year_n = property ( lambda self : self . __bookdata . volume_year_n ) <EOL> pub_year_n = property ( lambda self : self . __bookdata . pub_year_n ) <EOL> rel_year_n = property ( lambda self : self . __bookdata . rel_year_n ) <EOL> format_s = property ( lambda self : self . __bookdata . format_s ) <EOL> path_s = property ( lambda self : self . __bookdata . path_s ) <EOL> page_count_n = property ( lambda self : self . __bookdata . page_count_n ) <EOL> unique_series_s = property ( lambda self : self . __unique_series_s ( ) ) <EOL> issue_ref = property ( lambda self : None if <EOL> self . __extract_issue_ref ( ) == '<STR_LIT>' else self . __extract_issue_ref ( ) ) <EOL> series_ref = property ( lambda self : self . __extract_series_ref ( ) ) <EOL> skip_b = property ( lambda self : self . __extract_issue_ref ( ) == '<STR_LIT>' ) <EOL> def create_image_of_page ( self , page_index ) : <EOL> '''<STR_LIT>''' <EOL> return self . __bookdata . create_image_of_page ( page_index ) <EOL> def skip_forever ( self ) : <EOL> '''<STR_LIT>''' <EOL> bd = self . __bookdata <EOL> notes = self . __scraper . config . rescrape_notes_b <EOL> tags = self . __scraper . config . rescrape_tags_b <EOL> if notes == tags or tags : <EOL> bd . tags_sl = self . __add_key_to_tags ( bd . tags_sl , None ) ; <EOL> log . debug ( "<STR_LIT>" , ComicBook . CVDBSKIP , "<STR_LIT>" ) <EOL> if notes == tags or notes : <EOL> bd . notes_s = self . __add_key_to_notes ( bd . notes_s , None ) <EOL> log . debug ( "<STR_LIT>" , ComicBook . CVDBSKIP , "<STR_LIT>" ) <EOL> bd . update ( ) <EOL> def __extract_issue_ref ( self ) : <EOL> '''<STR_LIT>''' <EOL> bd = self . __bookdata <EOL> tagstring = '<STR_LIT:U+002CU+0020>' . join ( bd . tags_sl ) <EOL> skip_found = re . search ( r'<STR_LIT>' + ComicBook . CVDBSKIP , tagstring ) <EOL> if not skip_found : <EOL> skip_found = re . search ( r'<STR_LIT>' + ComicBook . CVDBSKIP , bd . notes_s ) <EOL> retval = "<STR_LIT>" if skip_found else None <EOL> if retval is None : <EOL> issue_key = db . parse_key_tag ( tagstring ) <EOL> if issue_key == None : <EOL> issue_key = db . parse_key_tag ( bd . notes_s ) <EOL> if issue_key == None : <EOL> issue_key = int ( bd . issue_key_s ) if utils . is_number ( bd . issue_key_s ) else None <EOL> if issue_key != None : <EOL> retval = IssueRef ( self . issue_num_s , issue_key , <EOL> self . __bookdata . title_s , self . __bookdata . cover_url_s ) ; <EOL> return retval <EOL> def __extract_series_ref ( self ) : <EOL> '''<STR_LIT>''' <EOL> bd = self . __bookdata <EOL> retval = None <EOL> series_key = int ( bd . series_key_s ) if utils . is_number ( bd . series_key_s ) else None <EOL> if series_key != None : <EOL> retval = SeriesRef ( series_key , None , - <NUM_LIT:1> , '<STR_LIT>' , - <NUM_LIT:1> , None ) ; <EOL> return retval <EOL> def __unique_series_s ( self ) : <EOL> '''<STR_LIT>''' <EOL> bd = self . __bookdata <EOL> sname = '<STR_LIT>' if not bd . series_s else bd . series_s <EOL> if sname and bd . format_s : <EOL> sname += bd . format_s <EOL> sname = re . sub ( '<STR_LIT>' , '<STR_LIT>' , sname ) . lower ( ) <EOL> svolume = '<STR_LIT>' <EOL> if sname : <EOL> if bd . volume_year_n and bd . volume_year_n > <NUM_LIT:0> : <EOL> svolume = sstr ( bd . volume_year_n ) <EOL> else : <EOL> sname = "<STR_LIT>" + utils . sstr ( id ( self ) ) <EOL> location = Path . GetDirectoryName ( bd . path_s ) if bd . path_s else None <EOL> location = location if location else '<STR_LIT>' <EOL> hash = svolume if self . __scraper . config . ignore_folders_b else location + svolume <EOL> if hash : <EOL> with MD5 . Create ( ) as md5 : <EOL> bytes = md5 . ComputeHash ( Encoding . UTF8 . GetBytes ( hash ) ) <EOL> hash = '<STR_LIT>' . join ( [ "<STR_LIT>" % x for x in bytes [ : <NUM_LIT:5> ] ] ) . strip ( ) <EOL> return sname + hash <EOL> def update ( self , issue ) : <EOL> '''<STR_LIT>''' <EOL> log . debug ( "<STR_LIT>" ) <EOL> config = self . __scraper . config <EOL> bd = self . __bookdata <EOL> value = self . __massage_new_string ( "<STR_LIT>" , issue . series_name_s , bd . series_s , config . update_series_b , config . ow_existing_b , True ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . series_s = value <EOL> value = self . __massage_new_string ( "<STR_LIT>" , issue . issue_num_s , bd . issue_num_s , config . update_number_b , config . ow_existing_b , True ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . issue_num_s = value <EOL> value = self . __massage_new_string ( "<STR_LIT>" , issue . title_s , bd . title_s , config . update_title_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . title_s = value <EOL> value = self . __massage_new_string_list ( "<STR_LIT>" , <EOL> issue . crossovers_sl , bd . crossovers_sl , config . update_crossovers_b , <EOL> config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . crossovers_sl = value <EOL> value = self . __massage_new_string ( "<STR_LIT>" , issue . summary_s , bd . summary_s , config . update_summary_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . summary_s = value <EOL> value = self . __massage_new_date ( "<STR_LIT>" , <EOL> ( issue . rel_year_n , issue . rel_month_n , issue . rel_day_n ) , <EOL> ( bd . rel_year_n , bd . rel_month_n , bd . rel_day_n ) , <EOL> config . update_released_b , config . ow_existing_b , <EOL> config . ignore_blanks_b , - <NUM_LIT:1> ) <EOL> if value is None : <EOL> bd . dont_update ( "<STR_LIT>" ) <EOL> bd . dont_update ( "<STR_LIT>" ) <EOL> bd . dont_update ( "<STR_LIT>" ) <EOL> else : <EOL> bd . rel_year_n , bd . rel_month_n , bd . rel_day_n = value <EOL> value = self . __massage_new_date ( "<STR_LIT>" , <EOL> ( issue . pub_year_n , issue . pub_month_n , issue . pub_day_n ) , <EOL> ( bd . pub_year_n , bd . pub_month_n , bd . pub_day_n ) , <EOL> config . update_published_b , config . ow_existing_b , <EOL> config . ignore_blanks_b , - <NUM_LIT:1> ) <EOL> if value is None : <EOL> bd . dont_update ( "<STR_LIT>" ) <EOL> bd . dont_update ( "<STR_LIT>" ) <EOL> bd . dont_update ( "<STR_LIT>" ) <EOL> else : <EOL> bd . pub_year_n , bd . pub_month_n , bd . pub_day_n = value <EOL> value = self . __massage_new_number ( "<STR_LIT>" , issue . volume_year_n , bd . volume_year_n , config . update_volume_b , config . ow_existing_b , config . ignore_blanks_b , - <NUM_LIT:1> , lambda x : x > <NUM_LIT:0> ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . volume_year_n = value <EOL> self . __update_publishers ( issue , config ) <EOL> value = self . __massage_new_string_list ( "<STR_LIT>" , issue . characters_sl , bd . characters_sl , config . update_characters_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . characters_sl = value <EOL> value = self . __massage_new_string_list ( "<STR_LIT>" , issue . teams_sl , bd . teams_sl , config . update_teams_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . teams_sl = value <EOL> value = self . __massage_new_string_list ( "<STR_LIT>" , issue . locations_sl , bd . locations_sl , config . update_locations_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . locations_sl = value <EOL> value = self . __massage_new_string_list ( "<STR_LIT>" , issue . writers_sl , bd . writers_sl , config . update_writer_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . writers_sl = value <EOL> value = self . __massage_new_string_list ( "<STR_LIT>" , issue . pencillers_sl , bd . pencillers_sl , config . update_penciller_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . pencillers_sl = value <EOL> value = self . __massage_new_string_list ( "<STR_LIT>" , issue . inkers_sl , bd . inkers_sl , config . update_inker_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . inkers_sl = value <EOL> value = self . __massage_new_string_list ( "<STR_LIT>" , issue . colorists_sl , bd . colorists_sl , config . update_colorist_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . colorists_sl = value <EOL> value = self . __massage_new_string_list ( "<STR_LIT>" , issue . letterers_sl , bd . letterers_sl , config . update_letterer_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . letterers_sl = value <EOL> value = self . __massage_new_string_list ( "<STR_LIT>" , <EOL> issue . cover_artists_sl , bd . cover_artists_sl , config . update_cover_artist_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . cover_artists_sl = value <EOL> value = self . __massage_new_string_list ( "<STR_LIT>" , issue . editors_sl , bd . editors_sl , config . update_editor_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . editors_sl = value <EOL> value = self . __massage_new_string ( "<STR_LIT>" , issue . webpage_s , bd . webpage_s , config . update_webpage_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . webpage_s = value <EOL> value = self . __massage_new_number ( "<STR_LIT>" , issue . rating_n , bd . rating_n , config . update_rating_b , config . ow_existing_b , config . ignore_blanks_b , <NUM_LIT:0.0> , lambda x : x >= <NUM_LIT:0> and x <= <NUM_LIT:5> ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . rating_n = value <EOL> new_tags = self . __add_key_to_tags ( bd . tags_sl , issue . issue_key ) <EOL> value = self . __massage_new_string_list ( "<STR_LIT>" , new_tags , bd . tags_sl , config . rescrape_tags_b , True , False ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . tags_sl = value <EOL> new_notes = self . __add_key_to_notes ( bd . notes_s , issue . issue_key ) <EOL> value = self . __massage_new_string ( "<STR_LIT>" , new_notes , bd . notes_s , config . rescrape_notes_b , True , False ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . notes_s = value <EOL> value = self . __massage_new_string ( "<STR_LIT>" , issue . issue_key , bd . issue_key_s , True , True , False ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . issue_key_s = value <EOL> value = self . __massage_new_string ( "<STR_LIT>" , issue . series_key , bd . series_key_s , True , True , False ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . series_key_s = value <EOL> self . __update_cover_url ( issue ) <EOL> bd . update ( ) ; <EOL> def __update_publishers ( self , issue , config ) : <EOL> '''<STR_LIT>''' <EOL> bd = self . __bookdata <EOL> publisher_s = issue . publisher_s <EOL> imprint_s = issue . imprint_s <EOL> key = imprint_s if imprint_s else publisher_s <EOL> if key and key . lower ( ) in config . user_imprints_sm : <EOL> publisher_s = config . user_imprints_sm [ key . lower ( ) ] <EOL> imprint_s = key <EOL> if not config . convert_imprints_b and imprint_s : <EOL> publisher_s = imprint_s <EOL> imprint_s = '<STR_LIT>' <EOL> aliases = config . publisher_aliases_sm ; <EOL> if publisher_s . lower ( ) in aliases : <EOL> publisher_s = aliases [ publisher_s . lower ( ) ] <EOL> if imprint_s . lower ( ) in aliases : <EOL> imprint_s = aliases [ imprint_s . lower ( ) ] <EOL> if publisher_s == imprint_s : <EOL> imprint_s = '<STR_LIT>' <EOL> value = self . __massage_new_string ( "<STR_LIT>" , imprint_s , bd . imprint_s , config . update_imprint_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . imprint_s = value <EOL> value = self . __massage_new_string ( "<STR_LIT>" , publisher_s , bd . publisher_s , config . update_publisher_b , config . ow_existing_b , config . ignore_blanks_b ) <EOL> if value is None : bd . dont_update ( "<STR_LIT>" ) <EOL> else : bd . publisher_s = value <EOL> def __update_cover_url ( self , issue ) : <EOL> '''<STR_LIT>''' <EOL> config = self . __scraper . config <EOL> bd = self . __bookdata <EOL> url_s = None <EOL> alt_cover_key = sstr ( issue . issue_key ) + "<STR_LIT>" <EOL> if alt_cover_key in config . session_data_map : <EOL> url_s = config . session_data_map [ alt_cover_key ] <EOL> if not url_s and len ( issue . image_urls_sl ) : <EOL> url_s = issue . image_urls_sl [ <NUM_LIT:0> ] <EOL> label = "<STR_LIT>" <EOL> if not url_s : <EOL> log . debug ( "<STR_LIT>" , label . ljust ( <NUM_LIT:15> ) , "<STR_LIT>" ) <EOL> bd . dont_update ( "<STR_LIT>" ) <EOL> else : <EOL> log . debug ( "<STR_LIT>" , label . ljust ( <NUM_LIT:15> ) , "<STR_LIT>" , url_s ) <EOL> bd . cover_url_s = url_s <EOL> def __add_key_to_tags ( self , tags_sl , issue_key ) : <EOL> '''<STR_LIT>''' <EOL> updated_tagstring_s = None <EOL> tagstring_s = '<STR_LIT:U+002CU+0020>' . join ( tags_sl ) . strip ( ) if tags_sl else '<STR_LIT>' <EOL> key_tag_s = db . create_key_tag_s ( issue_key ) if issue_key != None else ComicBook . CVDBSKIP <EOL> if key_tag_s and tagstring_s : <EOL> matches = False <EOL> prev_issue_key = db . parse_key_tag ( tagstring_s ) <EOL> if prev_issue_key : <EOL> prev_key_tag_s = db . create_key_tag_s ( prev_issue_key ) <EOL> if prev_key_tag_s : <EOL> regexp = re . compile ( r"<STR_LIT>" + prev_key_tag_s ) <EOL> matches = regexp . search ( tagstring_s ) <EOL> if matches : <EOL> updated_tagstring_s = re . sub ( regexp , key_tag_s , tagstring_s ) <EOL> else : <EOL> if tagstring_s [ - <NUM_LIT:1> ] == "<STR_LIT:U+002C>" : <EOL> tagstring_s = tagstring_s [ : - <NUM_LIT:1> ] <EOL> updated_tagstring_s = tagstring_s + "<STR_LIT:U+002CU+0020>" + key_tag_s <EOL> elif key_tag_s : <EOL> updated_tagstring_s = key_tag_s <EOL> else : <EOL> updated_tagstring_s = tagstring_s <EOL> return updated_tagstring_s . split ( "<STR_LIT:U+002CU+0020>" ) <EOL> def __add_key_to_notes ( self , notestring_s , issue_key ) : <EOL> '''<STR_LIT>''' <EOL> updated_notestring_s = None <EOL> notestring_s = notestring_s . strip ( ) if notestring_s else '<STR_LIT>' <EOL> key_tag_s = db . create_key_tag_s ( issue_key ) if issue_key != None else ComicBook . CVDBSKIP <EOL> date_s = "<STR_LIT>" + strftime ( r'<STR_LIT>' ) if self . __scraper . config . note_scrape_date_b else "<STR_LIT>" <EOL> key_note_s = '<STR_LIT>' . format ( <EOL> "<STR_LIT>" , key_tag_s , date_s ) if key_tag_s else '<STR_LIT>' <EOL> if key_note_s and notestring_s : <EOL> matches = False <EOL> prev_issue_key = db . parse_key_tag ( notestring_s ) <EOL> if prev_issue_key : <EOL> prev_key_tag = db . create_key_tag_s ( prev_issue_key ) <EOL> if prev_key_tag : <EOL> regexp = re . compile ( r"<STR_LIT>" + prev_key_tag + "<STR_LIT>" ) <EOL> matches = regexp . search ( notestring_s ) <EOL> if matches : <EOL> updated_notestring_s = re . sub ( regexp , key_note_s , notestring_s ) <EOL> else : <EOL> if prev_issue_key : <EOL> prev_key_tag = db . create_key_tag_s ( prev_issue_key ) <EOL> if prev_key_tag : <EOL> regexp = re . compile ( r"<STR_LIT>" + prev_key_tag ) <EOL> matches = regexp . search ( notestring_s ) <EOL> if matches : <EOL> updated_notestring_s = re . sub ( regexp , key_tag_s , notestring_s ) <EOL> else : <EOL> updated_notestring_s = notestring_s + "<STR_LIT>" + key_note_s <EOL> elif key_note_s : <EOL> updated_notestring_s = key_note_s <EOL> else : <EOL> updated_notestring_s = notestring_s <EOL> return updated_notestring_s <EOL> @ staticmethod <EOL> def __massage_new_string ( <EOL> label , new_value , old_value , update , overwrite , ignoreblanks ) : <EOL> '''<STR_LIT>''' <EOL> if new_value is None : <EOL> new_value = '<STR_LIT>' <EOL> if old_value is None : <EOL> old_value = '<STR_LIT>' <EOL> if not isinstance ( new_value , basestring ) or not isinstance ( old_value , basestring ) : <EOL> raise TypeError ( "<STR_LIT>" + label + "<STR_LIT:)>" ) <EOL> old_value = old_value . strip ( ) ; <EOL> new_value = new_value . strip ( ) ; <EOL> retval = None ; <EOL> if update and ( overwrite or not old_value ) and not ( ignoreblanks and not new_value ) : <EOL> retval = new_value <EOL> marker = '<STR_LIT:U+0020>' <EOL> if old_value != new_value : <EOL> marker = '<STR_LIT:*>' <EOL> chars = retval . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) <EOL> if len ( chars ) > <NUM_LIT> : <EOL> chars = chars [ : <NUM_LIT> ] + "<STR_LIT>" <EOL> log . debug ( "<STR_LIT>" , marker , label . ljust ( <NUM_LIT:15> ) , "<STR_LIT>" , chars ) <EOL> else : <EOL> log . debug ( "<STR_LIT>" , label . ljust ( <NUM_LIT:15> ) , "<STR_LIT>" ) <EOL> return retval <EOL> @ staticmethod <EOL> def __massage_new_string_list ( <EOL> label , new_list , old_list , update , overwrite , ignoreblanks ) : <EOL> '''<STR_LIT>''' <EOL> new_list = [ ] if new_list is None else list ( new_list ) <EOL> new_list = [ x for x in new_list if x != None and len ( x . strip ( ) ) > <NUM_LIT:0> ] <EOL> old_list = [ ] if old_list is None else list ( old_list ) <EOL> old_list = [ x for x in old_list if x != None and len ( x . strip ( ) ) > <NUM_LIT:0> ] <EOL> retval = None ; <EOL> if update and ( overwrite or len ( old_list ) == <NUM_LIT:0> ) and ( not ignoreblanks or len ( new_list ) > <NUM_LIT:0> ) : <EOL> retval = new_list <EOL> marker = '<STR_LIT:U+0020>' <EOL> if old_list != new_list : <EOL> marker = '<STR_LIT:*>' <EOL> chars = '<STR_LIT:U+002CU+0020>' . join ( retval ) . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) <EOL> if len ( chars ) > <NUM_LIT> : <EOL> chars = chars [ : <NUM_LIT> ] + "<STR_LIT>" <EOL> log . debug ( "<STR_LIT>" , marker , label . ljust ( <NUM_LIT:15> ) , "<STR_LIT>" , chars ) <EOL> else : <EOL> log . debug ( "<STR_LIT>" , label . ljust ( <NUM_LIT:15> ) , "<STR_LIT>" ) <EOL> return retval <EOL> @ staticmethod <EOL> def __massage_new_number ( label , new_value , old_value , update , overwrite , ignoreblanks , blank_value , is_valid = None , remap_invalid = None ) : <EOL> '''<STR_LIT>''' <EOL> if new_value is None : <EOL> new_value = blank_value ; <EOL> if old_value is None : <EOL> old_value = blank_value ; <EOL> if type ( blank_value ) != int and type ( blank_value ) != float : <EOL> raise TypeError ( "<STR_LIT>" ) ; <EOL> if type ( old_value ) != int and type ( old_value ) != float : <EOL> raise TypeError ( "<STR_LIT>" ) ; <EOL> if type ( old_value ) != type ( blank_value ) : <EOL> raise TypeError ( "<STR_LIT>" ) ; <EOL> if type ( old_value ) != type ( new_value ) : <EOL> try : <EOL> if isinstance ( old_value , int ) : <EOL> new_value = int ( new_value ) <EOL> else : <EOL> new_value = float ( new_value ) <EOL> except : <EOL> log . debug ( "<STR_LIT>" , new_value , <EOL> "<STR_LIT>" , type ( old_value ) ) <EOL> new_value = blank_value <EOL> if is_valid : <EOL> if not is_valid ( new_value ) : <EOL> if remap_invalid : <EOL> new_value = remap_invalid ( new_value ) <EOL> if not is_valid ( new_value ) : <EOL> new_value = blank_value <EOL> retval = None ; <EOL> if update and ( overwrite or old_value == blank_value ) and not ( ignoreblanks and new_value == blank_value ) : <EOL> retval = new_value <EOL> marker = '<STR_LIT:U+0020>' <EOL> if old_value != new_value : <EOL> marker = '<STR_LIT:*>' <EOL> if retval == blank_value : <EOL> log . debug ( "<STR_LIT>" , marker , label . ljust ( <NUM_LIT:15> ) , "<STR_LIT>" ) <EOL> else : <EOL> log . debug ( "<STR_LIT>" , marker , label . ljust ( <NUM_LIT:15> ) , "<STR_LIT>" , retval ) <EOL> else : <EOL> log . debug ( "<STR_LIT>" , label . ljust ( <NUM_LIT:15> ) , "<STR_LIT>" ) <EOL> if retval != None : <EOL> retval = float ( retval ) if type ( old_value ) == float else int ( retval ) <EOL> return retval <EOL> @ staticmethod <EOL> def __massage_new_date ( label , new_value , old_value , update , overwrite , ignoreblanks , blank_value ) : <EOL> '''<STR_LIT>''' <EOL> blank_date = ( blank_value , blank_value , blank_value ) <EOL> new_value = blank_date if not new_value else new_value <EOL> old_value = blank_date if not old_value else old_value <EOL> if type ( blank_value ) != int : <EOL> raise TypeError ( "<STR_LIT>" ) ; <EOL> if len ( old_value ) != <NUM_LIT:3> or type ( old_value [ <NUM_LIT:2> ] ) != int : <EOL> raise TypeError ( "<STR_LIT>" ) ; <EOL> if len ( new_value ) != <NUM_LIT:3> or type ( new_value [ <NUM_LIT:2> ] ) != int : <EOL> raise TypeError ( "<STR_LIT>" ) ; <EOL> retval = None ; <EOL> if update and ( overwrite or old_value == blank_date ) and not ( ignoreblanks and new_value == blank_date ) : <EOL> retval = new_value <EOL> marker = '<STR_LIT:U+0020>' <EOL> if old_value != new_value : <EOL> marker = '<STR_LIT:*>' <EOL> if retval == blank_date : <EOL> log . debug ( "<STR_LIT>" , marker , label . ljust ( <NUM_LIT:15> ) , "<STR_LIT>" ) <EOL> else : <EOL> log . debug ( "<STR_LIT>" , marker , label . ljust ( <NUM_LIT:15> ) , "<STR_LIT>" , '<STR_LIT:->' . join ( <EOL> [ '<STR_LIT>' if x == blank_value else sstr ( x ) for x in retval ] ) ) <EOL> else : <EOL> log . debug ( "<STR_LIT>" , label . ljust ( <NUM_LIT:15> ) , "<STR_LIT>" ) <EOL> return retval <EOL> def __parse_extra_details_from_path ( self ) : <EOL> '''<STR_LIT>''' <EOL> bd = self . __bookdata <EOL> no_series = BookData . blank ( "<STR_LIT>" ) == bd . series_s <EOL> no_issuenum = BookData . blank ( "<STR_LIT>" ) == bd . issue_num_s <EOL> no_year = BookData . blank ( "<STR_LIT>" ) == bd . pub_year_n <EOL> if no_series or no_issuenum or no_year : <EOL> if bd . path_s : <EOL> filename = Path . GetFileName ( bd . path_s ) <EOL> config = self . __scraper . config <EOL> regex = config . alt_search_regex_s <EOL> extracted = None <EOL> if regex : <EOL> extracted = fnameparser . regex ( filename , regex ) <EOL> if not extracted : <EOL> extracted = fnameparser . extract ( filename ) <EOL> if no_series : <EOL> bd . series_s = extracted [ <NUM_LIT:0> ] <EOL> if no_issuenum : <EOL> bd . issue_num_s = extracted [ <NUM_LIT:1> ] <EOL> if no_year : <EOL> bd . pub_year_n = int ( extracted [ <NUM_LIT:2> ] ) if is_number ( extracted [ <NUM_LIT:2> ] ) else BookData . blank ( "<STR_LIT>" ) </s>
