idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
20,300 | def copy_sizes ( self , othervd ) : if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Volume Descriptor is not yet initialized' ) self . space_size = othervd . space_size self . path_tbl_size = othervd . path_tbl_size self . path_table_num_extents = othervd . path_table_num_extents | Copy the path_tbl_size path_table_num_extents and space_size from another volume descriptor . |
20,301 | def parse ( self , ident_str ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This File or Text identifier is already initialized' ) self . text = ident_str self . _initialized = True | Parse a file or text identifier out of a string . |
20,302 | def new ( self , text ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This File or Text identifier is already initialized' ) if len ( text ) != 128 : raise pycdlibexception . PyCdlibInvalidInput ( 'Length of text must be 128' ) self . text = text self . _initialized = True | Create a new file or text identifier . |
20,303 | def parse ( self , vd , extent_loc ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Volume Descriptor Set Terminator already initialized' ) ( descriptor_type , identifier , version , zero_unused ) = struct . unpack_from ( self . FMT , vd , 0 ) if descriptor_type != VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid VDST descriptor type' ) if identifier != b'CD001' : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid VDST identifier' ) if version != 1 : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid VDST version' ) self . orig_extent_loc = extent_loc self . _initialized = True | A method to parse a Volume Descriptor Set Terminator out of a string . |
20,304 | def parse ( self , vd , extent_loc ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Boot Record already initialized' ) ( descriptor_type , identifier , version , self . boot_system_identifier , self . boot_identifier , self . boot_system_use ) = struct . unpack_from ( self . FMT , vd , 0 ) if descriptor_type != VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid boot record descriptor type' ) if identifier != b'CD001' : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid boot record identifier' ) if version != 1 : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid boot record version' ) self . orig_extent_loc = extent_loc self . _initialized = True | A method to parse a Boot Record out of a string . |
20,305 | def new ( self , boot_system_id ) : if self . _initialized : raise Exception ( 'Boot Record already initialized' ) self . boot_system_identifier = boot_system_id . ljust ( 32 , b'\x00' ) self . boot_identifier = b'\x00' * 32 self . boot_system_use = b'\x00' * 197 self . _initialized = True | A method to create a new Boot Record . |
20,306 | def record ( self ) : if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Boot Record not yet initialized' ) return struct . pack ( self . FMT , VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD , b'CD001' , 1 , self . boot_system_identifier , self . boot_identifier , self . boot_system_use ) | A method to generate a string representing this Boot Record . |
20,307 | def update_boot_system_use ( self , boot_sys_use ) : if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Boot Record not yet initialized' ) self . boot_system_use = boot_sys_use . ljust ( 197 , b'\x00' ) | A method to update the boot system use field of this Boot Record . |
20,308 | def parse ( self , data , extent ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Version Volume Descriptor is already initialized' ) if data [ : 3 ] == b'MKI' or data == allzero : self . _data = data self . orig_extent_loc = extent self . _initialized = True return True return False | Do a parse of a Version Volume Descriptor . This consists of seeing whether the data is either all zero or starts with MKI and if so setting the extent location of the Version Volume Descriptor properly . |
20,309 | def new ( self , log_block_size ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Version Volume Descriptor is already initialized' ) self . _data = b'\x00' * log_block_size self . _initialized = True | Create a new Version Volume Descriptor . |
20,310 | def parse ( self , vd , datastr , ino ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Eltorito Boot Info Table is already initialized' ) ( pvd_extent , rec_extent , self . orig_len , self . csum ) = struct . unpack_from ( '=LLLL' , datastr , 0 ) if pvd_extent != vd . extent_location ( ) or rec_extent != ino . extent_location ( ) : return False self . vd = vd self . inode = ino self . _initialized = True return True | A method to parse a boot info table out of a string . |
20,311 | def new ( self , vd , ino , orig_len , csum ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Eltorito Boot Info Table is already initialized' ) self . vd = vd self . orig_len = orig_len self . csum = csum self . inode = ino self . _initialized = True | A method to create a new boot info table . |
20,312 | def record ( self ) : if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Eltorito Boot Info Table not yet initialized' ) return struct . pack ( '=LLLL' , self . vd . extent_location ( ) , self . inode . extent_location ( ) , self . orig_len , self . csum ) + b'\x00' * 40 | A method to generate a string representing this boot info table . |
20,313 | def parse ( self , valstr ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Validation Entry already initialized' ) ( header_id , self . platform_id , reserved_unused , self . id_string , self . checksum , keybyte1 , keybyte2 ) = struct . unpack_from ( self . FMT , valstr , 0 ) if header_id != 1 : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito Validation entry header ID not 1' ) if self . platform_id not in ( 0 , 1 , 2 ) : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito Validation entry platform ID not valid' ) if keybyte1 != 0x55 : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito Validation entry first keybyte not 0x55' ) if keybyte2 != 0xaa : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito Validation entry second keybyte not 0xaa' ) if self . _checksum ( valstr ) != 0 : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito Validation entry checksum not correct' ) self . _initialized = True | A method to parse an El Torito Validation Entry out of a string . |
20,314 | def new ( self , platform_id ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Validation Entry already initialized' ) self . platform_id = platform_id self . id_string = b'\x00' * 24 self . checksum = 0 self . checksum = utils . swab_16bit ( self . _checksum ( self . _record ( ) ) - 1 ) self . _initialized = True | A method to create a new El Torito Validation Entry . |
20,315 | def _record ( self ) : return struct . pack ( self . FMT , 1 , self . platform_id , 0 , self . id_string , self . checksum , 0x55 , 0xaa ) | An internal method to generate a string representing this El Torito Validation Entry . |
20,316 | def parse ( self , valstr ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Entry already initialized' ) ( self . boot_indicator , self . boot_media_type , self . load_segment , self . system_type , unused1 , self . sector_count , self . load_rba , self . selection_criteria_type , self . selection_criteria ) = struct . unpack_from ( self . FMT , valstr , 0 ) if self . boot_indicator not in ( 0x88 , 0x00 ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid El Torito initial entry boot indicator' ) if self . boot_media_type > 4 : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid El Torito boot media type' ) if unused1 != 0 : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito unused field must be 0' ) self . _initialized = True | A method to parse an El Torito Entry out of a string . |
20,317 | def new ( self , sector_count , load_seg , media_name , system_type , bootable ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Entry already initialized' ) if media_name == 'noemul' : media_type = self . MEDIA_NO_EMUL elif media_name == 'floppy' : if sector_count == 2400 : media_type = self . MEDIA_12FLOPPY elif sector_count == 2880 : media_type = self . MEDIA_144FLOPPY elif sector_count == 5760 : media_type = self . MEDIA_288FLOPPY else : raise pycdlibexception . PyCdlibInvalidInput ( 'Invalid sector count for floppy media type; must be 2400, 2880, or 5760' ) sector_count = 1 elif media_name == 'hdemul' : media_type = self . MEDIA_HD_EMUL sector_count = 1 else : raise pycdlibexception . PyCdlibInvalidInput ( "Invalid media name '%s'" % ( media_name ) ) if bootable : self . boot_indicator = 0x88 else : self . boot_indicator = 0 self . boot_media_type = media_type self . load_segment = load_seg self . system_type = system_type self . sector_count = sector_count self . load_rba = 0 self . selection_criteria_type = 0 self . selection_criteria = b'' . ljust ( 19 , b'\x00' ) self . _initialized = True | A method to create a new El Torito Entry . |
20,318 | def set_inode ( self , ino ) : if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Entry not yet initialized' ) self . inode = ino | A method to set the Inode associated with this El Torito Entry . |
20,319 | def record ( self ) : if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Entry not yet initialized' ) return struct . pack ( self . FMT , self . boot_indicator , self . boot_media_type , self . load_segment , self . system_type , 0 , self . sector_count , self . load_rba , self . selection_criteria_type , self . selection_criteria ) | A method to generate a string representing this El Torito Entry . |
20,320 | def set_data_length ( self , length ) : if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Entry not initialized' ) self . sector_count = utils . ceiling_div ( length , 512 ) | A method to set the length of data for this El Torito Entry . |
20,321 | def parse ( self , valstr ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Section Header already initialized' ) ( self . header_indicator , self . platform_id , self . num_section_entries , self . id_string ) = struct . unpack_from ( self . FMT , valstr , 0 ) self . _initialized = True | Parse an El Torito section header from a string . |
20,322 | def new ( self , id_string , platform_id ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Section Header already initialized' ) self . header_indicator = 0x91 self . platform_id = platform_id self . num_section_entries = 0 self . id_string = id_string self . _initialized = True | Create a new El Torito section header . |
20,323 | def add_parsed_entry ( self , entry ) : if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Section Header not yet initialized' ) if len ( self . section_entries ) >= self . num_section_entries : raise pycdlibexception . PyCdlibInvalidInput ( 'Eltorito section had more entries than expected by section header; ISO is corrupt' ) self . section_entries . append ( entry ) | A method to add a parsed entry to the list of entries of this header . If the number of parsed entries exceeds what was expected from the initial parsing of the header this method will throw an Exception . |
20,324 | def add_new_entry ( self , entry ) : if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Section Header not yet initialized' ) self . num_section_entries += 1 self . section_entries . append ( entry ) | A method to add a completely new entry to the list of entries of this header . |
20,325 | def record ( self ) : if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Section Header not yet initialized' ) outlist = [ struct . pack ( self . FMT , self . header_indicator , self . platform_id , self . num_section_entries , self . id_string ) ] for entry in self . section_entries : outlist . append ( entry . record ( ) ) return b'' . join ( outlist ) | Get a string representing this El Torito section header . |
20,326 | def parse ( self , valstr ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Boot Catalog already initialized' ) if self . state == self . EXPECTING_VALIDATION_ENTRY : self . validation_entry . parse ( valstr ) self . state = self . EXPECTING_INITIAL_ENTRY elif self . state == self . EXPECTING_INITIAL_ENTRY : self . initial_entry . parse ( valstr ) self . state = self . EXPECTING_SECTION_HEADER_OR_DONE else : val = bytes ( bytearray ( [ valstr [ 0 ] ] ) ) if val == b'\x00' : last_section_index = len ( self . sections ) - 1 for index , sec in enumerate ( self . sections ) : if sec . num_section_entries != len ( sec . section_entries ) : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito section header specified %d entries, only saw %d' % ( sec . num_section_entries , len ( sec . section_entries ) ) ) if index != last_section_index : if sec . header_indicator != 0x90 : raise pycdlibexception . PyCdlibInvalidISO ( 'Intermediate El Torito section header not properly specified' ) self . _initialized = True elif val in ( b'\x90' , b'\x91' ) : section_header = EltoritoSectionHeader ( ) section_header . parse ( valstr ) self . sections . append ( section_header ) elif val in ( b'\x88' , b'\x00' ) : secentry = EltoritoEntry ( ) secentry . parse ( valstr ) if self . sections and len ( self . sections [ - 1 ] . section_entries ) < self . sections [ - 1 ] . num_section_entries : self . sections [ - 1 ] . add_parsed_entry ( secentry ) else : self . standalone_entries . append ( secentry ) elif val == b'\x44' : self . sections [ - 1 ] . section_entries [ - 1 ] . selection_criteria += valstr [ 2 : ] else : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid El Torito Boot Catalog entry' ) return self . _initialized | A method to parse an El Torito Boot Catalog out of a string . |
20,327 | def new ( self , br , ino , sector_count , load_seg , media_name , system_type , platform_id , bootable ) : if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Boot Catalog already initialized' ) self . validation_entry . new ( platform_id ) self . initial_entry . new ( sector_count , load_seg , media_name , system_type , bootable ) self . initial_entry . set_inode ( ino ) ino . linked_records . append ( self . initial_entry ) self . br = br self . _initialized = True | A method to create a new El Torito Boot Catalog . |
20,328 | def add_section ( self , ino , sector_count , load_seg , media_name , system_type , efi , bootable ) : if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Boot Catalog not yet initialized' ) if len ( self . sections ) == 31 : raise pycdlibexception . PyCdlibInvalidInput ( 'Too many Eltorito sections' ) sec = EltoritoSectionHeader ( ) platform_id = self . validation_entry . platform_id if efi : platform_id = 0xef sec . new ( b'\x00' * 28 , platform_id ) secentry = EltoritoEntry ( ) secentry . new ( sector_count , load_seg , media_name , system_type , bootable ) secentry . set_inode ( ino ) ino . linked_records . append ( secentry ) sec . add_new_entry ( secentry ) if self . sections : self . sections [ - 1 ] . set_record_not_last ( ) self . sections . append ( sec ) | A method to add an section header and entry to this Boot Catalog . |
20,329 | def record ( self ) : if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Boot Catalog not yet initialized' ) outlist = [ self . validation_entry . record ( ) , self . initial_entry . record ( ) ] for sec in self . sections : outlist . append ( sec . record ( ) ) for entry in self . standalone_entries : outlist . append ( entry . record ( ) ) return b'' . join ( outlist ) | A method to generate a string representing this El Torito Boot Catalog . |
20,330 | def add_dirrecord ( self , rec ) : if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Boot Catalog not yet initialized' ) self . dirrecords . append ( rec ) | A method to set the Directory Record associated with this Boot Catalog . |
20,331 | def update_catalog_extent ( self , current_extent ) : if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Boot Catalog not yet initialized' ) self . br . update_boot_system_use ( struct . pack ( '=L' , current_extent ) ) | A method to update the extent associated with this Boot Catalog . |
20,332 | def _check_d1_characters ( name ) : bytename = bytearray ( name ) for char in bytename : if char not in _allowed_d1_characters : raise pycdlibexception . PyCdlibInvalidInput ( 'ISO9660 filenames must consist of characters A-Z, 0-9, and _' ) | A function to check that a name only uses d1 characters as defined by ISO9660 . |
20,333 | def _split_iso9660_filename ( fullname ) : namesplit = fullname . split ( b';' ) version = b'' if len ( namesplit ) > 1 : version = namesplit . pop ( ) rest = b';' . join ( namesplit ) dotsplit = rest . split ( b'.' ) if len ( dotsplit ) == 1 : name = dotsplit [ 0 ] extension = b'' else : name = b'.' . join ( dotsplit [ : - 1 ] ) extension = dotsplit [ - 1 ] return ( name , extension , version ) | A function to split an ISO 9660 filename into its constituent parts . This is the name the extension and the version number . |
20,334 | def _check_iso9660_filename ( fullname , interchange_level ) : ( name , extension , version ) = _split_iso9660_filename ( fullname ) if version != b'' and ( int ( version ) < 1 or int ( version ) > 32767 ) : raise pycdlibexception . PyCdlibInvalidInput ( 'ISO9660 filenames must have a version between 1 and 32767' ) if not name and not extension : raise pycdlibexception . PyCdlibInvalidInput ( 'ISO9660 filenames must have a non-empty name or extension' ) if b';' in name or b';' in extension : raise pycdlibexception . PyCdlibInvalidInput ( 'ISO9660 filenames must contain exactly one semicolon' ) if interchange_level == 1 : if len ( name ) > 8 or len ( extension ) > 3 : raise pycdlibexception . PyCdlibInvalidInput ( 'ISO9660 filenames at interchange level 1 cannot have more than 8 characters or 3 characters in the extension' ) else : pass if interchange_level < 4 : _check_d1_characters ( name ) _check_d1_characters ( extension ) | A function to check that a file identifier conforms to the ISO9660 rules for a particular interchange level . |
20,335 | def _check_iso9660_directory ( fullname , interchange_level ) : if not fullname : raise pycdlibexception . PyCdlibInvalidInput ( 'ISO9660 directory names must be at least 1 character long' ) maxlen = float ( 'inf' ) if interchange_level == 1 : maxlen = 8 elif interchange_level in ( 2 , 3 ) : maxlen = 207 if len ( fullname ) > maxlen : raise pycdlibexception . PyCdlibInvalidInput ( 'ISO9660 directory names at interchange level %d cannot exceed %d characters' % ( interchange_level , maxlen ) ) if interchange_level < 4 : _check_d1_characters ( fullname ) | A function to check that an directory identifier conforms to the ISO9660 rules for a particular interchange level . |
20,336 | def _interchange_level_from_filename ( fullname ) : ( name , extension , version ) = _split_iso9660_filename ( fullname ) interchange_level = 1 if version != b'' and ( int ( version ) < 1 or int ( version ) > 32767 ) : interchange_level = 3 if b';' in name or b';' in extension : interchange_level = 3 if len ( name ) > 8 or len ( extension ) > 3 : interchange_level = 3 try : _check_d1_characters ( name ) _check_d1_characters ( extension ) except pycdlibexception . PyCdlibInvalidInput : interchange_level = 3 return interchange_level | A function to determine the ISO interchange level from the filename . In theory there are 3 levels but in practice we only deal with level 1 and level 3 . |
20,337 | def _interchange_level_from_directory ( name ) : interchange_level = 1 if len ( name ) > 8 : interchange_level = 3 try : _check_d1_characters ( name ) except pycdlibexception . PyCdlibInvalidInput : interchange_level = 3 return interchange_level | A function to determine the ISO interchange level from the directory name . In theory there are 3 levels but in practice we only deal with level 1 and level 3 . |
20,338 | def _yield_children ( rec ) : if not rec . is_dir ( ) : raise pycdlibexception . PyCdlibInvalidInput ( 'Record is not a directory!' ) last = b'' for child in rec . children : fi = child . file_identifier ( ) if fi == last : continue last = fi if child . rock_ridge is not None and child . rock_ridge . child_link_record_exists ( ) and child . rock_ridge . cl_to_moved_dr is not None and child . rock_ridge . cl_to_moved_dr . parent is not None : cl_parent = child . rock_ridge . cl_to_moved_dr . parent for cl_child in cl_parent . children : if cl_child . rock_ridge is not None and cl_child . rock_ridge . name ( ) == child . rock_ridge . name ( ) : child = cl_child break yield child | An internal function to gather and yield all of the children of a Directory Record . |
20,339 | def _assign_udf_desc_extents ( descs , start_extent ) : current_extent = start_extent descs . pvd . set_extent_location ( current_extent ) current_extent += 1 descs . impl_use . set_extent_location ( current_extent ) current_extent += 1 descs . partition . set_extent_location ( current_extent ) current_extent += 1 descs . logical_volume . set_extent_location ( current_extent ) current_extent += 1 descs . unallocated_space . set_extent_location ( current_extent ) current_extent += 1 descs . terminator . set_extent_location ( current_extent ) current_extent += 1 | An internal function to assign a consecutive sequence of extents for the given set of UDF Descriptors starting at the given extent . |
20,340 | def _find_dr_record_by_name ( vd , path , encoding ) : if not utils . starts_with_slash ( path ) : raise pycdlibexception . PyCdlibInvalidInput ( 'Must be a path starting with /' ) root_dir_record = vd . root_directory_record ( ) if path == b'/' : return root_dir_record splitpath = utils . split_path ( path ) currpath = splitpath . pop ( 0 ) . decode ( 'utf-8' ) . encode ( encoding ) entry = root_dir_record tmpdr = dr . DirectoryRecord ( ) while True : child = None thelist = entry . children lo = 2 hi = len ( thelist ) while lo < hi : mid = ( lo + hi ) // 2 tmpdr . file_ident = currpath if thelist [ mid ] < tmpdr : lo = mid + 1 else : hi = mid index = lo if index != len ( thelist ) and thelist [ index ] . file_ident == currpath : child = thelist [ index ] if child is None : break if child . rock_ridge is not None and child . rock_ridge . child_link_record_exists ( ) : child = child . rock_ridge . cl_to_moved_dr if child is None : break if not splitpath : return child if not child . is_dir ( ) : break entry = child currpath = splitpath . pop ( 0 ) . decode ( 'utf-8' ) . encode ( encoding ) raise pycdlibexception . PyCdlibInvalidInput ( 'Could not find path' ) | An internal function to find an directory record on the ISO given an ISO or Joliet path . If the entry is found it returns the directory record object corresponding to that entry . If the entry could not be found a pycdlibexception . PyCdlibInvalidInput exception is raised . |
20,341 | def read ( self , size = None ) : if not self . _open : raise pycdlibexception . PyCdlibInvalidInput ( 'I/O operation on closed file.' ) if self . _offset >= self . _length : return b'' if size is None or size < 0 : data = self . readall ( ) else : readsize = min ( self . _length - self . _offset , size ) data = self . _fp . read ( readsize ) self . _offset += readsize return data | A method to read and return up to size bytes . |
20,342 | def readall ( self ) : if not self . _open : raise pycdlibexception . PyCdlibInvalidInput ( 'I/O operation on closed file.' ) readsize = self . _length - self . _offset if readsize > 0 : data = self . _fp . read ( readsize ) self . _offset += readsize else : data = b'' return data | A method to read and return the remaining bytes in the file . |
20,343 | def _parse_volume_descriptors ( self ) : self . _cdfp . seek ( 16 * 2048 ) while True : curr_extent = self . _cdfp . tell ( ) // 2048 vd = self . _cdfp . read ( 2048 ) if len ( vd ) != 2048 : raise pycdlibexception . PyCdlibInvalidISO ( 'Failed to read entire volume descriptor' ) ( desc_type , ident ) = struct . unpack_from ( '=B5s' , vd , 0 ) if desc_type not in ( headervd . VOLUME_DESCRIPTOR_TYPE_PRIMARY , headervd . VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR , headervd . VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD , headervd . VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY ) or ident not in ( b'CD001' , b'BEA01' , b'NSR02' , b'TEA01' ) : self . _cdfp . seek ( - 2048 , os . SEEK_CUR ) break if desc_type == headervd . VOLUME_DESCRIPTOR_TYPE_PRIMARY : pvd = headervd . PrimaryOrSupplementaryVD ( headervd . VOLUME_DESCRIPTOR_TYPE_PRIMARY ) pvd . parse ( vd , curr_extent ) self . pvds . append ( pvd ) elif desc_type == headervd . VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR : vdst = headervd . VolumeDescriptorSetTerminator ( ) vdst . parse ( vd , curr_extent ) self . vdsts . append ( vdst ) elif desc_type == headervd . VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD : if ident == b'CD001' : br = headervd . BootRecord ( ) br . parse ( vd , curr_extent ) self . brs . append ( br ) elif ident == b'BEA01' : self . _has_udf = True self . udf_bea . parse ( vd , curr_extent ) elif ident == b'NSR02' : self . udf_nsr . parse ( vd , curr_extent ) elif ident == b'TEA01' : self . udf_tea . parse ( vd , curr_extent ) else : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid volume identification type' ) elif desc_type == headervd . VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY : svd = headervd . PrimaryOrSupplementaryVD ( headervd . VOLUME_DESCRIPTOR_TYPE_SUPPLEMENTARY ) svd . parse ( vd , curr_extent ) self . svds . append ( svd ) if not self . pvds : raise pycdlibexception . PyCdlibInvalidISO ( 'Valid ISO9660 filesystems must have at least one PVD' ) self . pvd = self . pvds [ 0 ] for pvd in self . pvds [ 1 : ] : if pvd != self . pvd : raise pycdlibexception . PyCdlibInvalidISO ( 'Multiple occurrences of PVD did not agree!' ) pvd . root_dir_record = self . pvd . root_dir_record if not self . vdsts : raise pycdlibexception . PyCdlibInvalidISO ( 'Valid ISO9660 filesystems must have at least one Volume Descriptor Set Terminator' ) | An internal method to parse the volume descriptors on an ISO . |
20,344 | def _seek_to_extent ( self , extent ) : self . _cdfp . seek ( extent * self . pvd . logical_block_size ( ) ) | An internal method to seek to a particular extent on the input ISO . |
20,345 | def _find_rr_record ( self , rr_path ) : if not utils . starts_with_slash ( rr_path ) : raise pycdlibexception . PyCdlibInvalidInput ( 'Must be a path starting with /' ) root_dir_record = self . pvd . root_directory_record ( ) if rr_path == b'/' : return root_dir_record splitpath = utils . split_path ( rr_path ) currpath = splitpath . pop ( 0 ) . decode ( 'utf-8' ) . encode ( 'utf-8' ) entry = root_dir_record while True : child = None thelist = entry . rr_children lo = 0 hi = len ( thelist ) while lo < hi : mid = ( lo + hi ) // 2 tmpchild = thelist [ mid ] if tmpchild . rock_ridge is None : raise pycdlibexception . PyCdlibInvalidInput ( 'Record without Rock Ridge entry on Rock Ridge ISO' ) if tmpchild . rock_ridge . name ( ) < currpath : lo = mid + 1 else : hi = mid index = lo tmpchild = thelist [ index ] if index != len ( thelist ) and tmpchild . rock_ridge is not None and tmpchild . rock_ridge . name ( ) == currpath : child = thelist [ index ] if child is None : break if child . rock_ridge is not None and child . rock_ridge . child_link_record_exists ( ) : child = child . rock_ridge . cl_to_moved_dr if child is None : break if not splitpath : return child if not child . is_dir ( ) : break entry = child currpath = splitpath . pop ( 0 ) . decode ( 'utf-8' ) . encode ( 'utf-8' ) raise pycdlibexception . PyCdlibInvalidInput ( 'Could not find path' ) | An internal method to find an directory record on the ISO given a Rock Ridge path . If the entry is found it returns the directory record object corresponding to that entry . If the entry could not be found a pycdlibexception . PyCdlibInvalidInput is raised . |
20,346 | def _find_joliet_record ( self , joliet_path ) : if self . joliet_vd is None : raise pycdlibexception . PyCdlibInternalError ( 'Joliet path requested on non-Joliet ISO' ) return _find_dr_record_by_name ( self . joliet_vd , joliet_path , 'utf-16_be' ) | An internal method to find an directory record on the ISO given a Joliet path . If the entry is found it returns the directory record object corresponding to that entry . If the entry could not be found a pycdlibexception . PyCdlibInvalidInput is raised . |
20,347 | def _find_udf_record ( self , udf_path ) : if udf_path == b'/' : return None , self . udf_root splitpath = utils . split_path ( udf_path ) currpath = splitpath . pop ( 0 ) entry = self . udf_root while entry is not None : child = entry . find_file_ident_desc_by_name ( currpath ) if not splitpath : return child , child . file_entry if not child . is_dir ( ) : break entry = child . file_entry currpath = splitpath . pop ( 0 ) raise pycdlibexception . PyCdlibInvalidInput ( 'Could not find path' ) | An internal method to find an directory record on the ISO given a UDF path . If the entry is found it returns the directory record object corresponding to that entry . If the entry could not be found a pycdlibexception . PyCdlibInvalidInput is raised . |
20,348 | def _iso_name_and_parent_from_path ( self , iso_path ) : splitpath = utils . split_path ( iso_path ) name = splitpath . pop ( ) parent = self . _find_iso_record ( b'/' + b'/' . join ( splitpath ) ) return ( name . decode ( 'utf-8' ) . encode ( 'utf-8' ) , parent ) | An internal method to find the parent directory record and name given an ISO path . If the parent is found return a tuple containing the basename of the path and the parent directory record object . |
20,349 | def _joliet_name_and_parent_from_path ( self , joliet_path ) : splitpath = utils . split_path ( joliet_path ) name = splitpath . pop ( ) if len ( name ) > 64 : raise pycdlibexception . PyCdlibInvalidInput ( 'Joliet names can be a maximum of 64 characters' ) parent = self . _find_joliet_record ( b'/' + b'/' . join ( splitpath ) ) return ( name . decode ( 'utf-8' ) . encode ( 'utf-16_be' ) , parent ) | An internal method to find the parent directory record and name given a Joliet path . If the parent is found return a tuple containing the basename of the path and the parent directory record object . |
20,350 | def _udf_name_and_parent_from_path ( self , udf_path ) : splitpath = utils . split_path ( udf_path ) name = splitpath . pop ( ) ( parent_ident_unused , parent ) = self . _find_udf_record ( b'/' + b'/' . join ( splitpath ) ) return ( name . decode ( 'utf-8' ) . encode ( 'utf-8' ) , parent ) | An internal method to find the parent directory record and name given a UDF path . If the parent is found return a tuple containing the basename of the path and the parent UDF File Entry object . |
20,351 | def _set_rock_ridge ( self , rr ) : if not self . rock_ridge : self . rock_ridge = rr else : for ver in [ '1.09' , '1.10' , '1.12' ] : if self . rock_ridge == ver : if rr and rr != ver : raise pycdlibexception . PyCdlibInvalidISO ( 'Inconsistent Rock Ridge versions on the ISO!' ) | An internal method to set the Rock Ridge version of the ISO given the Rock Ridge version of the previous entry . |
20,352 | def _parse_path_table ( self , ptr_size , extent ) : self . _seek_to_extent ( extent ) data = self . _cdfp . read ( ptr_size ) offset = 0 out = [ ] extent_to_ptr = { } while offset < ptr_size : ptr = path_table_record . PathTableRecord ( ) len_di_byte = bytearray ( [ data [ offset ] ] ) [ 0 ] read_len = path_table_record . PathTableRecord . record_length ( len_di_byte ) ptr . parse ( data [ offset : offset + read_len ] ) out . append ( ptr ) extent_to_ptr [ ptr . extent_location ] = ptr offset += read_len return out , extent_to_ptr | An internal method to parse a path table on an ISO . For each path table entry found a Path Table Record object is created and the callback is called . |
20,353 | def _check_and_parse_eltorito ( self , br ) : if br . boot_system_identifier != b'EL TORITO SPECIFICATION' . ljust ( 32 , b'\x00' ) : return if self . eltorito_boot_catalog is not None : raise pycdlibexception . PyCdlibInvalidISO ( 'Only one El Torito boot record is allowed' ) if br . extent_location ( ) != 17 : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito Boot Record must be at extent 17' ) self . eltorito_boot_catalog = eltorito . EltoritoBootCatalog ( br ) eltorito_boot_catalog_extent , = struct . unpack_from ( '=L' , br . boot_system_use [ : 4 ] , 0 ) old = self . _cdfp . tell ( ) self . _cdfp . seek ( eltorito_boot_catalog_extent * self . pvd . logical_block_size ( ) ) data = self . _cdfp . read ( 32 ) while not self . eltorito_boot_catalog . parse ( data ) : data = self . _cdfp . read ( 32 ) self . _cdfp . seek ( old ) | An internal method to examine a Boot Record and see if it is an El Torito Boot Record . If it is parse the El Torito Boot Catalog verification entry initial entry and any additional section entries . |
20,354 | def _remove_child_from_dr ( self , child , index , logical_block_size ) : if child . parent is None : raise pycdlibexception . PyCdlibInternalError ( 'Trying to remove child from non-existent parent' ) self . _find_iso_record . cache_clear ( ) self . _find_rr_record . cache_clear ( ) self . _find_joliet_record . cache_clear ( ) if child . parent . remove_child ( child , index , logical_block_size ) : return self . pvd . logical_block_size ( ) return 0 | An internal method to remove a child from a directory record shrinking the space in the Volume Descriptor if necessary . |
20,355 | def _add_to_ptr_size ( self , ptr ) : num_bytes_to_add = 0 for pvd in self . pvds : if pvd . add_to_ptr_size ( path_table_record . PathTableRecord . record_length ( ptr . len_di ) ) : num_bytes_to_add += 4 * self . pvd . logical_block_size ( ) return num_bytes_to_add | An internal method to add a PTR to a VD adding space to the VD if necessary . |
20,356 | def _remove_from_ptr_size ( self , ptr ) : num_bytes_to_remove = 0 for pvd in self . pvds : if pvd . remove_from_ptr_size ( path_table_record . PathTableRecord . record_length ( ptr . len_di ) ) : num_bytes_to_remove += 4 * self . pvd . logical_block_size ( ) return num_bytes_to_remove | An internal method to remove a PTR from a VD removing space from the VD if necessary . |
20,357 | def _calculate_eltorito_boot_info_table_csum ( self , data_fp , data_len ) : num_sectors = utils . ceiling_div ( data_len , self . pvd . logical_block_size ( ) ) csum = 0 curr_sector = 0 while curr_sector < num_sectors : block = data_fp . read ( self . pvd . logical_block_size ( ) ) block = block . ljust ( 2048 , b'\x00' ) i = 0 if curr_sector == 0 : i = 64 while i < len ( block ) : tmp , = struct . unpack_from ( '=L' , block [ : i + 4 ] , i ) csum += tmp csum = csum & 0xffffffff i += 4 curr_sector += 1 return csum | An internal method to calculate the checksum for an El Torito Boot Info Table . This checksum is a simple 32 - bit checksum over all of the data in the boot file starting right after the Boot Info Table itself . |
20,358 | def _check_for_eltorito_boot_info_table ( self , ino ) : orig = self . _cdfp . tell ( ) with inode . InodeOpenData ( ino , self . pvd . logical_block_size ( ) ) as ( data_fp , data_len ) : data_fp . seek ( 8 , os . SEEK_CUR ) bi_table = eltorito . EltoritoBootInfoTable ( ) if bi_table . parse ( self . pvd , data_fp . read ( eltorito . EltoritoBootInfoTable . header_length ( ) ) , ino ) : data_fp . seek ( - 24 , os . SEEK_CUR ) csum = self . _calculate_eltorito_boot_info_table_csum ( data_fp , data_len ) if csum == bi_table . csum : ino . add_boot_info_table ( bi_table ) self . _cdfp . seek ( orig ) | An internal method to check a boot directory record to see if it has an El Torito Boot Info Table embedded inside of it . |
20,359 | def _check_rr_name ( self , rr_name ) : if self . rock_ridge : if not rr_name : raise pycdlibexception . PyCdlibInvalidInput ( 'A rock ridge name must be passed for a rock-ridge ISO' ) if rr_name . count ( '/' ) != 0 : raise pycdlibexception . PyCdlibInvalidInput ( 'A rock ridge name must be relative' ) return rr_name . encode ( 'utf-8' ) if rr_name : raise pycdlibexception . PyCdlibInvalidInput ( 'A rock ridge name can only be specified for a rock-ridge ISO' ) return b'' | An internal method to check whether this ISO requires or does not require a Rock Ridge path . |
20,360 | def _normalize_joliet_path ( self , joliet_path ) : tmp_path = b'' if self . joliet_vd is not None : if not joliet_path : raise pycdlibexception . PyCdlibInvalidInput ( 'A Joliet path must be passed for a Joliet ISO' ) tmp_path = utils . normpath ( joliet_path ) else : if joliet_path : raise pycdlibexception . PyCdlibInvalidInput ( 'A Joliet path can only be specified for a Joliet ISO' ) return tmp_path | An internal method to check whether this ISO does or does not require a Joliet path . If a Joliet path is required the path is normalized and returned . |
20,361 | def _link_eltorito ( self , extent_to_inode ) : if self . eltorito_boot_catalog is None : raise pycdlibexception . PyCdlibInternalError ( 'Trying to link El Torito entries on a non-El Torito ISO' ) log_block_size = self . pvd . logical_block_size ( ) entries_to_assign = [ self . eltorito_boot_catalog . initial_entry ] for sec in self . eltorito_boot_catalog . sections : for entry in sec . section_entries : entries_to_assign . append ( entry ) for entry in entries_to_assign : entry_extent = entry . get_rba ( ) if entry_extent in extent_to_inode : ino = extent_to_inode [ entry_extent ] else : ino = inode . Inode ( ) ino . parse ( entry_extent , entry . length ( ) , self . _cdfp , log_block_size ) extent_to_inode [ entry_extent ] = ino self . inodes . append ( ino ) ino . linked_records . append ( entry ) entry . set_inode ( ino ) | An internal method to link the El Torito entries into their corresponding Directory Records creating new ones if they are hidden . Should only be called on an El Torito ISO . |
20,362 | def _parse_udf_vol_descs ( self , extent , length , descs ) : self . _seek_to_extent ( extent ) vd_data = self . _cdfp . read ( length ) block_size = self . pvd . logical_block_size ( ) offset = 0 current_extent = extent done = False while not done : desc_tag = udfmod . UDFTag ( ) desc_tag . parse ( vd_data [ offset : ] , current_extent ) if desc_tag . tag_ident == 1 : descs . pvd . parse ( vd_data [ offset : offset + 512 ] , current_extent , desc_tag ) elif desc_tag . tag_ident == 4 : descs . impl_use . parse ( vd_data [ offset : offset + 512 ] , current_extent , desc_tag ) elif desc_tag . tag_ident == 5 : descs . partition . parse ( vd_data [ offset : offset + 512 ] , current_extent , desc_tag ) elif desc_tag . tag_ident == 6 : descs . logical_volume . parse ( vd_data [ offset : offset + 512 ] , current_extent , desc_tag ) elif desc_tag . tag_ident == 7 : descs . unallocated_space . parse ( vd_data [ offset : offset + 512 ] , current_extent , desc_tag ) elif desc_tag . tag_ident == 8 : descs . terminator . parse ( current_extent , desc_tag ) done = True else : raise pycdlibexception . PyCdlibInvalidISO ( 'UDF Tag identifier not %d' % ( desc_tag . tag_ident ) ) offset += block_size current_extent += 1 | An internal method to parse a set of UDF Volume Descriptors . |
20,363 | def _parse_udf_descriptors ( self ) : block_size = self . pvd . logical_block_size ( ) anchor_locations = [ ( 256 * block_size , os . SEEK_SET ) , ( - 2048 , os . SEEK_END ) ] for loc , whence in anchor_locations : self . _cdfp . seek ( loc , whence ) extent = self . _cdfp . tell ( ) // 2048 anchor_data = self . _cdfp . read ( 2048 ) anchor_tag = udfmod . UDFTag ( ) anchor_tag . parse ( anchor_data , extent ) if anchor_tag . tag_ident != 2 : raise pycdlibexception . PyCdlibInvalidISO ( 'UDF Anchor Tag identifier not 2' ) anchor = udfmod . UDFAnchorVolumeStructure ( ) anchor . parse ( anchor_data , extent , anchor_tag ) self . udf_anchors . append ( anchor ) self . _parse_udf_vol_descs ( self . udf_anchors [ 0 ] . main_vd_extent , self . udf_anchors [ 0 ] . main_vd_length , self . udf_main_descs ) self . _parse_udf_vol_descs ( self . udf_anchors [ 0 ] . reserve_vd_extent , self . udf_anchors [ 0 ] . reserve_vd_length , self . udf_reserve_descs ) self . _seek_to_extent ( self . udf_main_descs . logical_volume . integrity_sequence_extent ) integrity_data = self . _cdfp . read ( self . udf_main_descs . logical_volume . integrity_sequence_length ) offset = 0 current_extent = self . udf_main_descs . logical_volume . integrity_sequence_extent desc_tag = udfmod . UDFTag ( ) desc_tag . parse ( integrity_data [ offset : ] , current_extent ) if desc_tag . tag_ident != 9 : raise pycdlibexception . PyCdlibInvalidISO ( 'UDF Volume Integrity Tag identifier not 9' ) self . udf_logical_volume_integrity . parse ( integrity_data [ offset : offset + 512 ] , current_extent , desc_tag ) offset += block_size current_extent += 1 desc_tag = udfmod . UDFTag ( ) desc_tag . parse ( integrity_data [ offset : ] , current_extent ) if desc_tag . tag_ident != 8 : raise pycdlibexception . PyCdlibInvalidISO ( 'UDF Logical Volume Integrity Terminator Tag identifier not 8' ) self . udf_logical_volume_integrity_terminator . parse ( current_extent , desc_tag ) current_extent = self . udf_main_descs . partition . part_start_location self . _seek_to_extent ( current_extent ) file_set_and_term_data = self . _cdfp . read ( 2 * block_size ) desc_tag = udfmod . UDFTag ( ) desc_tag . parse ( file_set_and_term_data [ : block_size ] , 0 ) if desc_tag . tag_ident != 256 : raise pycdlibexception . PyCdlibInvalidISO ( 'UDF File Set Tag identifier not 256' ) self . udf_file_set . parse ( file_set_and_term_data [ : block_size ] , current_extent , desc_tag ) current_extent += 1 desc_tag = udfmod . UDFTag ( ) desc_tag . parse ( file_set_and_term_data [ block_size : ] , current_extent - self . udf_main_descs . partition . part_start_location ) if desc_tag . tag_ident != 8 : raise pycdlibexception . PyCdlibInvalidISO ( 'UDF File Set Terminator Tag identifier not 8' ) self . udf_file_set_terminator . parse ( current_extent , desc_tag ) | An internal method to parse the UDF descriptors on the ISO . This should only be called if it the ISO has a valid UDF Volume Recognition Sequence at the beginning of the ISO . |
20,364 | def _parse_udf_file_entry ( self , abs_file_entry_extent , icb , parent ) : self . _seek_to_extent ( abs_file_entry_extent ) icbdata = self . _cdfp . read ( icb . extent_length ) if all ( v == 0 for v in bytearray ( icbdata ) ) : return None desc_tag = udfmod . UDFTag ( ) desc_tag . parse ( icbdata , icb . log_block_num ) if desc_tag . tag_ident != 261 : raise pycdlibexception . PyCdlibInvalidISO ( 'UDF File Entry Tag identifier not 261' ) file_entry = udfmod . UDFFileEntry ( ) file_entry . parse ( icbdata , abs_file_entry_extent , parent , desc_tag ) return file_entry | An internal method to parse a single UDF File Entry and return the corresponding object . |
20,365 | def _walk_udf_directories ( self , extent_to_inode ) : part_start = self . udf_main_descs . partition . part_start_location self . udf_root = self . _parse_udf_file_entry ( part_start + self . udf_file_set . root_dir_icb . log_block_num , self . udf_file_set . root_dir_icb , None ) log_block_size = self . pvd . logical_block_size ( ) udf_file_entries = collections . deque ( [ self . udf_root ] ) while udf_file_entries : udf_file_entry = udf_file_entries . popleft ( ) if udf_file_entry is None : continue for desc_len , desc_pos in udf_file_entry . alloc_descs : abs_file_ident_extent = part_start + desc_pos self . _seek_to_extent ( abs_file_ident_extent ) data = self . _cdfp . read ( desc_len ) offset = 0 while offset < len ( data ) : current_extent = ( abs_file_ident_extent * log_block_size + offset ) // log_block_size desc_tag = udfmod . UDFTag ( ) desc_tag . parse ( data [ offset : ] , current_extent - part_start ) if desc_tag . tag_ident != 257 : raise pycdlibexception . PyCdlibInvalidISO ( 'UDF File Identifier Tag identifier not 257' ) file_ident = udfmod . UDFFileIdentifierDescriptor ( ) offset += file_ident . parse ( data [ offset : ] , current_extent , desc_tag , udf_file_entry ) if file_ident . is_parent ( ) : udf_file_entry . track_file_ident_desc ( file_ident ) continue abs_file_entry_extent = part_start + file_ident . icb . log_block_num next_entry = self . _parse_udf_file_entry ( abs_file_entry_extent , file_ident . icb , udf_file_entry ) udf_file_entry . track_file_ident_desc ( file_ident ) if next_entry is None : if file_ident . is_dir ( ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Empty UDF File Entry for directories are not allowed' ) else : continue file_ident . file_entry = next_entry next_entry . file_ident = file_ident if file_ident . is_dir ( ) : udf_file_entries . append ( next_entry ) else : if next_entry . get_data_length ( ) > 0 : abs_file_data_extent = part_start + next_entry . alloc_descs [ 0 ] [ 1 ] else : abs_file_data_extent = 0 if self . eltorito_boot_catalog is not None and abs_file_data_extent == self . eltorito_boot_catalog . extent_location ( ) : self . eltorito_boot_catalog . add_dirrecord ( next_entry ) else : if abs_file_data_extent in extent_to_inode : ino = extent_to_inode [ abs_file_data_extent ] else : ino = inode . Inode ( ) ino . parse ( abs_file_data_extent , next_entry . get_data_length ( ) , self . _cdfp , log_block_size ) extent_to_inode [ abs_file_data_extent ] = ino self . inodes . append ( ino ) ino . linked_records . append ( next_entry ) next_entry . inode = ino udf_file_entry . finish_directory_parse ( ) | An internal method to walk a UDF filesystem and add all the metadata to this object . |
20,366 | def _udf_get_file_from_iso_fp ( self , outfp , blocksize , udf_path ) : if self . udf_root is None : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot fetch a udf_path from a non-UDF ISO' ) ( ident_unused , found_file_entry ) = self . _find_udf_record ( udf_path ) if found_file_entry is None : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot get the contents of an empty UDF File Entry' ) if not found_file_entry . is_file ( ) : raise pycdlibexception . PyCdlibInvalidInput ( 'Can only write out a file' ) if found_file_entry . inode is None : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot write out an entry without data' ) if found_file_entry . get_data_length ( ) > 0 : with inode . InodeOpenData ( found_file_entry . inode , self . pvd . logical_block_size ( ) ) as ( data_fp , data_len ) : utils . copy_data ( data_len , blocksize , data_fp , outfp ) | An internal method to fetch a single UDF file from the ISO and write it out to the file object . |
20,367 | def _outfp_write_with_check ( self , outfp , data , enable_overwrite_check = True ) : start = outfp . tell ( ) outfp . write ( data ) if self . _track_writes : end = outfp . tell ( ) if end > self . pvd . space_size * self . pvd . logical_block_size ( ) : raise pycdlibexception . PyCdlibInternalError ( 'Wrote past the end of the ISO! (%d > %d)' % ( end , self . pvd . space_size * self . pvd . logical_block_size ( ) ) ) if enable_overwrite_check : bisect . insort_left ( self . _write_check_list , self . _WriteRange ( start , end - 1 ) ) | Internal method to write data out to the output file descriptor ensuring that it doesn t go beyond the bounds of the ISO . |
20,368 | def _output_file_data ( self , outfp , blocksize , ino ) : log_block_size = self . pvd . logical_block_size ( ) outfp . seek ( ino . extent_location ( ) * log_block_size ) tmp_start = outfp . tell ( ) with inode . InodeOpenData ( ino , log_block_size ) as ( data_fp , data_len ) : utils . copy_data ( data_len , blocksize , data_fp , outfp ) utils . zero_pad ( outfp , data_len , log_block_size ) if self . _track_writes : end = outfp . tell ( ) bisect . insort_left ( self . _write_check_list , self . _WriteRange ( tmp_start , end - 1 ) ) if ino . boot_info_table is not None : old = outfp . tell ( ) outfp . seek ( tmp_start + 8 ) self . _outfp_write_with_check ( outfp , ino . boot_info_table . record ( ) , enable_overwrite_check = False ) outfp . seek ( old ) return outfp . tell ( ) - tmp_start | Internal method to write a directory record entry out . |
20,369 | def _write_directory_records ( self , vd , outfp , progress ) : log_block_size = vd . logical_block_size ( ) le_ptr_offset = 0 be_ptr_offset = 0 dirs = collections . deque ( [ vd . root_directory_record ( ) ] ) while dirs : curr = dirs . popleft ( ) curr_dirrecord_offset = 0 if curr . is_dir ( ) : if curr . ptr is None : raise pycdlibexception . PyCdlibInternalError ( 'Directory has no Path Table Record' ) outfp . seek ( vd . path_table_location_le * log_block_size + le_ptr_offset ) ret = curr . ptr . record_little_endian ( ) self . _outfp_write_with_check ( outfp , ret ) le_ptr_offset += len ( ret ) outfp . seek ( vd . path_table_location_be * log_block_size + be_ptr_offset ) ret = curr . ptr . record_big_endian ( ) self . _outfp_write_with_check ( outfp , ret ) be_ptr_offset += len ( ret ) progress . call ( curr . get_data_length ( ) ) dir_extent = curr . extent_location ( ) for child in curr . children : recstr = child . record ( ) if ( curr_dirrecord_offset + len ( recstr ) ) > log_block_size : dir_extent += 1 curr_dirrecord_offset = 0 outfp . seek ( dir_extent * log_block_size + curr_dirrecord_offset ) self . _outfp_write_with_check ( outfp , recstr ) curr_dirrecord_offset += len ( recstr ) if child . rock_ridge is not None : if child . rock_ridge . dr_entries . ce_record is not None : ce_rec = child . rock_ridge . dr_entries . ce_record outfp . seek ( ce_rec . bl_cont_area * self . pvd . logical_block_size ( ) + ce_rec . offset_cont_area ) rec = child . rock_ridge . record_ce_entries ( ) self . _outfp_write_with_check ( outfp , rec ) progress . call ( len ( rec ) ) if child . rock_ridge . child_link_record_exists ( ) : continue if child . is_dir ( ) : if not child . is_dot ( ) and not child . is_dotdot ( ) : dirs . append ( child ) | An internal method to write out the directory records from a particular Volume Descriptor . |
20,370 | def _write_udf_descs ( self , descs , outfp , progress ) : log_block_size = self . pvd . logical_block_size ( ) outfp . seek ( descs . pvd . extent_location ( ) * log_block_size ) rec = descs . pvd . record ( ) self . _outfp_write_with_check ( outfp , rec ) progress . call ( len ( rec ) ) outfp . seek ( descs . impl_use . extent_location ( ) * log_block_size ) rec = descs . impl_use . record ( ) self . _outfp_write_with_check ( outfp , rec ) progress . call ( len ( rec ) ) outfp . seek ( descs . partition . extent_location ( ) * log_block_size ) rec = descs . partition . record ( ) self . _outfp_write_with_check ( outfp , rec ) progress . call ( len ( rec ) ) outfp . seek ( descs . logical_volume . extent_location ( ) * log_block_size ) rec = descs . logical_volume . record ( ) self . _outfp_write_with_check ( outfp , rec ) progress . call ( len ( rec ) ) outfp . seek ( descs . unallocated_space . extent_location ( ) * log_block_size ) rec = descs . unallocated_space . record ( ) self . _outfp_write_with_check ( outfp , rec ) progress . call ( len ( rec ) ) outfp . seek ( descs . terminator . extent_location ( ) * log_block_size ) rec = descs . terminator . record ( ) self . _outfp_write_with_check ( outfp , rec ) progress . call ( len ( rec ) ) | An internal method to write out a UDF Descriptor sequence . |
20,371 | def _update_rr_ce_entry ( self , rec ) : if rec . rock_ridge is not None and rec . rock_ridge . dr_entries . ce_record is not None : celen = rec . rock_ridge . dr_entries . ce_record . len_cont_area added_block , block , offset = self . pvd . add_rr_ce_entry ( celen ) rec . rock_ridge . update_ce_block ( block ) rec . rock_ridge . dr_entries . ce_record . update_offset ( offset ) if added_block : return self . pvd . logical_block_size ( ) return 0 | An internal method to update the Rock Ridge CE entry for the given record . |
20,372 | def _finish_add ( self , num_bytes_to_add , num_partition_bytes_to_add ) : for pvd in self . pvds : pvd . add_to_space_size ( num_bytes_to_add + num_partition_bytes_to_add ) if self . joliet_vd is not None : self . joliet_vd . add_to_space_size ( num_bytes_to_add + num_partition_bytes_to_add ) if self . enhanced_vd is not None : self . enhanced_vd . copy_sizes ( self . pvd ) if self . udf_root is not None : num_extents_to_add = utils . ceiling_div ( num_partition_bytes_to_add , self . pvd . logical_block_size ( ) ) self . udf_main_descs . partition . part_length += num_extents_to_add self . udf_reserve_descs . partition . part_length += num_extents_to_add self . udf_logical_volume_integrity . size_table += num_extents_to_add if self . _always_consistent : self . _reshuffle_extents ( ) else : self . _needs_reshuffle = True | An internal method to do all of the accounting needed whenever something is added to the ISO . This method should only be called by public API implementations . |
20,373 | def _finish_remove ( self , num_bytes_to_remove , is_partition ) : for pvd in self . pvds : pvd . remove_from_space_size ( num_bytes_to_remove ) if self . joliet_vd is not None : self . joliet_vd . remove_from_space_size ( num_bytes_to_remove ) if self . enhanced_vd is not None : self . enhanced_vd . copy_sizes ( self . pvd ) if self . udf_root is not None and is_partition : num_extents_to_remove = utils . ceiling_div ( num_bytes_to_remove , self . pvd . logical_block_size ( ) ) self . udf_main_descs . partition . part_length -= num_extents_to_remove self . udf_reserve_descs . partition . part_length -= num_extents_to_remove self . udf_logical_volume_integrity . size_table -= num_extents_to_remove if self . _always_consistent : self . _reshuffle_extents ( ) else : self . _needs_reshuffle = True | An internal method to do all of the accounting needed whenever something is removed from the ISO . This method should only be called by public API implementations . |
20,374 | def _rm_dr_link ( self , rec ) : if not rec . is_file ( ) : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot remove a directory with rm_hard_link (try rm_directory instead)' ) num_bytes_to_remove = 0 logical_block_size = rec . vd . logical_block_size ( ) done = False while not done : num_bytes_to_remove += self . _remove_child_from_dr ( rec , rec . index_in_parent , logical_block_size ) if rec . inode is not None : found_index = None for index , link in enumerate ( rec . inode . linked_records ) : if id ( link ) == id ( rec ) : found_index = index break else : raise pycdlibexception . PyCdlibInternalError ( 'Could not find inode corresponding to record' ) del rec . inode . linked_records [ found_index ] if not rec . inode . linked_records : found_index = None for index , ino in enumerate ( self . inodes ) : if id ( ino ) == id ( rec . inode ) : found_index = index break else : raise pycdlibexception . PyCdlibInternalError ( 'Could not find inode corresponding to record' ) del self . inodes [ found_index ] num_bytes_to_remove += rec . get_data_length ( ) if rec . data_continuation is not None : rec = rec . data_continuation else : done = True return num_bytes_to_remove | An internal method to remove a Directory Record link given the record . |
20,375 | def _rm_udf_file_ident ( self , parent , fi ) : logical_block_size = self . pvd . logical_block_size ( ) num_extents_to_remove = parent . remove_file_ident_desc_by_name ( fi , logical_block_size ) self . udf_logical_volume_integrity . logical_volume_impl_use . num_files -= 1 self . _find_udf_record . cache_clear ( ) return num_extents_to_remove * logical_block_size | An internal method to remove a UDF File Identifier from the parent and remove any space from the Logical Volume as necessary . |
20,376 | def _rm_udf_link ( self , rec ) : if not rec . is_file ( ) and not rec . is_symlink ( ) : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot remove a directory with rm_hard_link (try rm_directory instead)' ) logical_block_size = self . pvd . logical_block_size ( ) num_bytes_to_remove = 0 if rec . inode is not None : found_index = None for index , link in enumerate ( rec . inode . linked_records ) : if id ( link ) == id ( rec ) : found_index = index break else : raise pycdlibexception . PyCdlibInternalError ( 'Could not find inode corresponding to record' ) del rec . inode . linked_records [ found_index ] rec . inode . num_udf -= 1 if not rec . inode . linked_records : found_index = None for index , ino in enumerate ( self . inodes ) : if id ( ino ) == id ( rec . inode ) : found_index = index break else : raise pycdlibexception . PyCdlibInternalError ( 'Could not find inode corresponding to record' ) del self . inodes [ found_index ] num_bytes_to_remove += rec . get_data_length ( ) if rec . inode . num_udf == 0 : num_bytes_to_remove += logical_block_size else : num_bytes_to_remove += logical_block_size if rec . parent is None : raise pycdlibexception . PyCdlibInternalError ( 'Cannot remove a UDF record with no parent' ) if rec . file_ident is None : raise pycdlibexception . PyCdlibInternalError ( 'Cannot remove a UDF record with no file identifier' ) return num_bytes_to_remove + self . _rm_udf_file_ident ( rec . parent , rec . file_ident . fi ) | An internal method to remove a UDF File Entry link . |
20,377 | def _add_joliet_dir ( self , joliet_path ) : if self . joliet_vd is None : raise pycdlibexception . PyCdlibInternalError ( 'Tried to add joliet dir to non-Joliet ISO' ) ( joliet_name , joliet_parent ) = self . _joliet_name_and_parent_from_path ( joliet_path ) log_block_size = self . joliet_vd . logical_block_size ( ) rec = dr . DirectoryRecord ( ) rec . new_dir ( self . joliet_vd , joliet_name , joliet_parent , self . joliet_vd . sequence_number ( ) , '' , b'' , log_block_size , False , False , False , - 1 ) num_bytes_to_add = self . _add_child_to_dr ( rec , log_block_size ) self . _create_dot ( self . joliet_vd , rec , '' , False , - 1 ) self . _create_dotdot ( self . joliet_vd , rec , '' , False , False , - 1 ) num_bytes_to_add += log_block_size if self . joliet_vd . add_to_ptr_size ( path_table_record . PathTableRecord . record_length ( len ( joliet_name ) ) ) : num_bytes_to_add += 4 * log_block_size ptr = path_table_record . PathTableRecord ( ) ptr . new_dir ( joliet_name ) rec . set_ptr ( ptr ) return num_bytes_to_add | An internal method to add a joliet directory to the ISO . |
20,378 | def _rm_joliet_dir ( self , joliet_path ) : if self . joliet_vd is None : raise pycdlibexception . PyCdlibInternalError ( 'Tried to remove joliet dir from non-Joliet ISO' ) log_block_size = self . joliet_vd . logical_block_size ( ) joliet_child = self . _find_joliet_record ( joliet_path ) num_bytes_to_remove = joliet_child . get_data_length ( ) num_bytes_to_remove += self . _remove_child_from_dr ( joliet_child , joliet_child . index_in_parent , log_block_size ) if joliet_child . ptr is None : raise pycdlibexception . PyCdlibInternalError ( 'Joliet directory has no path table record; this should not be' ) if self . joliet_vd . remove_from_ptr_size ( path_table_record . PathTableRecord . record_length ( joliet_child . ptr . len_di ) ) : num_bytes_to_remove += 4 * log_block_size return num_bytes_to_remove | An internal method to remove a directory from the Joliet portion of the ISO . |
20,379 | def _get_entry ( self , iso_path , rr_path , joliet_path ) : if self . _needs_reshuffle : self . _reshuffle_extents ( ) rec = None if joliet_path is not None : rec = self . _find_joliet_record ( joliet_path ) elif rr_path is not None : rec = self . _find_rr_record ( rr_path ) elif iso_path is not None : rec = self . _find_iso_record ( iso_path ) else : raise pycdlibexception . PyCdlibInternalError ( 'get_entry called without legal argument' ) return rec | Internal method to get the directory record for a particular path . |
20,380 | def _get_udf_entry ( self , udf_path ) : if self . _needs_reshuffle : self . _reshuffle_extents ( ) ( ident_unused , rec ) = self . _find_udf_record ( utils . normpath ( udf_path ) ) if rec is None : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot get entry for empty UDF File Entry' ) return rec | Internal method to get the UDF File Entry for a particular path . |
20,381 | def _create_dot ( self , vd , parent , rock_ridge , xa , file_mode ) : dot = dr . DirectoryRecord ( ) dot . new_dot ( vd , parent , vd . sequence_number ( ) , rock_ridge , vd . logical_block_size ( ) , xa , file_mode ) self . _add_child_to_dr ( dot , vd . logical_block_size ( ) ) | An internal method to create a new dot Directory Record . |
20,382 | def _create_dotdot ( self , vd , parent , rock_ridge , relocated , xa , file_mode ) : dotdot = dr . DirectoryRecord ( ) dotdot . new_dotdot ( vd , parent , vd . sequence_number ( ) , rock_ridge , vd . logical_block_size ( ) , relocated , xa , file_mode ) self . _add_child_to_dr ( dotdot , vd . logical_block_size ( ) ) return dotdot | An internal method to create a new dotdot Directory Record . |
20,383 | def open ( self , filename ) : if self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object already has an ISO; either close it or create a new object' ) fp = open ( filename , 'r+b' ) self . _managing_fp = True try : self . _open_fp ( fp ) except Exception : fp . close ( ) raise | Open up an existing ISO for inspection and modification . |
20,384 | def open_fp ( self , fp ) : if self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object already has an ISO; either close it or create a new object' ) self . _open_fp ( fp ) | Open up an existing ISO for inspection and modification . Note that the file object passed in here must stay open for the lifetime of this object as the PyCdlib class uses it internally to do writing and reading operations . If you want PyCdlib to manage this for you use open instead . |
20,385 | def get_file_from_iso ( self , local_path , ** kwargs ) : if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) blocksize = 8192 joliet_path = None iso_path = None rr_path = None udf_path = None num_paths = 0 for key in kwargs : if key == 'blocksize' : blocksize = kwargs [ key ] elif key == 'iso_path' and kwargs [ key ] is not None : iso_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 elif key == 'rr_path' and kwargs [ key ] is not None : rr_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 elif key == 'joliet_path' and kwargs [ key ] is not None : joliet_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 elif key == 'udf_path' and kwargs [ key ] is not None : udf_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 else : raise pycdlibexception . PyCdlibInvalidInput ( 'Unknown keyword %s' % ( key ) ) if num_paths != 1 : raise pycdlibexception . PyCdlibInvalidInput ( "Exactly one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path' must be passed" ) with open ( local_path , 'wb' ) as fp : if udf_path is not None : self . _udf_get_file_from_iso_fp ( fp , blocksize , udf_path ) else : self . _get_file_from_iso_fp ( fp , blocksize , iso_path , rr_path , joliet_path ) | A method to fetch a single file from the ISO and write it out to a local file . |
20,386 | def get_file_from_iso_fp ( self , outfp , ** kwargs ) : if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) blocksize = 8192 joliet_path = None iso_path = None rr_path = None udf_path = None num_paths = 0 for key in kwargs : if key == 'blocksize' : blocksize = kwargs [ key ] elif key == 'iso_path' and kwargs [ key ] is not None : iso_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 elif key == 'rr_path' and kwargs [ key ] is not None : rr_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 elif key == 'joliet_path' and kwargs [ key ] is not None : joliet_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 elif key == 'udf_path' and kwargs [ key ] is not None : udf_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 else : raise pycdlibexception . PyCdlibInvalidInput ( 'Unknown keyword %s' % ( key ) ) if num_paths != 1 : raise pycdlibexception . PyCdlibInvalidInput ( "Exactly one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path' must be passed" ) if udf_path is not None : self . _udf_get_file_from_iso_fp ( outfp , blocksize , udf_path ) else : self . _get_file_from_iso_fp ( outfp , blocksize , iso_path , rr_path , joliet_path ) | A method to fetch a single file from the ISO and write it out to the file object . |
20,387 | def write ( self , filename , blocksize = 32768 , progress_cb = None , progress_opaque = None ) : if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) with open ( filename , 'wb' ) as fp : self . _write_fp ( fp , blocksize , progress_cb , progress_opaque ) | Write a properly formatted ISO out to the filename passed in . This also goes by the name of mastering . |
20,388 | def add_file ( self , filename , iso_path , rr_name = None , joliet_path = None , file_mode = None , udf_path = None ) : if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) num_bytes_to_add = self . _add_fp ( filename , os . stat ( filename ) . st_size , True , iso_path , rr_name , joliet_path , udf_path , file_mode , False ) self . _finish_add ( 0 , num_bytes_to_add ) | Add a file to the ISO . If the ISO is a Rock Ridge one then a Rock Ridge name must also be provided . If the ISO is a Joliet one then a Joliet path may also be provided ; while it is optional to do so it is highly recommended . |
20,389 | def rm_file ( self , iso_path , rr_name = None , joliet_path = None , udf_path = None ) : if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) iso_path_bytes = utils . normpath ( iso_path ) if not utils . starts_with_slash ( iso_path_bytes ) : raise pycdlibexception . PyCdlibInvalidInput ( 'Must be a path starting with /' ) child = self . _find_iso_record ( iso_path_bytes ) if not child . is_file ( ) : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot remove a directory with rm_file (try rm_directory instead)' ) if self . eltorito_boot_catalog is not None : if any ( [ id ( child ) == id ( rec ) for rec in self . eltorito_boot_catalog . dirrecords ] ) : raise pycdlibexception . PyCdlibInvalidInput ( "Cannot remove a file that is referenced by El Torito; either use 'rm_eltorito' to remove El Torito first, or use 'rm_hard_link' to hide the entry" ) eltorito_entries = { } eltorito_entries [ id ( self . eltorito_boot_catalog . initial_entry . inode ) ] = True for sec in self . eltorito_boot_catalog . sections : for entry in sec . section_entries : eltorito_entries [ id ( entry . inode ) ] = True if id ( child . inode ) in eltorito_entries : raise pycdlibexception . PyCdlibInvalidInput ( "Cannot remove a file that is referenced by El Torito; either use 'rm_eltorito' to remove El Torito first, or use 'rm_hard_link' to hide the entry" ) num_bytes_to_remove = 0 udf_file_ident = None udf_file_entry = None if udf_path is not None : if self . udf_root is None : raise pycdlibexception . PyCdlibInvalidInput ( 'Can only specify a udf_path for a UDF ISO' ) udf_path_bytes = utils . normpath ( udf_path ) ( udf_file_ident , udf_file_entry ) = self . _find_udf_record ( udf_path_bytes ) if child . inode is None : num_bytes_to_remove += self . _remove_child_from_dr ( child , child . index_in_parent , self . pvd . logical_block_size ( ) ) else : while child . inode . linked_records : rec = child . inode . linked_records [ 0 ] if isinstance ( rec , dr . DirectoryRecord ) : num_bytes_to_remove += self . _rm_dr_link ( rec ) elif isinstance ( rec , udfmod . UDFFileEntry ) : num_bytes_to_remove += self . _rm_udf_link ( rec ) else : raise pycdlibexception . PyCdlibInternalError ( 'Saw a linked record that was neither ISO or UDF' ) if udf_file_ident is not None and udf_file_entry is None and udf_file_ident . parent is not None : self . _rm_udf_file_ident ( udf_file_ident . parent , udf_file_ident . fi ) num_bytes_to_remove += self . pvd . logical_block_size ( ) self . _finish_remove ( num_bytes_to_remove , True ) | Remove a file from the ISO . |
20,390 | def get_record ( self , ** kwargs ) : if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) num_paths = 0 for key in kwargs : if key in [ 'joliet_path' , 'rr_path' , 'iso_path' , 'udf_path' ] : if kwargs [ key ] is not None : num_paths += 1 else : raise pycdlibexception . PyCdlibInvalidInput ( "Invalid keyword, must be one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path'" ) if num_paths != 1 : raise pycdlibexception . PyCdlibInvalidInput ( "Must specify one, and only one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path'" ) if 'joliet_path' in kwargs : return self . _get_entry ( None , None , self . _normalize_joliet_path ( kwargs [ 'joliet_path' ] ) ) if 'rr_path' in kwargs : return self . _get_entry ( None , utils . normpath ( kwargs [ 'rr_path' ] ) , None ) if 'udf_path' in kwargs : return self . _get_udf_entry ( kwargs [ 'udf_path' ] ) return self . _get_entry ( utils . normpath ( kwargs [ 'iso_path' ] ) , None , None ) | Get the directory record for a particular path . |
20,391 | def full_path_from_dirrecord ( self , rec , rockridge = False ) : if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) ret = b'' if isinstance ( rec , dr . DirectoryRecord ) : encoding = 'utf-8' if self . joliet_vd is not None and id ( rec . vd ) == id ( self . joliet_vd ) : encoding = 'utf-16_be' slash = '/' . encode ( encoding ) if rec . is_root : return '/' if rockridge and rec . rock_ridge is None : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot generate a Rock Ridge path on a non-Rock Ridge ISO' ) parent = rec while parent is not None : if not parent . is_root : if rockridge and parent . rock_ridge is not None : ret = slash + parent . rock_ridge . name ( ) + ret else : ret = slash + parent . file_identifier ( ) + ret parent = parent . parent else : if rec . parent is None : return '/' if rec . file_ident is not None : encoding = rec . file_ident . encoding else : encoding = 'utf-8' slash = '/' . encode ( encoding ) udfparent = rec while udfparent is not None : ident = udfparent . file_identifier ( ) if ident != b'/' : ret = slash + ident + ret udfparent = udfparent . parent if sys . version_info >= ( 3 , 0 ) : return ret . decode ( encoding ) return ret . decode ( encoding ) . encode ( 'utf-8' ) | A method to get the absolute path of a directory record . |
20,392 | def duplicate_pvd ( self ) : if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) pvd = headervd . PrimaryOrSupplementaryVD ( headervd . VOLUME_DESCRIPTOR_TYPE_PRIMARY ) pvd . copy ( self . pvd ) self . pvds . append ( pvd ) self . _finish_add ( self . pvd . logical_block_size ( ) , 0 ) | A method to add a duplicate PVD to the ISO . This is a mostly useless feature allowed by Ecma - 119 to have duplicate PVDs to avoid possible corruption . |
20,393 | def clear_hidden ( self , iso_path = None , rr_path = None , joliet_path = None ) : if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) if len ( [ x for x in ( iso_path , rr_path , joliet_path ) if x is not None ] ) != 1 : raise pycdlibexception . PyCdlibInvalidInput ( 'Must provide exactly one of iso_path, rr_path, or joliet_path' ) if iso_path is not None : rec = self . _find_iso_record ( utils . normpath ( iso_path ) ) elif rr_path is not None : rec = self . _find_rr_record ( utils . normpath ( rr_path ) ) elif joliet_path is not None : joliet_path_bytes = self . _normalize_joliet_path ( joliet_path ) rec = self . _find_joliet_record ( joliet_path_bytes ) rec . change_existence ( False ) | Clear the ISO9660 hidden attribute on a file or directory . This will cause the file or directory to show up when listing entries on the ISO . Exactly one of iso_path rr_path or joliet_path must be specified . |
20,394 | def set_relocated_name ( self , name , rr_name ) : if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) if not self . rock_ridge : raise pycdlibexception . PyCdlibInvalidInput ( 'Can only set the relocated name on a Rock Ridge ISO' ) encoded_name = name . encode ( 'utf-8' ) encoded_rr_name = rr_name . encode ( 'utf-8' ) if self . _rr_moved_name is not None : if self . _rr_moved_name == encoded_name and self . _rr_moved_rr_name == encoded_rr_name : return raise pycdlibexception . PyCdlibInvalidInput ( 'Changing the existing rr_moved name is not allowed' ) _check_iso9660_directory ( encoded_name , self . interchange_level ) self . _rr_moved_name = encoded_name self . _rr_moved_rr_name = encoded_rr_name | Set the name of the relocated directory on a Rock Ridge ISO . The ISO must be a Rock Ridge one and must not have previously had the relocated name set . |
20,395 | def close ( self ) : if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) if self . _managing_fp : self . _cdfp . close ( ) self . _initialize ( ) | Close the PyCdlib object and re - initialize the object to the defaults . The object can then be re - used for manipulation of another ISO . |
20,396 | def make_arg_parser ( ) : parser = argparse . ArgumentParser ( formatter_class = argparse . RawTextHelpFormatter , usage = "vex [OPTIONS] VIRTUALENV_NAME COMMAND_TO_RUN ..." , ) make = parser . add_argument_group ( title = 'To make a new virtualenv' ) make . add_argument ( '-m' , '--make' , action = "store_true" , help = "make named virtualenv before running command" ) make . add_argument ( '--python' , help = "specify which python for virtualenv to be made" , action = "store" , default = None , ) make . add_argument ( '--site-packages' , help = "allow site package imports from new virtualenv" , action = "store_true" , ) make . add_argument ( '--always-copy' , help = "use copies instead of symlinks in new virtualenv" , action = "store_true" , ) remove = parser . add_argument_group ( title = 'To remove a virtualenv' ) remove . add_argument ( '-r' , '--remove' , action = "store_true" , help = "remove the named virtualenv after running command" ) parser . add_argument ( "--path" , metavar = "DIR" , help = "absolute path to virtualenv to use" , action = "store" ) parser . add_argument ( '--cwd' , metavar = "DIR" , action = "store" , default = '.' , help = "path to run command in (default: '.' aka $PWD)" , ) parser . add_argument ( "--config" , metavar = "FILE" , default = None , action = "store" , help = "path to config file to read (default: '~/.vexrc')" ) parser . add_argument ( '--shell-config' , metavar = "SHELL" , dest = "shell_to_configure" , action = "store" , default = None , help = "print optional config for the specified shell" ) parser . add_argument ( '--list' , metavar = "PREFIX" , nargs = "?" , const = "" , default = None , help = "print a list of available virtualenvs [matching PREFIX]" , action = "store" ) parser . add_argument ( '--version' , help = "print the version of vex that is being run" , action = "store_true" ) parser . add_argument ( "rest" , nargs = argparse . REMAINDER , help = argparse . SUPPRESS ) return parser | Return a standard ArgumentParser object . |
20,397 | def get_options ( argv ) : arg_parser = make_arg_parser ( ) options , unknown = arg_parser . parse_known_args ( argv ) if unknown : arg_parser . print_help ( ) raise exceptions . UnknownArguments ( "unknown args: {0!r}" . format ( unknown ) ) options . print_help = arg_parser . print_help return options | Called to parse the given list as command - line arguments . |
20,398 | def _update_bird_conf_file ( self , operation ) : conf_updated = False prefixes = [ ] ip_version = operation . ip_version config_file = self . bird_configuration [ ip_version ] [ 'config_file' ] variable_name = self . bird_configuration [ ip_version ] [ 'variable_name' ] changes_counter = self . bird_configuration [ ip_version ] [ 'changes_counter' ] dummy_ip_prefix = self . bird_configuration [ ip_version ] [ 'dummy_ip_prefix' ] try : prefixes = get_ip_prefixes_from_bird ( config_file ) except OSError as error : self . log . error ( "failed to open Bird configuration %s, this is a " "FATAL error, thus exiting main program" , error ) sys . exit ( 1 ) if not prefixes : self . log . error ( "found empty bird configuration %s, this is a FATAL" " error, thus exiting main program" , config_file ) sys . exit ( 1 ) if dummy_ip_prefix not in prefixes : self . log . warning ( "dummy IP prefix %s wasn't found in bird " "configuration, adding it. This shouldn't have " "happened!" , dummy_ip_prefix ) prefixes . insert ( 0 , dummy_ip_prefix ) conf_updated = True ip_prefixes_without_check = set ( prefixes ) . difference ( self . ip_prefixes [ ip_version ] ) if ip_prefixes_without_check : self . log . warning ( "found %s IP prefixes in Bird configuration but " "we aren't configured to run health checks on " "them. Either someone modified the configuration " "manually or something went horrible wrong. We " "remove them from Bird configuration" , ',' . join ( ip_prefixes_without_check ) ) prefixes [ : ] = ( ip for ip in prefixes if ip not in ip_prefixes_without_check ) conf_updated = True if operation . update ( prefixes ) : conf_updated = True if not conf_updated : self . log . info ( 'no updates for bird configuration' ) return conf_updated if self . bird_configuration [ ip_version ] [ 'keep_changes' ] : archive_bird_conf ( config_file , changes_counter ) tempname = write_temp_bird_conf ( dummy_ip_prefix , config_file , variable_name , prefixes ) try : os . rename ( tempname , config_file ) except OSError as error : self . log . critical ( "failed to create Bird configuration %s, this " "is a FATAL error, thus exiting main program" , error ) sys . exit ( 1 ) else : self . log . info ( "Bird configuration for IPv%s is updated" , ip_version ) if len ( prefixes ) == 1 : self . log . warning ( "Bird configuration doesn't have IP prefixes for " "any of the services we monitor! It means local " "node doesn't receive any traffic" ) return conf_updated | Update BIRD configuration . |
20,399 | def run ( self ) : if not self . services : self . log . warning ( "no service checks are configured" ) else : self . log . info ( "going to lunch %s threads" , len ( self . services ) ) if self . config . has_option ( 'daemon' , 'splay_startup' ) : splay_startup = self . config . getfloat ( 'daemon' , 'splay_startup' ) else : splay_startup = None for service in self . services : self . log . debug ( "lunching thread for %s" , service ) _config = { } for option , getter in SERVICE_OPTIONS_TYPE . items ( ) : try : _config [ option ] = getattr ( self . config , getter ) ( service , option ) except NoOptionError : pass _thread = ServiceCheck ( service , _config , self . action , splay_startup ) _thread . start ( ) while True : operation = self . action . get ( block = True ) if isinstance ( operation , ServiceCheckDiedError ) : self . log . critical ( operation ) self . log . critical ( "This is a fatal error and the only way to " "recover is to restart, thus exiting with a " "non-zero code and let systemd act by " "triggering a restart" ) sys . exit ( 1 ) self . log . info ( "returned an item from the queue for %s with IP " "prefix %s and action to %s Bird configuration" , operation . name , operation . ip_prefix , operation ) bird_updated = self . _update_bird_conf_file ( operation ) self . action . task_done ( ) if bird_updated : ip_version = operation . ip_version if operation . bird_reconfigure_cmd is None : reconfigure_bird ( self . bird_configuration [ ip_version ] [ 'reconfigure_cmd' ] ) else : run_custom_bird_reconfigure ( operation ) | Lunch checks and triggers updates on BIRD configuration . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.