repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
clalancette/pycdlib
pycdlib/headervd.py
PrimaryOrSupplementaryVD.copy_sizes
def copy_sizes(self, othervd): # type: (PrimaryOrSupplementaryVD) -> None ''' Copy the path_tbl_size, path_table_num_extents, and space_size from another volume descriptor. Parameters: othervd - The other volume descriptor to copy from. Returns: Nothing. ''' 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
python
def copy_sizes(self, othervd): # type: (PrimaryOrSupplementaryVD) -> None ''' Copy the path_tbl_size, path_table_num_extents, and space_size from another volume descriptor. Parameters: othervd - The other volume descriptor to copy from. Returns: Nothing. ''' 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
[ "def", "copy_sizes", "(", "self", ",", "othervd", ")", ":", "# type: (PrimaryOrSupplementaryVD) -> None", "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. Parameters: othervd - The other volume descriptor to copy from. Returns: Nothing.
[ "Copy", "the", "path_tbl_size", "path_table_num_extents", "and", "space_size", "from", "another", "volume", "descriptor", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/headervd.py#L679-L695
train
clalancette/pycdlib
pycdlib/headervd.py
FileOrTextIdentifier.parse
def parse(self, ident_str): # type: (bytes) -> None ''' Parse a file or text identifier out of a string. Parameters: ident_str - The string to parse the file or text identifier from. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This File or Text identifier is already initialized') self.text = ident_str # FIXME: we do not support a file identifier here. In the future, we # might want to implement this. self._initialized = True
python
def parse(self, ident_str): # type: (bytes) -> None ''' Parse a file or text identifier out of a string. Parameters: ident_str - The string to parse the file or text identifier from. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This File or Text identifier is already initialized') self.text = ident_str # FIXME: we do not support a file identifier here. In the future, we # might want to implement this. self._initialized = True
[ "def", "parse", "(", "self", ",", "ident_str", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'This File or Text identifier is already initialized'", ")", "self", ".", "text", "=", "ident_str", "# FIXME: we do not support a file identifier here. In the future, we", "# might want to implement this.", "self", ".", "_initialized", "=", "True" ]
Parse a file or text identifier out of a string. Parameters: ident_str - The string to parse the file or text identifier from. Returns: Nothing.
[ "Parse", "a", "file", "or", "text", "identifier", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/headervd.py#L904-L921
train
clalancette/pycdlib
pycdlib/headervd.py
FileOrTextIdentifier.new
def new(self, text): # type: (bytes) -> None ''' Create a new file or text identifier. Parameters: text - The text to store into the identifier. Returns: Nothing. ''' 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
python
def new(self, text): # type: (bytes) -> None ''' Create a new file or text identifier. Parameters: text - The text to store into the identifier. Returns: Nothing. ''' 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
[ "def", "new", "(", "self", ",", "text", ")", ":", "# type: (bytes) -> None", "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. Parameters: text - The text to store into the identifier. Returns: Nothing.
[ "Create", "a", "new", "file", "or", "text", "identifier", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/headervd.py#L923-L941
train
clalancette/pycdlib
pycdlib/headervd.py
VolumeDescriptorSetTerminator.parse
def parse(self, vd, extent_loc): # type: (bytes, int) -> None ''' A method to parse a Volume Descriptor Set Terminator out of a string. Parameters: vd - The string to parse. extent_loc - The extent this VDST is currently located at. Returns: Nothing. ''' 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) # According to Ecma-119, 8.3.1, the volume descriptor set terminator # type should be 255 if descriptor_type != VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR: raise pycdlibexception.PyCdlibInvalidISO('Invalid VDST descriptor type') # According to Ecma-119, 8.3.2, the identifier should be 'CD001' if identifier != b'CD001': raise pycdlibexception.PyCdlibInvalidISO('Invalid VDST identifier') # According to Ecma-119, 8.3.3, the version should be 1 if version != 1: raise pycdlibexception.PyCdlibInvalidISO('Invalid VDST version') # According to Ecma-119, 8.3.4, the rest of the terminator should be 0; # however, we have seen ISOs in the wild that put stuff into this field. # Just ignore it. self.orig_extent_loc = extent_loc self._initialized = True
python
def parse(self, vd, extent_loc): # type: (bytes, int) -> None ''' A method to parse a Volume Descriptor Set Terminator out of a string. Parameters: vd - The string to parse. extent_loc - The extent this VDST is currently located at. Returns: Nothing. ''' 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) # According to Ecma-119, 8.3.1, the volume descriptor set terminator # type should be 255 if descriptor_type != VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR: raise pycdlibexception.PyCdlibInvalidISO('Invalid VDST descriptor type') # According to Ecma-119, 8.3.2, the identifier should be 'CD001' if identifier != b'CD001': raise pycdlibexception.PyCdlibInvalidISO('Invalid VDST identifier') # According to Ecma-119, 8.3.3, the version should be 1 if version != 1: raise pycdlibexception.PyCdlibInvalidISO('Invalid VDST version') # According to Ecma-119, 8.3.4, the rest of the terminator should be 0; # however, we have seen ISOs in the wild that put stuff into this field. # Just ignore it. self.orig_extent_loc = extent_loc self._initialized = True
[ "def", "parse", "(", "self", ",", "vd", ",", "extent_loc", ")", ":", "# type: (bytes, int) -> None", "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", ")", "# According to Ecma-119, 8.3.1, the volume descriptor set terminator", "# type should be 255", "if", "descriptor_type", "!=", "VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid VDST descriptor type'", ")", "# According to Ecma-119, 8.3.2, the identifier should be 'CD001'", "if", "identifier", "!=", "b'CD001'", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid VDST identifier'", ")", "# According to Ecma-119, 8.3.3, the version should be 1", "if", "version", "!=", "1", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid VDST version'", ")", "# According to Ecma-119, 8.3.4, the rest of the terminator should be 0;", "# however, we have seen ISOs in the wild that put stuff into this field.", "# Just ignore it.", "self", ".", "orig_extent_loc", "=", "extent_loc", "self", ".", "_initialized", "=", "True" ]
A method to parse a Volume Descriptor Set Terminator out of a string. Parameters: vd - The string to parse. extent_loc - The extent this VDST is currently located at. Returns: Nothing.
[ "A", "method", "to", "parse", "a", "Volume", "Descriptor", "Set", "Terminator", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/headervd.py#L978-L1011
train
clalancette/pycdlib
pycdlib/headervd.py
BootRecord.parse
def parse(self, vd, extent_loc): # type: (bytes, int) -> None ''' A method to parse a Boot Record out of a string. Parameters: vd - The string to parse the Boot Record out of. extent_loc - The extent location this Boot Record is current at. Returns: Nothing. ''' 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) # According to Ecma-119, 8.2.1, the boot record type should be 0 if descriptor_type != VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD: raise pycdlibexception.PyCdlibInvalidISO('Invalid boot record descriptor type') # According to Ecma-119, 8.2.2, the identifier should be 'CD001' if identifier != b'CD001': raise pycdlibexception.PyCdlibInvalidISO('Invalid boot record identifier') # According to Ecma-119, 8.2.3, the version should be 1 if version != 1: raise pycdlibexception.PyCdlibInvalidISO('Invalid boot record version') self.orig_extent_loc = extent_loc self._initialized = True
python
def parse(self, vd, extent_loc): # type: (bytes, int) -> None ''' A method to parse a Boot Record out of a string. Parameters: vd - The string to parse the Boot Record out of. extent_loc - The extent location this Boot Record is current at. Returns: Nothing. ''' 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) # According to Ecma-119, 8.2.1, the boot record type should be 0 if descriptor_type != VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD: raise pycdlibexception.PyCdlibInvalidISO('Invalid boot record descriptor type') # According to Ecma-119, 8.2.2, the identifier should be 'CD001' if identifier != b'CD001': raise pycdlibexception.PyCdlibInvalidISO('Invalid boot record identifier') # According to Ecma-119, 8.2.3, the version should be 1 if version != 1: raise pycdlibexception.PyCdlibInvalidISO('Invalid boot record version') self.orig_extent_loc = extent_loc self._initialized = True
[ "def", "parse", "(", "self", ",", "vd", ",", "extent_loc", ")", ":", "# type: (bytes, int) -> None", "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", ")", "# According to Ecma-119, 8.2.1, the boot record type should be 0", "if", "descriptor_type", "!=", "VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid boot record descriptor type'", ")", "# According to Ecma-119, 8.2.2, the identifier should be 'CD001'", "if", "identifier", "!=", "b'CD001'", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid boot record identifier'", ")", "# According to Ecma-119, 8.2.3, the version should be 1", "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. Parameters: vd - The string to parse the Boot Record out of. extent_loc - The extent location this Boot Record is current at. Returns: Nothing.
[ "A", "method", "to", "parse", "a", "Boot", "Record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/headervd.py#L1105-L1135
train
clalancette/pycdlib
pycdlib/headervd.py
BootRecord.new
def new(self, boot_system_id): # type: (bytes) -> None ''' A method to create a new Boot Record. Parameters: boot_system_id - The system identifier to associate with this Boot Record. Returns: Nothing. ''' 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 # This will be set later self._initialized = True
python
def new(self, boot_system_id): # type: (bytes) -> None ''' A method to create a new Boot Record. Parameters: boot_system_id - The system identifier to associate with this Boot Record. Returns: Nothing. ''' 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 # This will be set later self._initialized = True
[ "def", "new", "(", "self", ",", "boot_system_id", ")", ":", "# type: (bytes) -> None", "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", "# This will be set later", "self", ".", "_initialized", "=", "True" ]
A method to create a new Boot Record. Parameters: boot_system_id - The system identifier to associate with this Boot Record. Returns: Nothing.
[ "A", "method", "to", "create", "a", "new", "Boot", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/headervd.py#L1137-L1155
train
clalancette/pycdlib
pycdlib/headervd.py
BootRecord.record
def record(self): # type: () -> bytes ''' A method to generate a string representing this Boot Record. Parameters: None. Returns: A string representing this Boot Record. ''' 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)
python
def record(self): # type: () -> bytes ''' A method to generate a string representing this Boot Record. Parameters: None. Returns: A string representing this Boot Record. ''' 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)
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "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. Parameters: None. Returns: A string representing this Boot Record.
[ "A", "method", "to", "generate", "a", "string", "representing", "this", "Boot", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/headervd.py#L1157-L1172
train
clalancette/pycdlib
pycdlib/headervd.py
BootRecord.update_boot_system_use
def update_boot_system_use(self, boot_sys_use): # type: (bytes) -> None ''' A method to update the boot system use field of this Boot Record. Parameters: boot_sys_use - The new boot system use field for this Boot Record. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Boot Record not yet initialized') self.boot_system_use = boot_sys_use.ljust(197, b'\x00')
python
def update_boot_system_use(self, boot_sys_use): # type: (bytes) -> None ''' A method to update the boot system use field of this Boot Record. Parameters: boot_sys_use - The new boot system use field for this Boot Record. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Boot Record not yet initialized') self.boot_system_use = boot_sys_use.ljust(197, b'\x00')
[ "def", "update_boot_system_use", "(", "self", ",", "boot_sys_use", ")", ":", "# type: (bytes) -> None", "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. Parameters: boot_sys_use - The new boot system use field for this Boot Record. Returns: Nothing.
[ "A", "method", "to", "update", "the", "boot", "system", "use", "field", "of", "this", "Boot", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/headervd.py#L1174-L1187
train
clalancette/pycdlib
pycdlib/headervd.py
VersionVolumeDescriptor.parse
def parse(self, data, extent): # type: (bytes, int) -> bool ''' 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. Parameters: data - The potential version data. extent - The location of the extent on the original ISO of this Version Volume Descriptor. Returns: True if the data passed in is a Version Descriptor, False otherwise. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This Version Volume Descriptor is already initialized') if data[:3] == b'MKI' or data == allzero: # OK, we have a version descriptor. self._data = data self.orig_extent_loc = extent self._initialized = True return True return False
python
def parse(self, data, extent): # type: (bytes, int) -> bool ''' 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. Parameters: data - The potential version data. extent - The location of the extent on the original ISO of this Version Volume Descriptor. Returns: True if the data passed in is a Version Descriptor, False otherwise. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This Version Volume Descriptor is already initialized') if data[:3] == b'MKI' or data == allzero: # OK, we have a version descriptor. self._data = data self.orig_extent_loc = extent self._initialized = True return True return False
[ "def", "parse", "(", "self", ",", "data", ",", "extent", ")", ":", "# type: (bytes, int) -> bool", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'This Version Volume Descriptor is already initialized'", ")", "if", "data", "[", ":", "3", "]", "==", "b'MKI'", "or", "data", "==", "allzero", ":", "# OK, we have a version descriptor.", "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. Parameters: data - The potential version data. extent - The location of the extent on the original ISO of this Version Volume Descriptor. Returns: True if the data passed in is a Version Descriptor, False otherwise.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/headervd.py#L1234-L1258
train
clalancette/pycdlib
pycdlib/headervd.py
VersionVolumeDescriptor.new
def new(self, log_block_size): # type: (int) -> None ''' Create a new Version Volume Descriptor. Parameters: log_block_size - The size of one extent. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This Version Volume Descriptor is already initialized') self._data = b'\x00' * log_block_size self._initialized = True
python
def new(self, log_block_size): # type: (int) -> None ''' Create a new Version Volume Descriptor. Parameters: log_block_size - The size of one extent. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This Version Volume Descriptor is already initialized') self._data = b'\x00' * log_block_size self._initialized = True
[ "def", "new", "(", "self", ",", "log_block_size", ")", ":", "# type: (int) -> None", "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. Parameters: log_block_size - The size of one extent. Returns: Nothing.
[ "Create", "a", "new", "Version", "Volume", "Descriptor", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/headervd.py#L1260-L1274
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoBootInfoTable.parse
def parse(self, vd, datastr, ino): # type: (headervd.PrimaryOrSupplementaryVD, bytes, inode.Inode) -> bool ''' A method to parse a boot info table out of a string. Parameters: vd - The Volume Descriptor associated with this Boot Info Table. datastr - The string to parse the boot info table out of. ino - The Inode associated with the boot file. Returns: True if this is a valid El Torito Boot Info Table, False otherwise. ''' 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
python
def parse(self, vd, datastr, ino): # type: (headervd.PrimaryOrSupplementaryVD, bytes, inode.Inode) -> bool ''' A method to parse a boot info table out of a string. Parameters: vd - The Volume Descriptor associated with this Boot Info Table. datastr - The string to parse the boot info table out of. ino - The Inode associated with the boot file. Returns: True if this is a valid El Torito Boot Info Table, False otherwise. ''' 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
[ "def", "parse", "(", "self", ",", "vd", ",", "datastr", ",", "ino", ")", ":", "# type: (headervd.PrimaryOrSupplementaryVD, bytes, inode.Inode) -> bool", "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. Parameters: vd - The Volume Descriptor associated with this Boot Info Table. datastr - The string to parse the boot info table out of. ino - The Inode associated with the boot file. Returns: True if this is a valid El Torito Boot Info Table, False otherwise.
[ "A", "method", "to", "parse", "a", "boot", "info", "table", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L52-L76
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoBootInfoTable.new
def new(self, vd, ino, orig_len, csum): # type: (headervd.PrimaryOrSupplementaryVD, inode.Inode, int, int) -> None ''' A method to create a new boot info table. Parameters: vd - The volume descriptor to associate with this boot info table. ino - The Inode associated with this Boot Info Table. orig_len - The original length of the file before the boot info table was patched into it. csum - The checksum for the boot file, starting at the byte after the boot info table. Returns: Nothing. ''' 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
python
def new(self, vd, ino, orig_len, csum): # type: (headervd.PrimaryOrSupplementaryVD, inode.Inode, int, int) -> None ''' A method to create a new boot info table. Parameters: vd - The volume descriptor to associate with this boot info table. ino - The Inode associated with this Boot Info Table. orig_len - The original length of the file before the boot info table was patched into it. csum - The checksum for the boot file, starting at the byte after the boot info table. Returns: Nothing. ''' 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
[ "def", "new", "(", "self", ",", "vd", ",", "ino", ",", "orig_len", ",", "csum", ")", ":", "# type: (headervd.PrimaryOrSupplementaryVD, inode.Inode, int, int) -> None", "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. Parameters: vd - The volume descriptor to associate with this boot info table. ino - The Inode associated with this Boot Info Table. orig_len - The original length of the file before the boot info table was patched into it. csum - The checksum for the boot file, starting at the byte after the boot info table. Returns: Nothing.
[ "A", "method", "to", "create", "a", "new", "boot", "info", "table", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L78-L97
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoBootInfoTable.record
def record(self): # type: () -> bytes ''' A method to generate a string representing this boot info table. Parameters: None. Returns: A string representing this boot info table. ''' 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
python
def record(self): # type: () -> bytes ''' A method to generate a string representing this boot info table. Parameters: None. Returns: A string representing this boot info table. ''' 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
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "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. Parameters: None. Returns: A string representing this boot info table.
[ "A", "method", "to", "generate", "a", "string", "representing", "this", "boot", "info", "table", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L99-L114
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoValidationEntry.parse
def parse(self, valstr): # type: (bytes) -> None ''' A method to parse an El Torito Validation Entry out of a string. Parameters: valstr - The string to parse the El Torito Validation Entry out of. Returns: Nothing. ''' 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') # Now that we've done basic checking, calculate the checksum of the # validation entry and make sure it is right. if self._checksum(valstr) != 0: raise pycdlibexception.PyCdlibInvalidISO('El Torito Validation entry checksum not correct') self._initialized = True
python
def parse(self, valstr): # type: (bytes) -> None ''' A method to parse an El Torito Validation Entry out of a string. Parameters: valstr - The string to parse the El Torito Validation Entry out of. Returns: Nothing. ''' 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') # Now that we've done basic checking, calculate the checksum of the # validation entry and make sure it is right. if self._checksum(valstr) != 0: raise pycdlibexception.PyCdlibInvalidISO('El Torito Validation entry checksum not correct') self._initialized = True
[ "def", "parse", "(", "self", ",", "valstr", ")", ":", "# type: (bytes) -> None", "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'", ")", "# Now that we've done basic checking, calculate the checksum of the", "# validation entry and make sure it is right.", "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. Parameters: valstr - The string to parse the El Torito Validation Entry out of. Returns: Nothing.
[ "A", "method", "to", "parse", "an", "El", "Torito", "Validation", "Entry", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L183-L216
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoValidationEntry.new
def new(self, platform_id): # type: (int) -> None ''' A method to create a new El Torito Validation Entry. Parameters: platform_id - The platform ID to set for this validation entry. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Validation Entry already initialized') self.platform_id = platform_id self.id_string = b'\x00' * 24 # FIXME: let the user set this self.checksum = 0 self.checksum = utils.swab_16bit(self._checksum(self._record()) - 1) self._initialized = True
python
def new(self, platform_id): # type: (int) -> None ''' A method to create a new El Torito Validation Entry. Parameters: platform_id - The platform ID to set for this validation entry. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Validation Entry already initialized') self.platform_id = platform_id self.id_string = b'\x00' * 24 # FIXME: let the user set this self.checksum = 0 self.checksum = utils.swab_16bit(self._checksum(self._record()) - 1) self._initialized = True
[ "def", "new", "(", "self", ",", "platform_id", ")", ":", "# type: (int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'El Torito Validation Entry already initialized'", ")", "self", ".", "platform_id", "=", "platform_id", "self", ".", "id_string", "=", "b'\\x00'", "*", "24", "# FIXME: let the user set this", "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. Parameters: platform_id - The platform ID to set for this validation entry. Returns: Nothing.
[ "A", "method", "to", "create", "a", "new", "El", "Torito", "Validation", "Entry", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L218-L235
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoValidationEntry._record
def _record(self): # type: () -> bytes ''' An internal method to generate a string representing this El Torito Validation Entry. Parameters: None. Returns: String representing this El Torito Validation Entry. ''' return struct.pack(self.FMT, 1, self.platform_id, 0, self.id_string, self.checksum, 0x55, 0xaa)
python
def _record(self): # type: () -> bytes ''' An internal method to generate a string representing this El Torito Validation Entry. Parameters: None. Returns: String representing this El Torito Validation Entry. ''' return struct.pack(self.FMT, 1, self.platform_id, 0, self.id_string, self.checksum, 0x55, 0xaa)
[ "def", "_record", "(", "self", ")", ":", "# type: () -> bytes", "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. Parameters: None. Returns: String representing this El Torito Validation Entry.
[ "An", "internal", "method", "to", "generate", "a", "string", "representing", "this", "El", "Torito", "Validation", "Entry", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L237-L249
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoEntry.parse
def parse(self, valstr): # type: (bytes) -> None ''' A method to parse an El Torito Entry out of a string. Parameters: valstr - The string to parse the El Torito Entry out of. Returns: Nothing. ''' 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') # FIXME: check that the system type matches the partition table if unused1 != 0: raise pycdlibexception.PyCdlibInvalidISO('El Torito unused field must be 0') # According to the specification, the El Torito unused end field (bytes # 0xc - 0x1f, unused2 field) should be all zero. However, we have found # ISOs in the wild where that is not the case, so skip that particular # check here. self._initialized = True
python
def parse(self, valstr): # type: (bytes) -> None ''' A method to parse an El Torito Entry out of a string. Parameters: valstr - The string to parse the El Torito Entry out of. Returns: Nothing. ''' 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') # FIXME: check that the system type matches the partition table if unused1 != 0: raise pycdlibexception.PyCdlibInvalidISO('El Torito unused field must be 0') # According to the specification, the El Torito unused end field (bytes # 0xc - 0x1f, unused2 field) should be all zero. However, we have found # ISOs in the wild where that is not the case, so skip that particular # check here. self._initialized = True
[ "def", "parse", "(", "self", ",", "valstr", ")", ":", "# type: (bytes) -> None", "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'", ")", "# FIXME: check that the system type matches the partition table", "if", "unused1", "!=", "0", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'El Torito unused field must be 0'", ")", "# According to the specification, the El Torito unused end field (bytes", "# 0xc - 0x1f, unused2 field) should be all zero. However, we have found", "# ISOs in the wild where that is not the case, so skip that particular", "# check here.", "self", ".", "_initialized", "=", "True" ]
A method to parse an El Torito Entry out of a string. Parameters: valstr - The string to parse the El Torito Entry out of. Returns: Nothing.
[ "A", "method", "to", "parse", "an", "El", "Torito", "Entry", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L306-L339
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoEntry.new
def new(self, sector_count, load_seg, media_name, system_type, bootable): # type: (int, int, str, int, bool) -> None ''' A method to create a new El Torito Entry. Parameters: sector_count - The number of sectors to assign to this El Torito Entry. load_seg - The load segment address of the boot image. media_name - The name of the media type, one of 'noemul', 'floppy', or 'hdemul'. system_type - The partition type to assign to the entry. bootable - Whether this entry is bootable. Returns: Nothing. ''' 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') # With floppy booting, the sector_count always ends up being 1 sector_count = 1 elif media_name == 'hdemul': media_type = self.MEDIA_HD_EMUL # With HD emul booting, the sector_count always ends up being 1 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 # This will get set later self.selection_criteria_type = 0 # FIXME: allow the user to set this self.selection_criteria = b''.ljust(19, b'\x00') self._initialized = True
python
def new(self, sector_count, load_seg, media_name, system_type, bootable): # type: (int, int, str, int, bool) -> None ''' A method to create a new El Torito Entry. Parameters: sector_count - The number of sectors to assign to this El Torito Entry. load_seg - The load segment address of the boot image. media_name - The name of the media type, one of 'noemul', 'floppy', or 'hdemul'. system_type - The partition type to assign to the entry. bootable - Whether this entry is bootable. Returns: Nothing. ''' 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') # With floppy booting, the sector_count always ends up being 1 sector_count = 1 elif media_name == 'hdemul': media_type = self.MEDIA_HD_EMUL # With HD emul booting, the sector_count always ends up being 1 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 # This will get set later self.selection_criteria_type = 0 # FIXME: allow the user to set this self.selection_criteria = b''.ljust(19, b'\x00') self._initialized = True
[ "def", "new", "(", "self", ",", "sector_count", ",", "load_seg", ",", "media_name", ",", "system_type", ",", "bootable", ")", ":", "# type: (int, int, str, int, bool) -> None", "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'", ")", "# With floppy booting, the sector_count always ends up being 1", "sector_count", "=", "1", "elif", "media_name", "==", "'hdemul'", ":", "media_type", "=", "self", ".", "MEDIA_HD_EMUL", "# With HD emul booting, the sector_count always ends up being 1", "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", "# This will get set later", "self", ".", "selection_criteria_type", "=", "0", "# FIXME: allow the user to set this", "self", ".", "selection_criteria", "=", "b''", ".", "ljust", "(", "19", ",", "b'\\x00'", ")", "self", ".", "_initialized", "=", "True" ]
A method to create a new El Torito Entry. Parameters: sector_count - The number of sectors to assign to this El Torito Entry. load_seg - The load segment address of the boot image. media_name - The name of the media type, one of 'noemul', 'floppy', or 'hdemul'. system_type - The partition type to assign to the entry. bootable - Whether this entry is bootable. Returns: Nothing.
[ "A", "method", "to", "create", "a", "new", "El", "Torito", "Entry", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L341-L390
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoEntry.set_inode
def set_inode(self, ino): # type: (inode.Inode) -> None ''' A method to set the Inode associated with this El Torito Entry. Parameters: ino - The Inode object corresponding to this entry. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Entry not yet initialized') self.inode = ino
python
def set_inode(self, ino): # type: (inode.Inode) -> None ''' A method to set the Inode associated with this El Torito Entry. Parameters: ino - The Inode object corresponding to this entry. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Entry not yet initialized') self.inode = ino
[ "def", "set_inode", "(", "self", ",", "ino", ")", ":", "# type: (inode.Inode) -> None", "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. Parameters: ino - The Inode object corresponding to this entry. Returns: Nothing.
[ "A", "method", "to", "set", "the", "Inode", "associated", "with", "this", "El", "Torito", "Entry", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L422-L434
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoEntry.record
def record(self): # type: () -> bytes ''' A method to generate a string representing this El Torito Entry. Parameters: None. Returns: String representing this El Torito Entry. ''' 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)
python
def record(self): # type: () -> bytes ''' A method to generate a string representing this El Torito Entry. Parameters: None. Returns: String representing this El Torito Entry. ''' 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)
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "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. Parameters: None. Returns: String representing this El Torito Entry.
[ "A", "method", "to", "generate", "a", "string", "representing", "this", "El", "Torito", "Entry", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L436-L453
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoEntry.set_data_length
def set_data_length(self, length): # type: (int) -> None ''' A method to set the length of data for this El Torito Entry. Parameters: length - The new length for the El Torito Entry. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Entry not initialized') self.sector_count = utils.ceiling_div(length, 512)
python
def set_data_length(self, length): # type: (int) -> None ''' A method to set the length of data for this El Torito Entry. Parameters: length - The new length for the El Torito Entry. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Entry not initialized') self.sector_count = utils.ceiling_div(length, 512)
[ "def", "set_data_length", "(", "self", ",", "length", ")", ":", "# type: (int) -> None", "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. Parameters: length - The new length for the El Torito Entry. Returns: Nothing.
[ "A", "method", "to", "set", "the", "length", "of", "data", "for", "this", "El", "Torito", "Entry", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L471-L483
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoSectionHeader.parse
def parse(self, valstr): # type: (bytes) -> None ''' Parse an El Torito section header from a string. Parameters: valstr - The string to parse. Returns: Nothing. ''' 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
python
def parse(self, valstr): # type: (bytes) -> None ''' Parse an El Torito section header from a string. Parameters: valstr - The string to parse. Returns: Nothing. ''' 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
[ "def", "parse", "(", "self", ",", "valstr", ")", ":", "# type: (bytes) -> None", "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. Parameters: valstr - The string to parse. Returns: Nothing.
[ "Parse", "an", "El", "Torito", "section", "header", "from", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L500-L516
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoSectionHeader.new
def new(self, id_string, platform_id): # type: (bytes, int) -> None ''' Create a new El Torito section header. Parameters: id_string - The ID to use for this section header. platform_id - The platform ID for this section header. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Section Header already initialized') # We always assume this is the last section, until we are told otherwise # via set_record_not_last. self.header_indicator = 0x91 self.platform_id = platform_id self.num_section_entries = 0 self.id_string = id_string self._initialized = True
python
def new(self, id_string, platform_id): # type: (bytes, int) -> None ''' Create a new El Torito section header. Parameters: id_string - The ID to use for this section header. platform_id - The platform ID for this section header. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Section Header already initialized') # We always assume this is the last section, until we are told otherwise # via set_record_not_last. self.header_indicator = 0x91 self.platform_id = platform_id self.num_section_entries = 0 self.id_string = id_string self._initialized = True
[ "def", "new", "(", "self", ",", "id_string", ",", "platform_id", ")", ":", "# type: (bytes, int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'El Torito Section Header already initialized'", ")", "# We always assume this is the last section, until we are told otherwise", "# via set_record_not_last.", "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. Parameters: id_string - The ID to use for this section header. platform_id - The platform ID for this section header. Returns: Nothing.
[ "Create", "a", "new", "El", "Torito", "section", "header", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L518-L538
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoSectionHeader.add_parsed_entry
def add_parsed_entry(self, entry): # type: (EltoritoEntry) -> None ''' 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. Parameters: entry - The EltoritoEntry object to add to the list of entries. Returns: Nothing. ''' 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)
python
def add_parsed_entry(self, entry): # type: (EltoritoEntry) -> None ''' 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. Parameters: entry - The EltoritoEntry object to add to the list of entries. Returns: Nothing. ''' 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)
[ "def", "add_parsed_entry", "(", "self", ",", "entry", ")", ":", "# type: (EltoritoEntry) -> None", "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. Parameters: entry - The EltoritoEntry object to add to the list of entries. Returns: Nothing.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L540-L558
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoSectionHeader.add_new_entry
def add_new_entry(self, entry): # type: (EltoritoEntry) -> None ''' A method to add a completely new entry to the list of entries of this header. Parameters: entry - The new EltoritoEntry object to add to the list of entries. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Section Header not yet initialized') self.num_section_entries += 1 self.section_entries.append(entry)
python
def add_new_entry(self, entry): # type: (EltoritoEntry) -> None ''' A method to add a completely new entry to the list of entries of this header. Parameters: entry - The new EltoritoEntry object to add to the list of entries. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Section Header not yet initialized') self.num_section_entries += 1 self.section_entries.append(entry)
[ "def", "add_new_entry", "(", "self", ",", "entry", ")", ":", "# type: (EltoritoEntry) -> None", "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. Parameters: entry - The new EltoritoEntry object to add to the list of entries. Returns: Nothing.
[ "A", "method", "to", "add", "a", "completely", "new", "entry", "to", "the", "list", "of", "entries", "of", "this", "header", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L560-L576
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoSectionHeader.record
def record(self): # type: () -> bytes ''' Get a string representing this El Torito section header. Parameters: None. Returns: A string representing this El Torito section header. ''' 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)
python
def record(self): # type: () -> bytes ''' Get a string representing this El Torito section header. Parameters: None. Returns: A string representing this El Torito section header. ''' 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)
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "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. Parameters: None. Returns: A string representing this El Torito section header.
[ "Get", "a", "string", "representing", "this", "El", "Torito", "section", "header", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L594-L614
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoBootCatalog.parse
def parse(self, valstr): # type: (bytes) -> bool ''' A method to parse an El Torito Boot Catalog out of a string. Parameters: valstr - The string to parse the El Torito Boot Catalog out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Boot Catalog already initialized') if self.state == self.EXPECTING_VALIDATION_ENTRY: # The first entry in an El Torito boot catalog is the Validation # Entry. A Validation entry consists of 32 bytes (described in # detail in the parse_eltorito_validation_entry() method). self.validation_entry.parse(valstr) self.state = self.EXPECTING_INITIAL_ENTRY elif self.state == self.EXPECTING_INITIAL_ENTRY: # The next entry is the Initial/Default entry. An Initial/Default # entry consists of 32 bytes (described in detail in the # parse_eltorito_initial_entry() method). self.initial_entry.parse(valstr) self.state = self.EXPECTING_SECTION_HEADER_OR_DONE else: val = bytes(bytearray([valstr[0]])) if val == b'\x00': # An empty entry tells us we are done parsing El Torito. Do # some sanity checks. 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') # In theory, we should also make sure that the very last # section has a header_indicator of 0x91. However, we # have seen ISOs in the wild (FreeBSD 11.0 amd64) in which # this is not the case, so we skip that check. self._initialized = True elif val in (b'\x90', b'\x91'): # A Section Header Entry section_header = EltoritoSectionHeader() section_header.parse(valstr) self.sections.append(section_header) elif val in (b'\x88', b'\x00'): # A Section Entry. According to El Torito 2.4, a Section Entry # must follow a Section Header, but we have seen ISOs in the # wild that do not follow this (Mageia 4 ISOs, for instance). # To deal with this, we get a little complicated here. If there # is a previous section header, and the length of the entries # attached to it is less than the number of entries it should # have, then we attach this entry to that header. If there is # no previous section header, or if the previous section header # is already 'full', then we make this a standalone entry. 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': # A Section Entry Extension self.sections[-1].section_entries[-1].selection_criteria += valstr[2:] else: raise pycdlibexception.PyCdlibInvalidISO('Invalid El Torito Boot Catalog entry') return self._initialized
python
def parse(self, valstr): # type: (bytes) -> bool ''' A method to parse an El Torito Boot Catalog out of a string. Parameters: valstr - The string to parse the El Torito Boot Catalog out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Boot Catalog already initialized') if self.state == self.EXPECTING_VALIDATION_ENTRY: # The first entry in an El Torito boot catalog is the Validation # Entry. A Validation entry consists of 32 bytes (described in # detail in the parse_eltorito_validation_entry() method). self.validation_entry.parse(valstr) self.state = self.EXPECTING_INITIAL_ENTRY elif self.state == self.EXPECTING_INITIAL_ENTRY: # The next entry is the Initial/Default entry. An Initial/Default # entry consists of 32 bytes (described in detail in the # parse_eltorito_initial_entry() method). self.initial_entry.parse(valstr) self.state = self.EXPECTING_SECTION_HEADER_OR_DONE else: val = bytes(bytearray([valstr[0]])) if val == b'\x00': # An empty entry tells us we are done parsing El Torito. Do # some sanity checks. 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') # In theory, we should also make sure that the very last # section has a header_indicator of 0x91. However, we # have seen ISOs in the wild (FreeBSD 11.0 amd64) in which # this is not the case, so we skip that check. self._initialized = True elif val in (b'\x90', b'\x91'): # A Section Header Entry section_header = EltoritoSectionHeader() section_header.parse(valstr) self.sections.append(section_header) elif val in (b'\x88', b'\x00'): # A Section Entry. According to El Torito 2.4, a Section Entry # must follow a Section Header, but we have seen ISOs in the # wild that do not follow this (Mageia 4 ISOs, for instance). # To deal with this, we get a little complicated here. If there # is a previous section header, and the length of the entries # attached to it is less than the number of entries it should # have, then we attach this entry to that header. If there is # no previous section header, or if the previous section header # is already 'full', then we make this a standalone entry. 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': # A Section Entry Extension self.sections[-1].section_entries[-1].selection_criteria += valstr[2:] else: raise pycdlibexception.PyCdlibInvalidISO('Invalid El Torito Boot Catalog entry') return self._initialized
[ "def", "parse", "(", "self", ",", "valstr", ")", ":", "# type: (bytes) -> bool", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'El Torito Boot Catalog already initialized'", ")", "if", "self", ".", "state", "==", "self", ".", "EXPECTING_VALIDATION_ENTRY", ":", "# The first entry in an El Torito boot catalog is the Validation", "# Entry. A Validation entry consists of 32 bytes (described in", "# detail in the parse_eltorito_validation_entry() method).", "self", ".", "validation_entry", ".", "parse", "(", "valstr", ")", "self", ".", "state", "=", "self", ".", "EXPECTING_INITIAL_ENTRY", "elif", "self", ".", "state", "==", "self", ".", "EXPECTING_INITIAL_ENTRY", ":", "# The next entry is the Initial/Default entry. An Initial/Default", "# entry consists of 32 bytes (described in detail in the", "# parse_eltorito_initial_entry() method).", "self", ".", "initial_entry", ".", "parse", "(", "valstr", ")", "self", ".", "state", "=", "self", ".", "EXPECTING_SECTION_HEADER_OR_DONE", "else", ":", "val", "=", "bytes", "(", "bytearray", "(", "[", "valstr", "[", "0", "]", "]", ")", ")", "if", "val", "==", "b'\\x00'", ":", "# An empty entry tells us we are done parsing El Torito. Do", "# some sanity checks.", "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'", ")", "# In theory, we should also make sure that the very last", "# section has a header_indicator of 0x91. However, we", "# have seen ISOs in the wild (FreeBSD 11.0 amd64) in which", "# this is not the case, so we skip that check.", "self", ".", "_initialized", "=", "True", "elif", "val", "in", "(", "b'\\x90'", ",", "b'\\x91'", ")", ":", "# A Section Header Entry", "section_header", "=", "EltoritoSectionHeader", "(", ")", "section_header", ".", "parse", "(", "valstr", ")", "self", ".", "sections", ".", "append", "(", "section_header", ")", "elif", "val", "in", "(", "b'\\x88'", ",", "b'\\x00'", ")", ":", "# A Section Entry. According to El Torito 2.4, a Section Entry", "# must follow a Section Header, but we have seen ISOs in the", "# wild that do not follow this (Mageia 4 ISOs, for instance).", "# To deal with this, we get a little complicated here. If there", "# is a previous section header, and the length of the entries", "# attached to it is less than the number of entries it should", "# have, then we attach this entry to that header. If there is", "# no previous section header, or if the previous section header", "# is already 'full', then we make this a standalone entry.", "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'", ":", "# A Section Entry Extension", "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. Parameters: valstr - The string to parse the El Torito Boot Catalog out of. Returns: Nothing.
[ "A", "method", "to", "parse", "an", "El", "Torito", "Boot", "Catalog", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L641-L710
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoBootCatalog.new
def new(self, br, ino, sector_count, load_seg, media_name, system_type, platform_id, bootable): # type: (headervd.BootRecord, inode.Inode, int, int, str, int, int, bool) -> None ''' A method to create a new El Torito Boot Catalog. Parameters: br - The boot record that this El Torito Boot Catalog is associated with. ino - The Inode to associate with the initial entry. sector_count - The number of sectors for the initial entry. load_seg - The load segment address of the boot image. media_name - The name of the media type, one of 'noemul', 'floppy', or 'hdemul'. system_type - The partition type the entry should be. platform_id - The platform id to set in the validation entry. bootable - Whether this entry should be bootable. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Boot Catalog already initialized') # Create the El Torito validation entry 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
python
def new(self, br, ino, sector_count, load_seg, media_name, system_type, platform_id, bootable): # type: (headervd.BootRecord, inode.Inode, int, int, str, int, int, bool) -> None ''' A method to create a new El Torito Boot Catalog. Parameters: br - The boot record that this El Torito Boot Catalog is associated with. ino - The Inode to associate with the initial entry. sector_count - The number of sectors for the initial entry. load_seg - The load segment address of the boot image. media_name - The name of the media type, one of 'noemul', 'floppy', or 'hdemul'. system_type - The partition type the entry should be. platform_id - The platform id to set in the validation entry. bootable - Whether this entry should be bootable. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Boot Catalog already initialized') # Create the El Torito validation entry 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
[ "def", "new", "(", "self", ",", "br", ",", "ino", ",", "sector_count", ",", "load_seg", ",", "media_name", ",", "system_type", ",", "platform_id", ",", "bootable", ")", ":", "# type: (headervd.BootRecord, inode.Inode, int, int, str, int, int, bool) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'El Torito Boot Catalog already initialized'", ")", "# Create the El Torito validation entry", "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. Parameters: br - The boot record that this El Torito Boot Catalog is associated with. ino - The Inode to associate with the initial entry. sector_count - The number of sectors for the initial entry. load_seg - The load segment address of the boot image. media_name - The name of the media type, one of 'noemul', 'floppy', or 'hdemul'. system_type - The partition type the entry should be. platform_id - The platform id to set in the validation entry. bootable - Whether this entry should be bootable. Returns: Nothing.
[ "A", "method", "to", "create", "a", "new", "El", "Torito", "Boot", "Catalog", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L712-L743
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoBootCatalog.add_section
def add_section(self, ino, sector_count, load_seg, media_name, system_type, efi, bootable): # type: (inode.Inode, int, int, str, int, bool, bool) -> None ''' A method to add an section header and entry to this Boot Catalog. Parameters: ino - The Inode object to associate with the new Entry. sector_count - The number of sectors to assign to the new Entry. load_seg - The load segment address of the boot image. media_name - The name of the media type, one of 'noemul', 'floppy', or 'hdemul'. system_type - The type of partition this entry should be. efi - Whether this section is an EFI section. bootable - Whether this entry should be bootable. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Boot Catalog not yet initialized') # The Eltorito Boot Catalog can only be 2048 bytes (1 extent). By # default, the first 64 bytes are used by the Validation Entry and the # Initial Entry, which leaves 1984 bytes. Each section takes up 32 # bytes for the Section Header and 32 bytes for the Section Entry, for # a total of 64 bytes, so we can have a maximum of 1984/64 = 31 # sections. 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)
python
def add_section(self, ino, sector_count, load_seg, media_name, system_type, efi, bootable): # type: (inode.Inode, int, int, str, int, bool, bool) -> None ''' A method to add an section header and entry to this Boot Catalog. Parameters: ino - The Inode object to associate with the new Entry. sector_count - The number of sectors to assign to the new Entry. load_seg - The load segment address of the boot image. media_name - The name of the media type, one of 'noemul', 'floppy', or 'hdemul'. system_type - The type of partition this entry should be. efi - Whether this section is an EFI section. bootable - Whether this entry should be bootable. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Boot Catalog not yet initialized') # The Eltorito Boot Catalog can only be 2048 bytes (1 extent). By # default, the first 64 bytes are used by the Validation Entry and the # Initial Entry, which leaves 1984 bytes. Each section takes up 32 # bytes for the Section Header and 32 bytes for the Section Entry, for # a total of 64 bytes, so we can have a maximum of 1984/64 = 31 # sections. 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)
[ "def", "add_section", "(", "self", ",", "ino", ",", "sector_count", ",", "load_seg", ",", "media_name", ",", "system_type", ",", "efi", ",", "bootable", ")", ":", "# type: (inode.Inode, int, int, str, int, bool, bool) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'El Torito Boot Catalog not yet initialized'", ")", "# The Eltorito Boot Catalog can only be 2048 bytes (1 extent). By", "# default, the first 64 bytes are used by the Validation Entry and the", "# Initial Entry, which leaves 1984 bytes. Each section takes up 32", "# bytes for the Section Header and 32 bytes for the Section Entry, for", "# a total of 64 bytes, so we can have a maximum of 1984/64 = 31", "# sections.", "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. Parameters: ino - The Inode object to associate with the new Entry. sector_count - The number of sectors to assign to the new Entry. load_seg - The load segment address of the boot image. media_name - The name of the media type, one of 'noemul', 'floppy', or 'hdemul'. system_type - The type of partition this entry should be. efi - Whether this section is an EFI section. bootable - Whether this entry should be bootable. Returns: Nothing.
[ "A", "method", "to", "add", "an", "section", "header", "and", "entry", "to", "this", "Boot", "Catalog", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L745-L790
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoBootCatalog.record
def record(self): # type: () -> bytes ''' A method to generate a string representing this El Torito Boot Catalog. Parameters: None. Returns: A string representing this El Torito Boot Catalog. ''' 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)
python
def record(self): # type: () -> bytes ''' A method to generate a string representing this El Torito Boot Catalog. Parameters: None. Returns: A string representing this El Torito Boot Catalog. ''' 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)
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "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. Parameters: None. Returns: A string representing this El Torito Boot Catalog.
[ "A", "method", "to", "generate", "a", "string", "representing", "this", "El", "Torito", "Boot", "Catalog", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L792-L813
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoBootCatalog.add_dirrecord
def add_dirrecord(self, rec): # type: (Union[dr.DirectoryRecord, udfmod.UDFFileEntry]) -> None ''' A method to set the Directory Record associated with this Boot Catalog. Parameters: rec - The DirectoryRecord object to associate with this Boot Catalog. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Boot Catalog not yet initialized') self.dirrecords.append(rec)
python
def add_dirrecord(self, rec): # type: (Union[dr.DirectoryRecord, udfmod.UDFFileEntry]) -> None ''' A method to set the Directory Record associated with this Boot Catalog. Parameters: rec - The DirectoryRecord object to associate with this Boot Catalog. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('El Torito Boot Catalog not yet initialized') self.dirrecords.append(rec)
[ "def", "add_dirrecord", "(", "self", ",", "rec", ")", ":", "# type: (Union[dr.DirectoryRecord, udfmod.UDFFileEntry]) -> None", "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. Parameters: rec - The DirectoryRecord object to associate with this Boot Catalog. Returns: Nothing.
[ "A", "method", "to", "set", "the", "Directory", "Record", "associated", "with", "this", "Boot", "Catalog", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L815-L828
train
clalancette/pycdlib
pycdlib/eltorito.py
EltoritoBootCatalog.update_catalog_extent
def update_catalog_extent(self, current_extent): # type: (int) -> None ''' A method to update the extent associated with this Boot Catalog. Parameters: current_extent - New extent to associate with this Boot Catalog Returns: Nothing. ''' 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))
python
def update_catalog_extent(self, current_extent): # type: (int) -> None ''' A method to update the extent associated with this Boot Catalog. Parameters: current_extent - New extent to associate with this Boot Catalog Returns: Nothing. ''' 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))
[ "def", "update_catalog_extent", "(", "self", ",", "current_extent", ")", ":", "# type: (int) -> None", "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. Parameters: current_extent - New extent to associate with this Boot Catalog Returns: Nothing.
[ "A", "method", "to", "update", "the", "extent", "associated", "with", "this", "Boot", "Catalog", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/eltorito.py#L857-L870
train
clalancette/pycdlib
pycdlib/pycdlib.py
_check_d1_characters
def _check_d1_characters(name): # type: (bytes) -> None ''' A function to check that a name only uses d1 characters as defined by ISO9660. Parameters: name - The name to check. Returns: Nothing. ''' 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 _')
python
def _check_d1_characters(name): # type: (bytes) -> None ''' A function to check that a name only uses d1 characters as defined by ISO9660. Parameters: name - The name to check. Returns: Nothing. ''' 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 _')
[ "def", "_check_d1_characters", "(", "name", ")", ":", "# type: (bytes) -> None", "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. Parameters: name - The name to check. Returns: Nothing.
[ "A", "function", "to", "check", "that", "a", "name", "only", "uses", "d1", "characters", "as", "defined", "by", "ISO9660", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L68-L81
train
clalancette/pycdlib
pycdlib/pycdlib.py
_split_iso9660_filename
def _split_iso9660_filename(fullname): # type: (bytes) -> Tuple[bytes, bytes, bytes] ''' A function to split an ISO 9660 filename into its constituent parts. This is the name, the extension, and the version number. Parameters: fullname - The name to split. Returns: A tuple containing the name, extension, and version. ''' 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)
python
def _split_iso9660_filename(fullname): # type: (bytes) -> Tuple[bytes, bytes, bytes] ''' A function to split an ISO 9660 filename into its constituent parts. This is the name, the extension, and the version number. Parameters: fullname - The name to split. Returns: A tuple containing the name, extension, and version. ''' 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)
[ "def", "_split_iso9660_filename", "(", "fullname", ")", ":", "# type: (bytes) -> Tuple[bytes, bytes, bytes]", "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. Parameters: fullname - The name to split. Returns: A tuple containing the name, extension, and version.
[ "A", "function", "to", "split", "an", "ISO", "9660", "filename", "into", "its", "constituent", "parts", ".", "This", "is", "the", "name", "the", "extension", "and", "the", "version", "number", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L84-L110
train
clalancette/pycdlib
pycdlib/pycdlib.py
_check_iso9660_filename
def _check_iso9660_filename(fullname, interchange_level): # type: (bytes, int) -> None ''' A function to check that a file identifier conforms to the ISO9660 rules for a particular interchange level. Parameters: fullname - The name to check. interchange_level - The interchange level to check against. Returns: Nothing. ''' # Check to ensure the name is a valid filename for the ISO according to # Ecma-119 7.5. (name, extension, version) = _split_iso9660_filename(fullname) # Ecma-119 says that filenames must end with a semicolon-number, but I have # found CDs (Ubuntu 14.04 Desktop i386, for instance) that do not follow # this. Thus we allow for names both with and without the semi+version. # Ecma-119 says that filenames must have a version number, but I have # found CDs (FreeBSD 10.1 amd64) that do not have any version number. # Allow for this. if version != b'' and (int(version) < 1 or int(version) > 32767): raise pycdlibexception.PyCdlibInvalidInput('ISO9660 filenames must have a version between 1 and 32767') # Ecma-119 section 7.5.1 specifies that filenames must have at least one # character in either the name or the extension. 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: # According to Ecma-119, section 10.1, at level 1 the filename can # only be up to 8 d-characters or d1-characters, and the extension can # only be up to 3 d-characters or 3 d1-characters. 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: # For all other interchange levels, the maximum filename length is # specified in Ecma-119 7.5.2. However, I have found CDs (Ubuntu 14.04 # Desktop i386, for instance) that don't conform to this. Skip the # check until we know how long is allowed. pass # Ecma-119 section 7.5.1 says that the file name and extension each contain # zero or more d-characters or d1-characters. While the definition of # d-characters and d1-characters is not specified in Ecma-119, # http://wiki.osdev.org/ISO_9660 suggests that this consists of A-Z, 0-9, _ # which seems to correlate with empirical evidence. Thus we check for that # here. if interchange_level < 4: _check_d1_characters(name) _check_d1_characters(extension)
python
def _check_iso9660_filename(fullname, interchange_level): # type: (bytes, int) -> None ''' A function to check that a file identifier conforms to the ISO9660 rules for a particular interchange level. Parameters: fullname - The name to check. interchange_level - The interchange level to check against. Returns: Nothing. ''' # Check to ensure the name is a valid filename for the ISO according to # Ecma-119 7.5. (name, extension, version) = _split_iso9660_filename(fullname) # Ecma-119 says that filenames must end with a semicolon-number, but I have # found CDs (Ubuntu 14.04 Desktop i386, for instance) that do not follow # this. Thus we allow for names both with and without the semi+version. # Ecma-119 says that filenames must have a version number, but I have # found CDs (FreeBSD 10.1 amd64) that do not have any version number. # Allow for this. if version != b'' and (int(version) < 1 or int(version) > 32767): raise pycdlibexception.PyCdlibInvalidInput('ISO9660 filenames must have a version between 1 and 32767') # Ecma-119 section 7.5.1 specifies that filenames must have at least one # character in either the name or the extension. 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: # According to Ecma-119, section 10.1, at level 1 the filename can # only be up to 8 d-characters or d1-characters, and the extension can # only be up to 3 d-characters or 3 d1-characters. 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: # For all other interchange levels, the maximum filename length is # specified in Ecma-119 7.5.2. However, I have found CDs (Ubuntu 14.04 # Desktop i386, for instance) that don't conform to this. Skip the # check until we know how long is allowed. pass # Ecma-119 section 7.5.1 says that the file name and extension each contain # zero or more d-characters or d1-characters. While the definition of # d-characters and d1-characters is not specified in Ecma-119, # http://wiki.osdev.org/ISO_9660 suggests that this consists of A-Z, 0-9, _ # which seems to correlate with empirical evidence. Thus we check for that # here. if interchange_level < 4: _check_d1_characters(name) _check_d1_characters(extension)
[ "def", "_check_iso9660_filename", "(", "fullname", ",", "interchange_level", ")", ":", "# type: (bytes, int) -> None", "# Check to ensure the name is a valid filename for the ISO according to", "# Ecma-119 7.5.", "(", "name", ",", "extension", ",", "version", ")", "=", "_split_iso9660_filename", "(", "fullname", ")", "# Ecma-119 says that filenames must end with a semicolon-number, but I have", "# found CDs (Ubuntu 14.04 Desktop i386, for instance) that do not follow", "# this. Thus we allow for names both with and without the semi+version.", "# Ecma-119 says that filenames must have a version number, but I have", "# found CDs (FreeBSD 10.1 amd64) that do not have any version number.", "# Allow for this.", "if", "version", "!=", "b''", "and", "(", "int", "(", "version", ")", "<", "1", "or", "int", "(", "version", ")", ">", "32767", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidInput", "(", "'ISO9660 filenames must have a version between 1 and 32767'", ")", "# Ecma-119 section 7.5.1 specifies that filenames must have at least one", "# character in either the name or the extension.", "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", ":", "# According to Ecma-119, section 10.1, at level 1 the filename can", "# only be up to 8 d-characters or d1-characters, and the extension can", "# only be up to 3 d-characters or 3 d1-characters.", "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", ":", "# For all other interchange levels, the maximum filename length is", "# specified in Ecma-119 7.5.2. However, I have found CDs (Ubuntu 14.04", "# Desktop i386, for instance) that don't conform to this. Skip the", "# check until we know how long is allowed.", "pass", "# Ecma-119 section 7.5.1 says that the file name and extension each contain", "# zero or more d-characters or d1-characters. While the definition of", "# d-characters and d1-characters is not specified in Ecma-119,", "# http://wiki.osdev.org/ISO_9660 suggests that this consists of A-Z, 0-9, _", "# which seems to correlate with empirical evidence. Thus we check for that", "# here.", "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. Parameters: fullname - The name to check. interchange_level - The interchange level to check against. Returns: Nothing.
[ "A", "function", "to", "check", "that", "a", "file", "identifier", "conforms", "to", "the", "ISO9660", "rules", "for", "a", "particular", "interchange", "level", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L113-L171
train
clalancette/pycdlib
pycdlib/pycdlib.py
_check_iso9660_directory
def _check_iso9660_directory(fullname, interchange_level): # type: (bytes, int) -> None ''' A function to check that an directory identifier conforms to the ISO9660 rules for a particular interchange level. Parameters: fullname - The name to check. interchange_level - The interchange level to check against. Returns: Nothing. ''' # Check to ensure the directory name is valid for the ISO according to # Ecma-119 7.6. # Ecma-119 section 7.6.1 says that a directory identifier needs at least one # character if not fullname: raise pycdlibexception.PyCdlibInvalidInput('ISO9660 directory names must be at least 1 character long') maxlen = float('inf') if interchange_level == 1: # Ecma-119 section 10.1 says that directory identifiers lengths cannot # exceed 8 at interchange level 1. maxlen = 8 elif interchange_level in (2, 3): # Ecma-119 section 7.6.3 says that directory identifiers lengths cannot # exceed 207. maxlen = 207 # for interchange_level 4, we allow any length if len(fullname) > maxlen: raise pycdlibexception.PyCdlibInvalidInput('ISO9660 directory names at interchange level %d cannot exceed %d characters' % (interchange_level, maxlen)) # Ecma-119 section 7.6.1 says that directory names consist of one or more # d-characters or d1-characters. While the definition of d-characters and # d1-characters is not specified in Ecma-119, # http://wiki.osdev.org/ISO_9660 suggests that this consists of A-Z, 0-9, _ # which seems to correlate with empirical evidence. Thus we check for that # here. if interchange_level < 4: _check_d1_characters(fullname)
python
def _check_iso9660_directory(fullname, interchange_level): # type: (bytes, int) -> None ''' A function to check that an directory identifier conforms to the ISO9660 rules for a particular interchange level. Parameters: fullname - The name to check. interchange_level - The interchange level to check against. Returns: Nothing. ''' # Check to ensure the directory name is valid for the ISO according to # Ecma-119 7.6. # Ecma-119 section 7.6.1 says that a directory identifier needs at least one # character if not fullname: raise pycdlibexception.PyCdlibInvalidInput('ISO9660 directory names must be at least 1 character long') maxlen = float('inf') if interchange_level == 1: # Ecma-119 section 10.1 says that directory identifiers lengths cannot # exceed 8 at interchange level 1. maxlen = 8 elif interchange_level in (2, 3): # Ecma-119 section 7.6.3 says that directory identifiers lengths cannot # exceed 207. maxlen = 207 # for interchange_level 4, we allow any length if len(fullname) > maxlen: raise pycdlibexception.PyCdlibInvalidInput('ISO9660 directory names at interchange level %d cannot exceed %d characters' % (interchange_level, maxlen)) # Ecma-119 section 7.6.1 says that directory names consist of one or more # d-characters or d1-characters. While the definition of d-characters and # d1-characters is not specified in Ecma-119, # http://wiki.osdev.org/ISO_9660 suggests that this consists of A-Z, 0-9, _ # which seems to correlate with empirical evidence. Thus we check for that # here. if interchange_level < 4: _check_d1_characters(fullname)
[ "def", "_check_iso9660_directory", "(", "fullname", ",", "interchange_level", ")", ":", "# type: (bytes, int) -> None", "# Check to ensure the directory name is valid for the ISO according to", "# Ecma-119 7.6.", "# Ecma-119 section 7.6.1 says that a directory identifier needs at least one", "# character", "if", "not", "fullname", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidInput", "(", "'ISO9660 directory names must be at least 1 character long'", ")", "maxlen", "=", "float", "(", "'inf'", ")", "if", "interchange_level", "==", "1", ":", "# Ecma-119 section 10.1 says that directory identifiers lengths cannot", "# exceed 8 at interchange level 1.", "maxlen", "=", "8", "elif", "interchange_level", "in", "(", "2", ",", "3", ")", ":", "# Ecma-119 section 7.6.3 says that directory identifiers lengths cannot", "# exceed 207.", "maxlen", "=", "207", "# for interchange_level 4, we allow any length", "if", "len", "(", "fullname", ")", ">", "maxlen", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidInput", "(", "'ISO9660 directory names at interchange level %d cannot exceed %d characters'", "%", "(", "interchange_level", ",", "maxlen", ")", ")", "# Ecma-119 section 7.6.1 says that directory names consist of one or more", "# d-characters or d1-characters. While the definition of d-characters and", "# d1-characters is not specified in Ecma-119,", "# http://wiki.osdev.org/ISO_9660 suggests that this consists of A-Z, 0-9, _", "# which seems to correlate with empirical evidence. Thus we check for that", "# here.", "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. Parameters: fullname - The name to check. interchange_level - The interchange level to check against. Returns: Nothing.
[ "A", "function", "to", "check", "that", "an", "directory", "identifier", "conforms", "to", "the", "ISO9660", "rules", "for", "a", "particular", "interchange", "level", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L174-L215
train
clalancette/pycdlib
pycdlib/pycdlib.py
_interchange_level_from_filename
def _interchange_level_from_filename(fullname): # type: (bytes) -> int ''' 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. Parameters: name - The name to use to determine the interchange level. Returns: The interchange level determined from this filename. ''' (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
python
def _interchange_level_from_filename(fullname): # type: (bytes) -> int ''' 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. Parameters: name - The name to use to determine the interchange level. Returns: The interchange level determined from this filename. ''' (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
[ "def", "_interchange_level_from_filename", "(", "fullname", ")", ":", "# type: (bytes) -> int", "(", "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. Parameters: name - The name to use to determine the interchange level. Returns: The interchange level determined from this filename.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L218-L249
train
clalancette/pycdlib
pycdlib/pycdlib.py
_interchange_level_from_directory
def _interchange_level_from_directory(name): # type: (bytes) -> int ''' 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. Parameters: name - The name to use to determine the interchange level. Returns: The interchange level determined from this filename. ''' interchange_level = 1 if len(name) > 8: interchange_level = 3 try: _check_d1_characters(name) except pycdlibexception.PyCdlibInvalidInput: interchange_level = 3 return interchange_level
python
def _interchange_level_from_directory(name): # type: (bytes) -> int ''' 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. Parameters: name - The name to use to determine the interchange level. Returns: The interchange level determined from this filename. ''' interchange_level = 1 if len(name) > 8: interchange_level = 3 try: _check_d1_characters(name) except pycdlibexception.PyCdlibInvalidInput: interchange_level = 3 return interchange_level
[ "def", "_interchange_level_from_directory", "(", "name", ")", ":", "# type: (bytes) -> int", "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. Parameters: name - The name to use to determine the interchange level. Returns: The interchange level determined from this filename.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L252-L273
train
clalancette/pycdlib
pycdlib/pycdlib.py
_yield_children
def _yield_children(rec): # type: (dr.DirectoryRecord) -> Generator ''' An internal function to gather and yield all of the children of a Directory Record. Parameters: rec - The Directory Record to get all of the children from (must be a directory) Yields: Children of this Directory Record. Returns: Nothing. ''' if not rec.is_dir(): raise pycdlibexception.PyCdlibInvalidInput('Record is not a directory!') last = b'' for child in rec.children: # Check to see if the filename of this child is the same as the # last one, and if so, skip the child. This can happen if we # have very large files with more than one directory entry. 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: # If this is the case, this is a relocated entry. We actually # want to go find the entry this was relocated to; we do that # by following the child_link, then going up to the parent and # finding the entry that links to the same one as this one. 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 # If we ended up not finding the right one in the parent of the # moved entry, weird, but just return the one we would have # anyway. yield child
python
def _yield_children(rec): # type: (dr.DirectoryRecord) -> Generator ''' An internal function to gather and yield all of the children of a Directory Record. Parameters: rec - The Directory Record to get all of the children from (must be a directory) Yields: Children of this Directory Record. Returns: Nothing. ''' if not rec.is_dir(): raise pycdlibexception.PyCdlibInvalidInput('Record is not a directory!') last = b'' for child in rec.children: # Check to see if the filename of this child is the same as the # last one, and if so, skip the child. This can happen if we # have very large files with more than one directory entry. 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: # If this is the case, this is a relocated entry. We actually # want to go find the entry this was relocated to; we do that # by following the child_link, then going up to the parent and # finding the entry that links to the same one as this one. 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 # If we ended up not finding the right one in the parent of the # moved entry, weird, but just return the one we would have # anyway. yield child
[ "def", "_yield_children", "(", "rec", ")", ":", "# type: (dr.DirectoryRecord) -> Generator", "if", "not", "rec", ".", "is_dir", "(", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidInput", "(", "'Record is not a directory!'", ")", "last", "=", "b''", "for", "child", "in", "rec", ".", "children", ":", "# Check to see if the filename of this child is the same as the", "# last one, and if so, skip the child. This can happen if we", "# have very large files with more than one directory entry.", "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", ":", "# If this is the case, this is a relocated entry. We actually", "# want to go find the entry this was relocated to; we do that", "# by following the child_link, then going up to the parent and", "# finding the entry that links to the same one as this one.", "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", "# If we ended up not finding the right one in the parent of the", "# moved entry, weird, but just return the one we would have", "# anyway.", "yield", "child" ]
An internal function to gather and yield all of the children of a Directory Record. Parameters: rec - The Directory Record to get all of the children from (must be a directory) Yields: Children of this Directory Record. Returns: Nothing.
[ "An", "internal", "function", "to", "gather", "and", "yield", "all", "of", "the", "children", "of", "a", "Directory", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L417-L458
train
clalancette/pycdlib
pycdlib/pycdlib.py
_assign_udf_desc_extents
def _assign_udf_desc_extents(descs, start_extent): # type: (PyCdlib._UDFDescriptors, int) -> None ''' An internal function to assign a consecutive sequence of extents for the given set of UDF Descriptors, starting at the given extent. Parameters: descs - The PyCdlib._UDFDescriptors object to assign extents for. start_extent - The starting extent to assign from. Returns: Nothing. ''' 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
python
def _assign_udf_desc_extents(descs, start_extent): # type: (PyCdlib._UDFDescriptors, int) -> None ''' An internal function to assign a consecutive sequence of extents for the given set of UDF Descriptors, starting at the given extent. Parameters: descs - The PyCdlib._UDFDescriptors object to assign extents for. start_extent - The starting extent to assign from. Returns: Nothing. ''' 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
[ "def", "_assign_udf_desc_extents", "(", "descs", ",", "start_extent", ")", ":", "# type: (PyCdlib._UDFDescriptors, int) -> None", "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. Parameters: descs - The PyCdlib._UDFDescriptors object to assign extents for. start_extent - The starting extent to assign from. Returns: Nothing.
[ "An", "internal", "function", "to", "assign", "a", "consecutive", "sequence", "of", "extents", "for", "the", "given", "set", "of", "UDF", "Descriptors", "starting", "at", "the", "given", "extent", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L461-L491
train
clalancette/pycdlib
pycdlib/pycdlib.py
_find_dr_record_by_name
def _find_dr_record_by_name(vd, path, encoding): # type: (headervd.PrimaryOrSupplementaryVD, bytes, str) -> dr.DirectoryRecord ''' 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. Parameters: vd - The Volume Descriptor to look in for the Directory Record. path - The ISO or Joliet entry to find the Directory Record for. encoding - The string encoding used for the path. Returns: The directory record entry representing the entry on the ISO. ''' if not utils.starts_with_slash(path): raise pycdlibexception.PyCdlibInvalidInput('Must be a path starting with /') root_dir_record = vd.root_directory_record() # If the path is just the slash, we just want the root directory, so # get the child there and quit. if path == b'/': return root_dir_record # Split the path along the slashes 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: # We failed to find this component of the path, so break out of the # loop and fail break if child.rock_ridge is not None and child.rock_ridge.child_link_record_exists(): # Here, the rock ridge extension has a child link, so we # need to follow it. child = child.rock_ridge.cl_to_moved_dr if child is None: break # We found the child, and it is the last one we are looking for; # return it. 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')
python
def _find_dr_record_by_name(vd, path, encoding): # type: (headervd.PrimaryOrSupplementaryVD, bytes, str) -> dr.DirectoryRecord ''' 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. Parameters: vd - The Volume Descriptor to look in for the Directory Record. path - The ISO or Joliet entry to find the Directory Record for. encoding - The string encoding used for the path. Returns: The directory record entry representing the entry on the ISO. ''' if not utils.starts_with_slash(path): raise pycdlibexception.PyCdlibInvalidInput('Must be a path starting with /') root_dir_record = vd.root_directory_record() # If the path is just the slash, we just want the root directory, so # get the child there and quit. if path == b'/': return root_dir_record # Split the path along the slashes 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: # We failed to find this component of the path, so break out of the # loop and fail break if child.rock_ridge is not None and child.rock_ridge.child_link_record_exists(): # Here, the rock ridge extension has a child link, so we # need to follow it. child = child.rock_ridge.cl_to_moved_dr if child is None: break # We found the child, and it is the last one we are looking for; # return it. 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')
[ "def", "_find_dr_record_by_name", "(", "vd", ",", "path", ",", "encoding", ")", ":", "# type: (headervd.PrimaryOrSupplementaryVD, bytes, str) -> dr.DirectoryRecord", "if", "not", "utils", ".", "starts_with_slash", "(", "path", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidInput", "(", "'Must be a path starting with /'", ")", "root_dir_record", "=", "vd", ".", "root_directory_record", "(", ")", "# If the path is just the slash, we just want the root directory, so", "# get the child there and quit.", "if", "path", "==", "b'/'", ":", "return", "root_dir_record", "# Split the path along the slashes", "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", ":", "# We failed to find this component of the path, so break out of the", "# loop and fail", "break", "if", "child", ".", "rock_ridge", "is", "not", "None", "and", "child", ".", "rock_ridge", ".", "child_link_record_exists", "(", ")", ":", "# Here, the rock ridge extension has a child link, so we", "# need to follow it.", "child", "=", "child", ".", "rock_ridge", ".", "cl_to_moved_dr", "if", "child", "is", "None", ":", "break", "# We found the child, and it is the last one we are looking for;", "# return it.", "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. Parameters: vd - The Volume Descriptor to look in for the Directory Record. path - The ISO or Joliet entry to find the Directory Record for. encoding - The string encoding used for the path. Returns: The directory record entry representing the entry on the ISO.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L494-L567
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlibIO.read
def read(self, size=None): # type: (Optional[int]) -> bytes ''' A method to read and return up to size bytes. Parameters: size - Optional parameter to read size number of bytes; if None or negative, all remaining bytes in the file will be read Returns: The number of bytes requested or the rest of the data left in the file, whichever is smaller. If the file is at or past EOF, returns an empty bytestring. ''' 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
python
def read(self, size=None): # type: (Optional[int]) -> bytes ''' A method to read and return up to size bytes. Parameters: size - Optional parameter to read size number of bytes; if None or negative, all remaining bytes in the file will be read Returns: The number of bytes requested or the rest of the data left in the file, whichever is smaller. If the file is at or past EOF, returns an empty bytestring. ''' 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
[ "def", "read", "(", "self", ",", "size", "=", "None", ")", ":", "# type: (Optional[int]) -> bytes", "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. Parameters: size - Optional parameter to read size number of bytes; if None or negative, all remaining bytes in the file will be read Returns: The number of bytes requested or the rest of the data left in the file, whichever is smaller. If the file is at or past EOF, returns an empty bytestring.
[ "A", "method", "to", "read", "and", "return", "up", "to", "size", "bytes", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L594-L620
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlibIO.readall
def readall(self): # type: () -> bytes ''' A method to read and return the remaining bytes in the file. Parameters: None. Returns: The rest of the data left in the file. If the file is at or past EOF, returns an empty bytestring. ''' 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
python
def readall(self): # type: () -> bytes ''' A method to read and return the remaining bytes in the file. Parameters: None. Returns: The rest of the data left in the file. If the file is at or past EOF, returns an empty bytestring. ''' 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
[ "def", "readall", "(", "self", ")", ":", "# type: () -> bytes", "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. Parameters: None. Returns: The rest of the data left in the file. If the file is at or past EOF, returns an empty bytestring.
[ "A", "method", "to", "read", "and", "return", "the", "remaining", "bytes", "in", "the", "file", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L622-L643
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._parse_volume_descriptors
def _parse_volume_descriptors(self): # type: () -> None ''' An internal method to parse the volume descriptors on an ISO. Parameters: None. Returns: Nothing. ''' # Ecma-119 says that the Volume Descriptor set is a sequence of volume # descriptors recorded in consecutively numbered Logical Sectors # starting with Logical Sector Number 16. Since sectors are 2048 bytes # in length, we start at sector 16 * 2048 # Ecma-119, 6.2.1 says that the Volume Space is divided into a System # Area and a Data Area, where the System Area is in logical sectors 0 # to 15, and whose contents is not specified by the standard. self._cdfp.seek(16 * 2048) while True: # All volume descriptors are exactly 2048 bytes long 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'): # We read the next extent, and it wasn't a descriptor. Abort # the loop, remembering to back up the input file descriptor. 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: # Both an Ecma-119 Boot Record and a Ecma-TR 071 UDF-Bridge # Beginning Extended Area Descriptor have the first byte as 0, # so we can't tell which it is until we look at the next 5 # bytes (Boot Record will have 'CD001', BEAD will have 'BEA01'). 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: # This isn't really possible, since we would have aborted # the loop above. 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) # Since we checked for the valid descriptors above, it is impossible # to see an invalid desc_type here, so no check necessary. # The language in Ecma-119, p.8, Section 6.7.1 says: # # The sequence shall contain one Primary Volume Descriptor (see 8.4) recorded at least once. # # The important bit there is "at least one", which means that we have # to accept ISOs with more than one PVD. if not self.pvds: raise pycdlibexception.PyCdlibInvalidISO('Valid ISO9660 filesystems must have at least one PVD') self.pvd = self.pvds[0] # Make sure any other PVDs agree with the first one. 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')
python
def _parse_volume_descriptors(self): # type: () -> None ''' An internal method to parse the volume descriptors on an ISO. Parameters: None. Returns: Nothing. ''' # Ecma-119 says that the Volume Descriptor set is a sequence of volume # descriptors recorded in consecutively numbered Logical Sectors # starting with Logical Sector Number 16. Since sectors are 2048 bytes # in length, we start at sector 16 * 2048 # Ecma-119, 6.2.1 says that the Volume Space is divided into a System # Area and a Data Area, where the System Area is in logical sectors 0 # to 15, and whose contents is not specified by the standard. self._cdfp.seek(16 * 2048) while True: # All volume descriptors are exactly 2048 bytes long 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'): # We read the next extent, and it wasn't a descriptor. Abort # the loop, remembering to back up the input file descriptor. 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: # Both an Ecma-119 Boot Record and a Ecma-TR 071 UDF-Bridge # Beginning Extended Area Descriptor have the first byte as 0, # so we can't tell which it is until we look at the next 5 # bytes (Boot Record will have 'CD001', BEAD will have 'BEA01'). 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: # This isn't really possible, since we would have aborted # the loop above. 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) # Since we checked for the valid descriptors above, it is impossible # to see an invalid desc_type here, so no check necessary. # The language in Ecma-119, p.8, Section 6.7.1 says: # # The sequence shall contain one Primary Volume Descriptor (see 8.4) recorded at least once. # # The important bit there is "at least one", which means that we have # to accept ISOs with more than one PVD. if not self.pvds: raise pycdlibexception.PyCdlibInvalidISO('Valid ISO9660 filesystems must have at least one PVD') self.pvd = self.pvds[0] # Make sure any other PVDs agree with the first one. 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')
[ "def", "_parse_volume_descriptors", "(", "self", ")", ":", "# type: () -> None", "# Ecma-119 says that the Volume Descriptor set is a sequence of volume", "# descriptors recorded in consecutively numbered Logical Sectors", "# starting with Logical Sector Number 16. Since sectors are 2048 bytes", "# in length, we start at sector 16 * 2048", "# Ecma-119, 6.2.1 says that the Volume Space is divided into a System", "# Area and a Data Area, where the System Area is in logical sectors 0", "# to 15, and whose contents is not specified by the standard.", "self", ".", "_cdfp", ".", "seek", "(", "16", "*", "2048", ")", "while", "True", ":", "# All volume descriptors are exactly 2048 bytes long", "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'", ")", ":", "# We read the next extent, and it wasn't a descriptor. Abort", "# the loop, remembering to back up the input file descriptor.", "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", ":", "# Both an Ecma-119 Boot Record and a Ecma-TR 071 UDF-Bridge", "# Beginning Extended Area Descriptor have the first byte as 0,", "# so we can't tell which it is until we look at the next 5", "# bytes (Boot Record will have 'CD001', BEAD will have 'BEA01').", "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", ":", "# This isn't really possible, since we would have aborted", "# the loop above.", "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", ")", "# Since we checked for the valid descriptors above, it is impossible", "# to see an invalid desc_type here, so no check necessary.", "# The language in Ecma-119, p.8, Section 6.7.1 says:", "#", "# The sequence shall contain one Primary Volume Descriptor (see 8.4) recorded at least once.", "#", "# The important bit there is \"at least one\", which means that we have", "# to accept ISOs with more than one PVD.", "if", "not", "self", ".", "pvds", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Valid ISO9660 filesystems must have at least one PVD'", ")", "self", ".", "pvd", "=", "self", ".", "pvds", "[", "0", "]", "# Make sure any other PVDs agree with the first one.", "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. Parameters: None. Returns: Nothing.
[ "An", "internal", "method", "to", "parse", "the", "volume", "descriptors", "on", "an", "ISO", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L838-L926
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._seek_to_extent
def _seek_to_extent(self, extent): # type: (int) -> None ''' An internal method to seek to a particular extent on the input ISO. Parameters: extent - The extent to seek to. Returns: Nothing. ''' self._cdfp.seek(extent * self.pvd.logical_block_size())
python
def _seek_to_extent(self, extent): # type: (int) -> None ''' An internal method to seek to a particular extent on the input ISO. Parameters: extent - The extent to seek to. Returns: Nothing. ''' self._cdfp.seek(extent * self.pvd.logical_block_size())
[ "def", "_seek_to_extent", "(", "self", ",", "extent", ")", ":", "# type: (int) -> None", "self", ".", "_cdfp", ".", "seek", "(", "extent", "*", "self", ".", "pvd", ".", "logical_block_size", "(", ")", ")" ]
An internal method to seek to a particular extent on the input ISO. Parameters: extent - The extent to seek to. Returns: Nothing.
[ "An", "internal", "method", "to", "seek", "to", "a", "particular", "extent", "on", "the", "input", "ISO", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L928-L938
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._find_rr_record
def _find_rr_record(self, rr_path): # type: (bytes) -> dr.DirectoryRecord ''' 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. Parameters: rr_path - The Rock Ridge path to lookup. Returns: The directory record entry representing the entry on the ISO. ''' 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 the path is just the slash, we just want the root directory, so # get the child there and quit. if rr_path == b'/': return root_dir_record # Split the path along the slashes 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: # We failed to find this component of the path, so break out of the # loop and fail break if child.rock_ridge is not None and child.rock_ridge.child_link_record_exists(): # Here, the rock ridge extension has a child link, so we # need to follow it. child = child.rock_ridge.cl_to_moved_dr if child is None: break # We found the child, and it is the last one we are looking for; # return it. 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')
python
def _find_rr_record(self, rr_path): # type: (bytes) -> dr.DirectoryRecord ''' 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. Parameters: rr_path - The Rock Ridge path to lookup. Returns: The directory record entry representing the entry on the ISO. ''' 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 the path is just the slash, we just want the root directory, so # get the child there and quit. if rr_path == b'/': return root_dir_record # Split the path along the slashes 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: # We failed to find this component of the path, so break out of the # loop and fail break if child.rock_ridge is not None and child.rock_ridge.child_link_record_exists(): # Here, the rock ridge extension has a child link, so we # need to follow it. child = child.rock_ridge.cl_to_moved_dr if child is None: break # We found the child, and it is the last one we are looking for; # return it. 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')
[ "def", "_find_rr_record", "(", "self", ",", "rr_path", ")", ":", "# type: (bytes) -> dr.DirectoryRecord", "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 the path is just the slash, we just want the root directory, so", "# get the child there and quit.", "if", "rr_path", "==", "b'/'", ":", "return", "root_dir_record", "# Split the path along the slashes", "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", ":", "# We failed to find this component of the path, so break out of the", "# loop and fail", "break", "if", "child", ".", "rock_ridge", "is", "not", "None", "and", "child", ".", "rock_ridge", ".", "child_link_record_exists", "(", ")", ":", "# Here, the rock ridge extension has a child link, so we", "# need to follow it.", "child", "=", "child", ".", "rock_ridge", ".", "cl_to_moved_dr", "if", "child", "is", "None", ":", "break", "# We found the child, and it is the last one we are looking for;", "# return it.", "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. Parameters: rr_path - The Rock Ridge path to lookup. Returns: The directory record entry representing the entry on the ISO.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L957-L1032
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._find_joliet_record
def _find_joliet_record(self, joliet_path): # type: (bytes) -> dr.DirectoryRecord ''' 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. Parameters: joliet_path - The Joliet path to lookup. Returns: The directory record entry representing the entry on the ISO. ''' 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')
python
def _find_joliet_record(self, joliet_path): # type: (bytes) -> dr.DirectoryRecord ''' 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. Parameters: joliet_path - The Joliet path to lookup. Returns: The directory record entry representing the entry on the ISO. ''' 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')
[ "def", "_find_joliet_record", "(", "self", ",", "joliet_path", ")", ":", "# type: (bytes) -> dr.DirectoryRecord", "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. Parameters: joliet_path - The Joliet path to lookup. Returns: The directory record entry representing the entry on the ISO.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L1035-L1050
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._find_udf_record
def _find_udf_record(self, udf_path): # type: (bytes) -> Tuple[Optional[udfmod.UDFFileIdentifierDescriptor], udfmod.UDFFileEntry] ''' 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. Parameters: udf_path - The UDF path to lookup. Returns: The UDF File Entry representing the entry on the ISO. ''' # If the path is just the slash, we just want the root directory, so # get the child there and quit. if udf_path == b'/': return None, self.udf_root # type: ignore # Split the path along the slashes 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) # We found the child, and it is the last one we are looking for; # return it. if not splitpath: return child, child.file_entry # type: ignore if not child.is_dir(): break entry = child.file_entry currpath = splitpath.pop(0) raise pycdlibexception.PyCdlibInvalidInput('Could not find path')
python
def _find_udf_record(self, udf_path): # type: (bytes) -> Tuple[Optional[udfmod.UDFFileIdentifierDescriptor], udfmod.UDFFileEntry] ''' 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. Parameters: udf_path - The UDF path to lookup. Returns: The UDF File Entry representing the entry on the ISO. ''' # If the path is just the slash, we just want the root directory, so # get the child there and quit. if udf_path == b'/': return None, self.udf_root # type: ignore # Split the path along the slashes 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) # We found the child, and it is the last one we are looking for; # return it. if not splitpath: return child, child.file_entry # type: ignore if not child.is_dir(): break entry = child.file_entry currpath = splitpath.pop(0) raise pycdlibexception.PyCdlibInvalidInput('Could not find path')
[ "def", "_find_udf_record", "(", "self", ",", "udf_path", ")", ":", "# type: (bytes) -> Tuple[Optional[udfmod.UDFFileIdentifierDescriptor], udfmod.UDFFileEntry]", "# If the path is just the slash, we just want the root directory, so", "# get the child there and quit.", "if", "udf_path", "==", "b'/'", ":", "return", "None", ",", "self", ".", "udf_root", "# type: ignore", "# Split the path along the slashes", "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", ")", "# We found the child, and it is the last one we are looking for;", "# return it.", "if", "not", "splitpath", ":", "return", "child", ",", "child", ".", "file_entry", "# type: ignore", "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. Parameters: udf_path - The UDF path to lookup. Returns: The UDF File Entry representing the entry on the ISO.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L1053-L1091
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._iso_name_and_parent_from_path
def _iso_name_and_parent_from_path(self, iso_path): # type: (bytes) -> Tuple[bytes, dr.DirectoryRecord] ''' 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. Parameters: iso_path - The absolute ISO path to the entry on the ISO. Returns: A tuple containing just the name of the entry and a Directory Record object representing the parent of the entry. ''' 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)
python
def _iso_name_and_parent_from_path(self, iso_path): # type: (bytes) -> Tuple[bytes, dr.DirectoryRecord] ''' 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. Parameters: iso_path - The absolute ISO path to the entry on the ISO. Returns: A tuple containing just the name of the entry and a Directory Record object representing the parent of the entry. ''' 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)
[ "def", "_iso_name_and_parent_from_path", "(", "self", ",", "iso_path", ")", ":", "# type: (bytes) -> Tuple[bytes, dr.DirectoryRecord]", "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. Parameters: iso_path - The absolute ISO path to the entry on the ISO. Returns: A tuple containing just the name of the entry and a Directory Record object representing the parent of the entry.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L1093-L1112
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._joliet_name_and_parent_from_path
def _joliet_name_and_parent_from_path(self, joliet_path): # type: (bytes) -> Tuple[bytes, dr.DirectoryRecord] ''' 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. Parameters: joliet_path - The absolute Joliet path to the entry on the ISO. Returns: A tuple containing just the name of the entry and a Directory Record object representing the parent of the entry. ''' 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)
python
def _joliet_name_and_parent_from_path(self, joliet_path): # type: (bytes) -> Tuple[bytes, dr.DirectoryRecord] ''' 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. Parameters: joliet_path - The absolute Joliet path to the entry on the ISO. Returns: A tuple containing just the name of the entry and a Directory Record object representing the parent of the entry. ''' 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)
[ "def", "_joliet_name_and_parent_from_path", "(", "self", ",", "joliet_path", ")", ":", "# type: (bytes) -> Tuple[bytes, dr.DirectoryRecord]", "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. Parameters: joliet_path - The absolute Joliet path to the entry on the ISO. Returns: A tuple containing just the name of the entry and a Directory Record object representing the parent of the entry.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L1114-L1135
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._udf_name_and_parent_from_path
def _udf_name_and_parent_from_path(self, udf_path): # type: (bytes) -> Tuple[bytes, udfmod.UDFFileEntry] ''' 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. Parameters: udf_path - The absolute UDF path to the entry on the ISO. Returns: A tuple containing just the name of the entry and a UDF File Entry object representing the parent of the entry. ''' 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)
python
def _udf_name_and_parent_from_path(self, udf_path): # type: (bytes) -> Tuple[bytes, udfmod.UDFFileEntry] ''' 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. Parameters: udf_path - The absolute UDF path to the entry on the ISO. Returns: A tuple containing just the name of the entry and a UDF File Entry object representing the parent of the entry. ''' 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)
[ "def", "_udf_name_and_parent_from_path", "(", "self", ",", "udf_path", ")", ":", "# type: (bytes) -> Tuple[bytes, udfmod.UDFFileEntry]", "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. Parameters: udf_path - The absolute UDF path to the entry on the ISO. Returns: A tuple containing just the name of the entry and a UDF File Entry object representing the parent of the entry.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L1137-L1154
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._set_rock_ridge
def _set_rock_ridge(self, rr): # type: (str) -> None ''' An internal method to set the Rock Ridge version of the ISO given the Rock Ridge version of the previous entry. Parameters: rr - The version of rr from the last directory record. Returns: Nothing. ''' # We don't allow mixed Rock Ridge versions on the ISO, so apply some # checking. If the current overall Rock Ridge version on the ISO is # None, we upgrade it to whatever version we were given. Once we have # seen a particular version, we only allow records of that version or # None (to account for dotdot records which have no Rock Ridge). if not self.rock_ridge: self.rock_ridge = rr # type: str 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!')
python
def _set_rock_ridge(self, rr): # type: (str) -> None ''' An internal method to set the Rock Ridge version of the ISO given the Rock Ridge version of the previous entry. Parameters: rr - The version of rr from the last directory record. Returns: Nothing. ''' # We don't allow mixed Rock Ridge versions on the ISO, so apply some # checking. If the current overall Rock Ridge version on the ISO is # None, we upgrade it to whatever version we were given. Once we have # seen a particular version, we only allow records of that version or # None (to account for dotdot records which have no Rock Ridge). if not self.rock_ridge: self.rock_ridge = rr # type: str 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!')
[ "def", "_set_rock_ridge", "(", "self", ",", "rr", ")", ":", "# type: (str) -> None", "# We don't allow mixed Rock Ridge versions on the ISO, so apply some", "# checking. If the current overall Rock Ridge version on the ISO is", "# None, we upgrade it to whatever version we were given. Once we have", "# seen a particular version, we only allow records of that version or", "# None (to account for dotdot records which have no Rock Ridge).", "if", "not", "self", ".", "rock_ridge", ":", "self", ".", "rock_ridge", "=", "rr", "# type: str", "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. Parameters: rr - The version of rr from the last directory record. Returns: Nothing.
[ "An", "internal", "method", "to", "set", "the", "Rock", "Ridge", "version", "of", "the", "ISO", "given", "the", "Rock", "Ridge", "version", "of", "the", "previous", "entry", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L1156-L1178
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._parse_path_table
def _parse_path_table(self, ptr_size, extent): # type: (int, int) -> Tuple[List[path_table_record.PathTableRecord], Dict[int, path_table_record.PathTableRecord]] ''' 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. Parameters: vd - The volume descriptor that these path table records correspond to. extent - The extent at which this path table record starts. callback - The callback to call for each path table record. Returns: A tuple consisting of the list of path table record entries and a dictionary of the extent locations to the path table record entries. ''' 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
python
def _parse_path_table(self, ptr_size, extent): # type: (int, int) -> Tuple[List[path_table_record.PathTableRecord], Dict[int, path_table_record.PathTableRecord]] ''' 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. Parameters: vd - The volume descriptor that these path table records correspond to. extent - The extent at which this path table record starts. callback - The callback to call for each path table record. Returns: A tuple consisting of the list of path table record entries and a dictionary of the extent locations to the path table record entries. ''' 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
[ "def", "_parse_path_table", "(", "self", ",", "ptr_size", ",", "extent", ")", ":", "# type: (int, int) -> Tuple[List[path_table_record.PathTableRecord], Dict[int, path_table_record.PathTableRecord]]", "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. Parameters: vd - The volume descriptor that these path table records correspond to. extent - The extent at which this path table record starts. callback - The callback to call for each path table record. Returns: A tuple consisting of the list of path table record entries and a dictionary of the extent locations to the path table record entries.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L1434-L1464
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._check_and_parse_eltorito
def _check_and_parse_eltorito(self, br): # type: (headervd.BootRecord) -> None ''' 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. Parameters: br - The boot record to examine for an El Torito signature. Returns: Nothing. ''' 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') # According to the El Torito specification, section 2.0, the El # Torito boot record must be at extent 17. if br.extent_location() != 17: raise pycdlibexception.PyCdlibInvalidISO('El Torito Boot Record must be at extent 17') # Now that we have verified that the BootRecord is an El Torito one # and that it is sane, we go on to parse the El Torito Boot Catalog. # Note that the Boot Catalog is stored as a file in the ISO, though # we ignore that for the purposes of parsing. 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)
python
def _check_and_parse_eltorito(self, br): # type: (headervd.BootRecord) -> None ''' 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. Parameters: br - The boot record to examine for an El Torito signature. Returns: Nothing. ''' 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') # According to the El Torito specification, section 2.0, the El # Torito boot record must be at extent 17. if br.extent_location() != 17: raise pycdlibexception.PyCdlibInvalidISO('El Torito Boot Record must be at extent 17') # Now that we have verified that the BootRecord is an El Torito one # and that it is sane, we go on to parse the El Torito Boot Catalog. # Note that the Boot Catalog is stored as a file in the ISO, though # we ignore that for the purposes of parsing. 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)
[ "def", "_check_and_parse_eltorito", "(", "self", ",", "br", ")", ":", "# type: (headervd.BootRecord) -> None", "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'", ")", "# According to the El Torito specification, section 2.0, the El", "# Torito boot record must be at extent 17.", "if", "br", ".", "extent_location", "(", ")", "!=", "17", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'El Torito Boot Record must be at extent 17'", ")", "# Now that we have verified that the BootRecord is an El Torito one", "# and that it is sane, we go on to parse the El Torito Boot Catalog.", "# Note that the Boot Catalog is stored as a file in the ISO, though", "# we ignore that for the purposes of parsing.", "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. Parameters: br - The boot record to examine for an El Torito signature. Returns: Nothing.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L1466-L1502
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._remove_child_from_dr
def _remove_child_from_dr(self, child, index, logical_block_size): # type: (dr.DirectoryRecord, int, int) -> int ''' An internal method to remove a child from a directory record, shrinking the space in the Volume Descriptor if necessary. Parameters: child - The child to remove. index - The index of the child into the parent's child array. logical_block_size - The size of one logical block. Returns: The number of bytes to remove for this directory record (this may be zero). ''' if child.parent is None: raise pycdlibexception.PyCdlibInternalError('Trying to remove child from non-existent parent') self._find_iso_record.cache_clear() # pylint: disable=no-member self._find_rr_record.cache_clear() # pylint: disable=no-member self._find_joliet_record.cache_clear() # pylint: disable=no-member # The remove_child() method returns True if the parent no longer needs # the extent that the directory record for this child was on. Remove # the extent as appropriate here. if child.parent.remove_child(child, index, logical_block_size): return self.pvd.logical_block_size() return 0
python
def _remove_child_from_dr(self, child, index, logical_block_size): # type: (dr.DirectoryRecord, int, int) -> int ''' An internal method to remove a child from a directory record, shrinking the space in the Volume Descriptor if necessary. Parameters: child - The child to remove. index - The index of the child into the parent's child array. logical_block_size - The size of one logical block. Returns: The number of bytes to remove for this directory record (this may be zero). ''' if child.parent is None: raise pycdlibexception.PyCdlibInternalError('Trying to remove child from non-existent parent') self._find_iso_record.cache_clear() # pylint: disable=no-member self._find_rr_record.cache_clear() # pylint: disable=no-member self._find_joliet_record.cache_clear() # pylint: disable=no-member # The remove_child() method returns True if the parent no longer needs # the extent that the directory record for this child was on. Remove # the extent as appropriate here. if child.parent.remove_child(child, index, logical_block_size): return self.pvd.logical_block_size() return 0
[ "def", "_remove_child_from_dr", "(", "self", ",", "child", ",", "index", ",", "logical_block_size", ")", ":", "# type: (dr.DirectoryRecord, int, int) -> int", "if", "child", ".", "parent", "is", "None", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Trying to remove child from non-existent parent'", ")", "self", ".", "_find_iso_record", ".", "cache_clear", "(", ")", "# pylint: disable=no-member", "self", ".", "_find_rr_record", ".", "cache_clear", "(", ")", "# pylint: disable=no-member", "self", ".", "_find_joliet_record", ".", "cache_clear", "(", ")", "# pylint: disable=no-member", "# The remove_child() method returns True if the parent no longer needs", "# the extent that the directory record for this child was on. Remove", "# the extent as appropriate here.", "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. Parameters: child - The child to remove. index - The index of the child into the parent's child array. logical_block_size - The size of one logical block. Returns: The number of bytes to remove for this directory record (this may be zero).
[ "An", "internal", "method", "to", "remove", "a", "child", "from", "a", "directory", "record", "shrinking", "the", "space", "in", "the", "Volume", "Descriptor", "if", "necessary", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L1858-L1885
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._add_to_ptr_size
def _add_to_ptr_size(self, ptr): # type: (path_table_record.PathTableRecord) -> int ''' An internal method to add a PTR to a VD, adding space to the VD if necessary. Parameters: ptr - The PTR to add to the vd. Returns: The number of additional bytes that are needed to fit the new PTR (this may be zero). ''' num_bytes_to_add = 0 for pvd in self.pvds: # The add_to_ptr_size() method returns True if the PVD needs # additional space in the PTR to store this directory. We always # add 4 additional extents for that (2 for LE, 2 for BE). 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
python
def _add_to_ptr_size(self, ptr): # type: (path_table_record.PathTableRecord) -> int ''' An internal method to add a PTR to a VD, adding space to the VD if necessary. Parameters: ptr - The PTR to add to the vd. Returns: The number of additional bytes that are needed to fit the new PTR (this may be zero). ''' num_bytes_to_add = 0 for pvd in self.pvds: # The add_to_ptr_size() method returns True if the PVD needs # additional space in the PTR to store this directory. We always # add 4 additional extents for that (2 for LE, 2 for BE). 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
[ "def", "_add_to_ptr_size", "(", "self", ",", "ptr", ")", ":", "# type: (path_table_record.PathTableRecord) -> int", "num_bytes_to_add", "=", "0", "for", "pvd", "in", "self", ".", "pvds", ":", "# The add_to_ptr_size() method returns True if the PVD needs", "# additional space in the PTR to store this directory. We always", "# add 4 additional extents for that (2 for LE, 2 for BE).", "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. Parameters: ptr - The PTR to add to the vd. Returns: The number of additional bytes that are needed to fit the new PTR (this may be zero).
[ "An", "internal", "method", "to", "add", "a", "PTR", "to", "a", "VD", "adding", "space", "to", "the", "VD", "if", "necessary", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L1887-L1907
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._remove_from_ptr_size
def _remove_from_ptr_size(self, ptr): # type: (path_table_record.PathTableRecord) -> int ''' An internal method to remove a PTR from a VD, removing space from the VD if necessary. Parameters: ptr - The PTR to remove from the VD. Returns: The number of bytes to remove from the VDs (this may be zero). ''' num_bytes_to_remove = 0 for pvd in self.pvds: # The remove_from_ptr_size() returns True if the PVD no longer # needs the extra extents in the PTR that stored this directory. # We always remove 4 additional extents for that. 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
python
def _remove_from_ptr_size(self, ptr): # type: (path_table_record.PathTableRecord) -> int ''' An internal method to remove a PTR from a VD, removing space from the VD if necessary. Parameters: ptr - The PTR to remove from the VD. Returns: The number of bytes to remove from the VDs (this may be zero). ''' num_bytes_to_remove = 0 for pvd in self.pvds: # The remove_from_ptr_size() returns True if the PVD no longer # needs the extra extents in the PTR that stored this directory. # We always remove 4 additional extents for that. 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
[ "def", "_remove_from_ptr_size", "(", "self", ",", "ptr", ")", ":", "# type: (path_table_record.PathTableRecord) -> int", "num_bytes_to_remove", "=", "0", "for", "pvd", "in", "self", ".", "pvds", ":", "# The remove_from_ptr_size() returns True if the PVD no longer", "# needs the extra extents in the PTR that stored this directory.", "# We always remove 4 additional extents for that.", "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. Parameters: ptr - The PTR to remove from the VD. Returns: The number of bytes to remove from the VDs (this may be zero).
[ "An", "internal", "method", "to", "remove", "a", "PTR", "from", "a", "VD", "removing", "space", "from", "the", "VD", "if", "necessary", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L1909-L1928
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._calculate_eltorito_boot_info_table_csum
def _calculate_eltorito_boot_info_table_csum(self, data_fp, data_len): # type: (BinaryIO, int) -> int ''' 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. Parameters: data_fp - The file object to read the input data from. data_len - The length of the input file. Returns: An integer representing the 32-bit checksum for the boot info table. ''' # Here we want to read the boot file so we can calculate the checksum # over it. 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: # The first 64 bytes are not included in the checksum, so skip # them here. 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
python
def _calculate_eltorito_boot_info_table_csum(self, data_fp, data_len): # type: (BinaryIO, int) -> int ''' 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. Parameters: data_fp - The file object to read the input data from. data_len - The length of the input file. Returns: An integer representing the 32-bit checksum for the boot info table. ''' # Here we want to read the boot file so we can calculate the checksum # over it. 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: # The first 64 bytes are not included in the checksum, so skip # them here. 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
[ "def", "_calculate_eltorito_boot_info_table_csum", "(", "self", ",", "data_fp", ",", "data_len", ")", ":", "# type: (BinaryIO, int) -> int", "# Here we want to read the boot file so we can calculate the checksum", "# over it.", "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", ":", "# The first 64 bytes are not included in the checksum, so skip", "# them here.", "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. Parameters: data_fp - The file object to read the input data from. data_len - The length of the input file. Returns: An integer representing the 32-bit checksum for the boot info table.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L1977-L2011
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._check_for_eltorito_boot_info_table
def _check_for_eltorito_boot_info_table(self, ino): # type: (inode.Inode) -> None ''' An internal method to check a boot directory record to see if it has an El Torito Boot Info Table embedded inside of it. Parameters: ino - The Inode to check for a Boot Info Table. Returns: Nothing. ''' 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) # OK, the rest of the stuff checks out; do a final # check to make sure the checksum is reasonable. 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)
python
def _check_for_eltorito_boot_info_table(self, ino): # type: (inode.Inode) -> None ''' An internal method to check a boot directory record to see if it has an El Torito Boot Info Table embedded inside of it. Parameters: ino - The Inode to check for a Boot Info Table. Returns: Nothing. ''' 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) # OK, the rest of the stuff checks out; do a final # check to make sure the checksum is reasonable. 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)
[ "def", "_check_for_eltorito_boot_info_table", "(", "self", ",", "ino", ")", ":", "# type: (inode.Inode) -> None", "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", ")", "# OK, the rest of the stuff checks out; do a final", "# check to make sure the checksum is reasonable.", "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. Parameters: ino - The Inode to check for a Boot Info Table. Returns: Nothing.
[ "An", "internal", "method", "to", "check", "a", "boot", "directory", "record", "to", "see", "if", "it", "has", "an", "El", "Torito", "Boot", "Info", "Table", "embedded", "inside", "of", "it", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L2013-L2037
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._check_rr_name
def _check_rr_name(self, rr_name): # type: (Optional[str]) -> bytes ''' An internal method to check whether this ISO requires or does not require a Rock Ridge path. Parameters: rr_name - The Rock Ridge name. Returns: The Rock Ridge name in bytes if this is a Rock Ridge ISO, None otherwise. ''' 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''
python
def _check_rr_name(self, rr_name): # type: (Optional[str]) -> bytes ''' An internal method to check whether this ISO requires or does not require a Rock Ridge path. Parameters: rr_name - The Rock Ridge name. Returns: The Rock Ridge name in bytes if this is a Rock Ridge ISO, None otherwise. ''' 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''
[ "def", "_check_rr_name", "(", "self", ",", "rr_name", ")", ":", "# type: (Optional[str]) -> bytes", "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. Parameters: rr_name - The Rock Ridge name. Returns: The Rock Ridge name in bytes if this is a Rock Ridge ISO, None otherwise.
[ "An", "internal", "method", "to", "check", "whether", "this", "ISO", "requires", "or", "does", "not", "require", "a", "Rock", "Ridge", "path", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L2039-L2062
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._normalize_joliet_path
def _normalize_joliet_path(self, joliet_path): # type: (str) -> bytes ''' 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. Parameters: joliet_path - The joliet_path to normalize (if necessary). Returns: The normalized joliet_path if this ISO has Joliet, None otherwise. ''' 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
python
def _normalize_joliet_path(self, joliet_path): # type: (str) -> bytes ''' 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. Parameters: joliet_path - The joliet_path to normalize (if necessary). Returns: The normalized joliet_path if this ISO has Joliet, None otherwise. ''' 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
[ "def", "_normalize_joliet_path", "(", "self", ",", "joliet_path", ")", ":", "# type: (str) -> bytes", "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. Parameters: joliet_path - The joliet_path to normalize (if necessary). Returns: The normalized joliet_path if this ISO has Joliet, None otherwise.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L2064-L2085
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._link_eltorito
def _link_eltorito(self, extent_to_inode): # type: (Dict[int, inode.Inode]) -> None ''' 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. Parameters: extent_to_inode - The map that maps extents to Inodes. Returns: Nothing. ''' 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)
python
def _link_eltorito(self, extent_to_inode): # type: (Dict[int, inode.Inode]) -> None ''' 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. Parameters: extent_to_inode - The map that maps extents to Inodes. Returns: Nothing. ''' 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)
[ "def", "_link_eltorito", "(", "self", ",", "extent_to_inode", ")", ":", "# type: (Dict[int, inode.Inode]) -> None", "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. Parameters: extent_to_inode - The map that maps extents to Inodes. Returns: Nothing.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L2087-L2121
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._parse_udf_vol_descs
def _parse_udf_vol_descs(self, extent, length, descs): # type: (int, int, PyCdlib._UDFDescriptors) -> None ''' An internal method to parse a set of UDF Volume Descriptors. Parameters: extent - The extent at which to start parsing. length - The number of bytes to read from the incoming ISO. descs - The _UDFDescriptors object to store parsed objects into. Returns: Nothing. ''' # Read in the Volume Descriptor Sequence self._seek_to_extent(extent) vd_data = self._cdfp.read(length) # And parse it. Since the sequence doesn't have to be in any set order, # and since some of the entries may be missing, we parse the Descriptor # Tag (the first 16 bytes) to find out what kind of descriptor it is, # then construct the correct type based on that. We keep going until we # see a Terminating Descriptor. 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
python
def _parse_udf_vol_descs(self, extent, length, descs): # type: (int, int, PyCdlib._UDFDescriptors) -> None ''' An internal method to parse a set of UDF Volume Descriptors. Parameters: extent - The extent at which to start parsing. length - The number of bytes to read from the incoming ISO. descs - The _UDFDescriptors object to store parsed objects into. Returns: Nothing. ''' # Read in the Volume Descriptor Sequence self._seek_to_extent(extent) vd_data = self._cdfp.read(length) # And parse it. Since the sequence doesn't have to be in any set order, # and since some of the entries may be missing, we parse the Descriptor # Tag (the first 16 bytes) to find out what kind of descriptor it is, # then construct the correct type based on that. We keep going until we # see a Terminating Descriptor. 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
[ "def", "_parse_udf_vol_descs", "(", "self", ",", "extent", ",", "length", ",", "descs", ")", ":", "# type: (int, int, PyCdlib._UDFDescriptors) -> None", "# Read in the Volume Descriptor Sequence", "self", ".", "_seek_to_extent", "(", "extent", ")", "vd_data", "=", "self", ".", "_cdfp", ".", "read", "(", "length", ")", "# And parse it. Since the sequence doesn't have to be in any set order,", "# and since some of the entries may be missing, we parse the Descriptor", "# Tag (the first 16 bytes) to find out what kind of descriptor it is,", "# then construct the correct type based on that. We keep going until we", "# see a Terminating Descriptor.", "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. Parameters: extent - The extent at which to start parsing. length - The number of bytes to read from the incoming ISO. descs - The _UDFDescriptors object to store parsed objects into. Returns: Nothing.
[ "An", "internal", "method", "to", "parse", "a", "set", "of", "UDF", "Volume", "Descriptors", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L2123-L2169
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._parse_udf_descriptors
def _parse_udf_descriptors(self): # type: () -> None ''' 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. Parameters: None. Returns: Nothing. ''' block_size = self.pvd.logical_block_size() # Parse the anchors 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) # Parse the Main Volume Descriptor Sequence self._parse_udf_vol_descs(self.udf_anchors[0].main_vd_extent, self.udf_anchors[0].main_vd_length, self.udf_main_descs) # Parse the Reserve Volume Descriptor Sequence self._parse_udf_vol_descs(self.udf_anchors[0].reserve_vd_extent, self.udf_anchors[0].reserve_vd_length, self.udf_reserve_descs) # Parse the Logical Volume Integrity Sequence 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) # Now look for the File Set Descriptor current_extent = self.udf_main_descs.partition.part_start_location self._seek_to_extent(current_extent) # Read the data for the File Set and File Terminator together 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)
python
def _parse_udf_descriptors(self): # type: () -> None ''' 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. Parameters: None. Returns: Nothing. ''' block_size = self.pvd.logical_block_size() # Parse the anchors 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) # Parse the Main Volume Descriptor Sequence self._parse_udf_vol_descs(self.udf_anchors[0].main_vd_extent, self.udf_anchors[0].main_vd_length, self.udf_main_descs) # Parse the Reserve Volume Descriptor Sequence self._parse_udf_vol_descs(self.udf_anchors[0].reserve_vd_extent, self.udf_anchors[0].reserve_vd_length, self.udf_reserve_descs) # Parse the Logical Volume Integrity Sequence 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) # Now look for the File Set Descriptor current_extent = self.udf_main_descs.partition.part_start_location self._seek_to_extent(current_extent) # Read the data for the File Set and File Terminator together 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)
[ "def", "_parse_udf_descriptors", "(", "self", ")", ":", "# type: () -> None", "block_size", "=", "self", ".", "pvd", ".", "logical_block_size", "(", ")", "# Parse the anchors", "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", ")", "# Parse the Main Volume Descriptor Sequence", "self", ".", "_parse_udf_vol_descs", "(", "self", ".", "udf_anchors", "[", "0", "]", ".", "main_vd_extent", ",", "self", ".", "udf_anchors", "[", "0", "]", ".", "main_vd_length", ",", "self", ".", "udf_main_descs", ")", "# Parse the Reserve Volume Descriptor Sequence", "self", ".", "_parse_udf_vol_descs", "(", "self", ".", "udf_anchors", "[", "0", "]", ".", "reserve_vd_extent", ",", "self", ".", "udf_anchors", "[", "0", "]", ".", "reserve_vd_length", ",", "self", ".", "udf_reserve_descs", ")", "# Parse the Logical Volume Integrity Sequence", "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", ")", "# Now look for the File Set Descriptor", "current_extent", "=", "self", ".", "udf_main_descs", ".", "partition", ".", "part_start_location", "self", ".", "_seek_to_extent", "(", "current_extent", ")", "# Read the data for the File Set and File Terminator together", "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. Parameters: None. Returns: Nothing.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L2171-L2248
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._parse_udf_file_entry
def _parse_udf_file_entry(self, abs_file_entry_extent, icb, parent): # type: (int, udfmod.UDFLongAD, Optional[udfmod.UDFFileEntry]) -> Optional[udfmod.UDFFileEntry] ''' An internal method to parse a single UDF File Entry and return the corresponding object. Parameters: part_start - The extent number the partition starts at. icb - The ICB object for the data. parent - The parent of the UDF File Entry. Returns: A UDF File Entry object corresponding to the on-disk File Entry. ''' self._seek_to_extent(abs_file_entry_extent) icbdata = self._cdfp.read(icb.extent_length) if all(v == 0 for v in bytearray(icbdata)): # We have seen ISOs in the wild (Windows 2008 Datacenter Enterprise # Standard SP2 x86 DVD) where the UDF File Identifier points to a # UDF File Entry of all zeros. In those cases, we just keep the # File Identifier, and keep the UDF File Entry blank. 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
python
def _parse_udf_file_entry(self, abs_file_entry_extent, icb, parent): # type: (int, udfmod.UDFLongAD, Optional[udfmod.UDFFileEntry]) -> Optional[udfmod.UDFFileEntry] ''' An internal method to parse a single UDF File Entry and return the corresponding object. Parameters: part_start - The extent number the partition starts at. icb - The ICB object for the data. parent - The parent of the UDF File Entry. Returns: A UDF File Entry object corresponding to the on-disk File Entry. ''' self._seek_to_extent(abs_file_entry_extent) icbdata = self._cdfp.read(icb.extent_length) if all(v == 0 for v in bytearray(icbdata)): # We have seen ISOs in the wild (Windows 2008 Datacenter Enterprise # Standard SP2 x86 DVD) where the UDF File Identifier points to a # UDF File Entry of all zeros. In those cases, we just keep the # File Identifier, and keep the UDF File Entry blank. 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
[ "def", "_parse_udf_file_entry", "(", "self", ",", "abs_file_entry_extent", ",", "icb", ",", "parent", ")", ":", "# type: (int, udfmod.UDFLongAD, Optional[udfmod.UDFFileEntry]) -> Optional[udfmod.UDFFileEntry]", "self", ".", "_seek_to_extent", "(", "abs_file_entry_extent", ")", "icbdata", "=", "self", ".", "_cdfp", ".", "read", "(", "icb", ".", "extent_length", ")", "if", "all", "(", "v", "==", "0", "for", "v", "in", "bytearray", "(", "icbdata", ")", ")", ":", "# We have seen ISOs in the wild (Windows 2008 Datacenter Enterprise", "# Standard SP2 x86 DVD) where the UDF File Identifier points to a", "# UDF File Entry of all zeros. In those cases, we just keep the", "# File Identifier, and keep the UDF File Entry blank.", "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. Parameters: part_start - The extent number the partition starts at. icb - The ICB object for the data. parent - The parent of the UDF File Entry. Returns: A UDF File Entry object corresponding to the on-disk File Entry.
[ "An", "internal", "method", "to", "parse", "a", "single", "UDF", "File", "Entry", "and", "return", "the", "corresponding", "object", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L2250-L2281
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._walk_udf_directories
def _walk_udf_directories(self, extent_to_inode): # type: (Dict[int, inode.Inode]) -> None ''' An internal method to walk a UDF filesystem and add all the metadata to this object. Parameters: extent_to_inode - A map from extent numbers to Inodes. Returns: Nothing. ''' 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(): # For a parent, no further work to do. 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) # For a non-parent, we delay adding this to the list of # fi_descs until after we check whether this is a valid # entry or not. 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: # If the next_entry is None, then we just skip the # rest of the code dealing with the entry and the # Inode. 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()
python
def _walk_udf_directories(self, extent_to_inode): # type: (Dict[int, inode.Inode]) -> None ''' An internal method to walk a UDF filesystem and add all the metadata to this object. Parameters: extent_to_inode - A map from extent numbers to Inodes. Returns: Nothing. ''' 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(): # For a parent, no further work to do. 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) # For a non-parent, we delay adding this to the list of # fi_descs until after we check whether this is a valid # entry or not. 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: # If the next_entry is None, then we just skip the # rest of the code dealing with the entry and the # Inode. 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()
[ "def", "_walk_udf_directories", "(", "self", ",", "extent_to_inode", ")", ":", "# type: (Dict[int, inode.Inode]) -> None", "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", "(", ")", ":", "# For a parent, no further work to do.", "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", ")", "# For a non-parent, we delay adding this to the list of", "# fi_descs until after we check whether this is a valid", "# entry or not.", "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", ":", "# If the next_entry is None, then we just skip the", "# rest of the code dealing with the entry and the", "# Inode.", "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. Parameters: extent_to_inode - A map from extent numbers to Inodes. Returns: Nothing.
[ "An", "internal", "method", "to", "walk", "a", "UDF", "filesystem", "and", "add", "all", "the", "metadata", "to", "this", "object", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L2283-L2373
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._udf_get_file_from_iso_fp
def _udf_get_file_from_iso_fp(self, outfp, blocksize, udf_path): # type: (BinaryIO, int, bytes) -> None ''' An internal method to fetch a single UDF file from the ISO and write it out to the file object. Parameters: outfp - The file object to write data to. blocksize - The number of bytes in each transfer. udf_path - The absolute UDF path to lookup on the ISO. Returns: Nothing. ''' 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)
python
def _udf_get_file_from_iso_fp(self, outfp, blocksize, udf_path): # type: (BinaryIO, int, bytes) -> None ''' An internal method to fetch a single UDF file from the ISO and write it out to the file object. Parameters: outfp - The file object to write data to. blocksize - The number of bytes in each transfer. udf_path - The absolute UDF path to lookup on the ISO. Returns: Nothing. ''' 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)
[ "def", "_udf_get_file_from_iso_fp", "(", "self", ",", "outfp", ",", "blocksize", ",", "udf_path", ")", ":", "# type: (BinaryIO, int, bytes) -> None", "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. Parameters: outfp - The file object to write data to. blocksize - The number of bytes in each transfer. udf_path - The absolute UDF path to lookup on the ISO. Returns: Nothing.
[ "An", "internal", "method", "to", "fetch", "a", "single", "UDF", "file", "from", "the", "ISO", "and", "write", "it", "out", "to", "the", "file", "object", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L2557-L2585
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._outfp_write_with_check
def _outfp_write_with_check(self, outfp, data, enable_overwrite_check=True): # type: (BinaryIO, bytes, bool) -> None ''' Internal method to write data out to the output file descriptor, ensuring that it doesn't go beyond the bounds of the ISO. Parameters: outfp - The file object to write to. data - The actual data to write. enable_overwrite_check - Whether to do overwrite checking if it is enabled. Some pieces of code explicitly want to overwrite data, so this allows them to disable the checking. Returns: Nothing. ''' start = outfp.tell() outfp.write(data) if self._track_writes: # After the write, double check that we didn't write beyond the # boundary of the PVD, and raise a PyCdlibException if we do. 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))
python
def _outfp_write_with_check(self, outfp, data, enable_overwrite_check=True): # type: (BinaryIO, bytes, bool) -> None ''' Internal method to write data out to the output file descriptor, ensuring that it doesn't go beyond the bounds of the ISO. Parameters: outfp - The file object to write to. data - The actual data to write. enable_overwrite_check - Whether to do overwrite checking if it is enabled. Some pieces of code explicitly want to overwrite data, so this allows them to disable the checking. Returns: Nothing. ''' start = outfp.tell() outfp.write(data) if self._track_writes: # After the write, double check that we didn't write beyond the # boundary of the PVD, and raise a PyCdlibException if we do. 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))
[ "def", "_outfp_write_with_check", "(", "self", ",", "outfp", ",", "data", ",", "enable_overwrite_check", "=", "True", ")", ":", "# type: (BinaryIO, bytes, bool) -> None", "start", "=", "outfp", ".", "tell", "(", ")", "outfp", ".", "write", "(", "data", ")", "if", "self", ".", "_track_writes", ":", "# After the write, double check that we didn't write beyond the", "# boundary of the PVD, and raise a PyCdlibException if we do.", "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. Parameters: outfp - The file object to write to. data - The actual data to write. enable_overwrite_check - Whether to do overwrite checking if it is enabled. Some pieces of code explicitly want to overwrite data, so this allows them to disable the checking. Returns: Nothing.
[ "Internal", "method", "to", "write", "data", "out", "to", "the", "output", "file", "descriptor", "ensuring", "that", "it", "doesn", "t", "go", "beyond", "the", "bounds", "of", "the", "ISO", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L2686-L2709
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._output_file_data
def _output_file_data(self, outfp, blocksize, ino): # type: (BinaryIO, int, inode.Inode) -> int ''' Internal method to write a directory record entry out. Parameters: outfp - The file object to write the data to. blocksize - The blocksize to use when writing the data out. ino - The Inode to write. Returns: The total number of bytes written out. ''' 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 this file is being used as a bootfile, and the user # requested that the boot info table be patched into it, # we patch the boot info table at offset 8 here. 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
python
def _output_file_data(self, outfp, blocksize, ino): # type: (BinaryIO, int, inode.Inode) -> int ''' Internal method to write a directory record entry out. Parameters: outfp - The file object to write the data to. blocksize - The blocksize to use when writing the data out. ino - The Inode to write. Returns: The total number of bytes written out. ''' 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 this file is being used as a bootfile, and the user # requested that the boot info table be patched into it, # we patch the boot info table at offset 8 here. 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
[ "def", "_output_file_data", "(", "self", ",", "outfp", ",", "blocksize", ",", "ino", ")", ":", "# type: (BinaryIO, int, inode.Inode) -> int", "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 this file is being used as a bootfile, and the user", "# requested that the boot info table be patched into it,", "# we patch the boot info table at offset 8 here.", "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. Parameters: outfp - The file object to write the data to. blocksize - The blocksize to use when writing the data out. ino - The Inode to write. Returns: The total number of bytes written out.
[ "Internal", "method", "to", "write", "a", "directory", "record", "entry", "out", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L2711-L2744
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._write_directory_records
def _write_directory_records(self, vd, outfp, progress): # type: (headervd.PrimaryOrSupplementaryVD, BinaryIO, PyCdlib._Progress) -> None ''' An internal method to write out the directory records from a particular Volume Descriptor. Parameters: vd - The Volume Descriptor to write the Directory Records from. outfp - The file object to write data to. progress - The _Progress object to use for outputting progress. Returns: Nothing. ''' 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') # Little Endian PTR 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) # Big Endian PTR 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: # No matter what type the child is, we need to first write # out the directory record entry. 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) # Now write out the child 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: # The child has a continue block, so write it out here. 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 the child is a directory, and is not dot or dotdot, # we want to descend into it to look at the children. if not child.is_dot() and not child.is_dotdot(): dirs.append(child)
python
def _write_directory_records(self, vd, outfp, progress): # type: (headervd.PrimaryOrSupplementaryVD, BinaryIO, PyCdlib._Progress) -> None ''' An internal method to write out the directory records from a particular Volume Descriptor. Parameters: vd - The Volume Descriptor to write the Directory Records from. outfp - The file object to write data to. progress - The _Progress object to use for outputting progress. Returns: Nothing. ''' 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') # Little Endian PTR 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) # Big Endian PTR 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: # No matter what type the child is, we need to first write # out the directory record entry. 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) # Now write out the child 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: # The child has a continue block, so write it out here. 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 the child is a directory, and is not dot or dotdot, # we want to descend into it to look at the children. if not child.is_dot() and not child.is_dotdot(): dirs.append(child)
[ "def", "_write_directory_records", "(", "self", ",", "vd", ",", "outfp", ",", "progress", ")", ":", "# type: (headervd.PrimaryOrSupplementaryVD, BinaryIO, PyCdlib._Progress) -> None", "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'", ")", "# Little Endian PTR", "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", ")", "# Big Endian PTR", "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", ":", "# No matter what type the child is, we need to first write", "# out the directory record entry.", "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", ")", "# Now write out the child", "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", ":", "# The child has a continue block, so write it out here.", "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 the child is a directory, and is not dot or dotdot,", "# we want to descend into it to look at the children.", "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. Parameters: vd - The Volume Descriptor to write the Directory Records from. outfp - The file object to write data to. progress - The _Progress object to use for outputting progress. Returns: Nothing.
[ "An", "internal", "method", "to", "write", "out", "the", "directory", "records", "from", "a", "particular", "Volume", "Descriptor", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L2784-L2850
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._write_udf_descs
def _write_udf_descs(self, descs, outfp, progress): # type: (PyCdlib._UDFDescriptors, BinaryIO, PyCdlib._Progress) -> None ''' An internal method to write out a UDF Descriptor sequence. Parameters: descs - The UDF Descriptors object to write out. outfp - The output file descriptor to use for writing. progress - The _Progress object to use for updating progress. Returns: Nothing. ''' 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))
python
def _write_udf_descs(self, descs, outfp, progress): # type: (PyCdlib._UDFDescriptors, BinaryIO, PyCdlib._Progress) -> None ''' An internal method to write out a UDF Descriptor sequence. Parameters: descs - The UDF Descriptors object to write out. outfp - The output file descriptor to use for writing. progress - The _Progress object to use for updating progress. Returns: Nothing. ''' 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))
[ "def", "_write_udf_descs", "(", "self", ",", "descs", ",", "outfp", ",", "progress", ")", ":", "# type: (PyCdlib._UDFDescriptors, BinaryIO, PyCdlib._Progress) -> None", "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. Parameters: descs - The UDF Descriptors object to write out. outfp - The output file descriptor to use for writing. progress - The _Progress object to use for updating progress. Returns: Nothing.
[ "An", "internal", "method", "to", "write", "out", "a", "UDF", "Descriptor", "sequence", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L2852-L2894
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._update_rr_ce_entry
def _update_rr_ce_entry(self, rec): # type: (dr.DirectoryRecord) -> int ''' An internal method to update the Rock Ridge CE entry for the given record. Parameters: rec - The record to update the Rock Ridge CE entry for (if it exists). Returns: The number of additional bytes needed for this Rock Ridge CE entry. ''' 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
python
def _update_rr_ce_entry(self, rec): # type: (dr.DirectoryRecord) -> int ''' An internal method to update the Rock Ridge CE entry for the given record. Parameters: rec - The record to update the Rock Ridge CE entry for (if it exists). Returns: The number of additional bytes needed for this Rock Ridge CE entry. ''' 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
[ "def", "_update_rr_ce_entry", "(", "self", ",", "rec", ")", ":", "# type: (dr.DirectoryRecord) -> int", "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. Parameters: rec - The record to update the Rock Ridge CE entry for (if it exists). Returns: The number of additional bytes needed for this Rock Ridge CE entry.
[ "An", "internal", "method", "to", "update", "the", "Rock", "Ridge", "CE", "entry", "for", "the", "given", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L3096-L3115
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._finish_add
def _finish_add(self, num_bytes_to_add, num_partition_bytes_to_add): # type: (int, int) -> None ''' 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. Parameters: num_bytes_to_add - The number of additional bytes to add to all descriptors. num_partition_bytes_to_add - The number of additional bytes to add to the partition if this is a UDF file. Returns: Nothing. ''' 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
python
def _finish_add(self, num_bytes_to_add, num_partition_bytes_to_add): # type: (int, int) -> None ''' 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. Parameters: num_bytes_to_add - The number of additional bytes to add to all descriptors. num_partition_bytes_to_add - The number of additional bytes to add to the partition if this is a UDF file. Returns: Nothing. ''' 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
[ "def", "_finish_add", "(", "self", ",", "num_bytes_to_add", ",", "num_partition_bytes_to_add", ")", ":", "# type: (int, int) -> None", "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. Parameters: num_bytes_to_add - The number of additional bytes to add to all descriptors. num_partition_bytes_to_add - The number of additional bytes to add to the partition if this is a UDF file. Returns: Nothing.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L3117-L3151
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._finish_remove
def _finish_remove(self, num_bytes_to_remove, is_partition): # type: (int, bool) -> None ''' 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. Parameters: num_bytes_to_remove - The number of additional bytes to remove from the descriptors. is_partition - Whether these bytes are part of a UDF partition. Returns: Nothing. ''' 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
python
def _finish_remove(self, num_bytes_to_remove, is_partition): # type: (int, bool) -> None ''' 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. Parameters: num_bytes_to_remove - The number of additional bytes to remove from the descriptors. is_partition - Whether these bytes are part of a UDF partition. Returns: Nothing. ''' 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
[ "def", "_finish_remove", "(", "self", ",", "num_bytes_to_remove", ",", "is_partition", ")", ":", "# type: (int, bool) -> None", "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. Parameters: num_bytes_to_remove - The number of additional bytes to remove from the descriptors. is_partition - Whether these bytes are part of a UDF partition. Returns: Nothing.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L3153-L3185
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._rm_dr_link
def _rm_dr_link(self, rec): # type: (dr.DirectoryRecord) -> int ''' An internal method to remove a Directory Record link given the record. Parameters: rec - The Directory Record to remove. Returns: The number of bytes to remove from the ISO. ''' 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: # This should never happen raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record') del rec.inode.linked_records[found_index] # We only remove the size of the child from the ISO if there are no # other references to this file on the ISO. 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: # This should never happen 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
python
def _rm_dr_link(self, rec): # type: (dr.DirectoryRecord) -> int ''' An internal method to remove a Directory Record link given the record. Parameters: rec - The Directory Record to remove. Returns: The number of bytes to remove from the ISO. ''' 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: # This should never happen raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record') del rec.inode.linked_records[found_index] # We only remove the size of the child from the ISO if there are no # other references to this file on the ISO. 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: # This should never happen 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
[ "def", "_rm_dr_link", "(", "self", ",", "rec", ")", ":", "# type: (dr.DirectoryRecord) -> int", "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", ":", "# This should never happen", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Could not find inode corresponding to record'", ")", "del", "rec", ".", "inode", ".", "linked_records", "[", "found_index", "]", "# We only remove the size of the child from the ISO if there are no", "# other references to this file on the ISO.", "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", ":", "# This should never happen", "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. Parameters: rec - The Directory Record to remove. Returns: The number of bytes to remove from the ISO.
[ "An", "internal", "method", "to", "remove", "a", "Directory", "Record", "link", "given", "the", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L3435-L3490
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._rm_udf_file_ident
def _rm_udf_file_ident(self, parent, fi): # type: (udfmod.UDFFileEntry, bytes) -> int ''' An internal method to remove a UDF File Identifier from the parent and remove any space from the Logical Volume as necessary. Parameters: parent - The parent entry to remove the UDF File Identifier from. fi - The file identifier to remove. Returns: The number of bytes to remove from the ISO. ''' 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() # pylint: disable=no-member return num_extents_to_remove * logical_block_size
python
def _rm_udf_file_ident(self, parent, fi): # type: (udfmod.UDFFileEntry, bytes) -> int ''' An internal method to remove a UDF File Identifier from the parent and remove any space from the Logical Volume as necessary. Parameters: parent - The parent entry to remove the UDF File Identifier from. fi - The file identifier to remove. Returns: The number of bytes to remove from the ISO. ''' 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() # pylint: disable=no-member return num_extents_to_remove * logical_block_size
[ "def", "_rm_udf_file_ident", "(", "self", ",", "parent", ",", "fi", ")", ":", "# type: (udfmod.UDFFileEntry, bytes) -> int", "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", "(", ")", "# pylint: disable=no-member", "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. Parameters: parent - The parent entry to remove the UDF File Identifier from. fi - The file identifier to remove. Returns: The number of bytes to remove from the ISO.
[ "An", "internal", "method", "to", "remove", "a", "UDF", "File", "Identifier", "from", "the", "parent", "and", "remove", "any", "space", "from", "the", "Logical", "Volume", "as", "necessary", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L3492-L3511
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._rm_udf_link
def _rm_udf_link(self, rec): # type: (udfmod.UDFFileEntry) -> int ''' An internal method to remove a UDF File Entry link. Parameters: rec - The UDF File Entry to remove. Returns: The number of bytes to remove from the ISO. ''' 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)') # To remove something from UDF, we have to: # 1. Remove it from the list of linked_records on the Inode. # 2. If the number of links to the Inode is now 0, remove the Inode. # 3. If the number of links to the UDF File Entry this uses is 0, # remove the UDF File Entry. # 4. Remove the UDF File Identifier from the parent. logical_block_size = self.pvd.logical_block_size() num_bytes_to_remove = 0 if rec.inode is not None: # Step 1. found_index = None for index, link in enumerate(rec.inode.linked_records): if id(link) == id(rec): found_index = index break else: # This should never happen raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record') del rec.inode.linked_records[found_index] rec.inode.num_udf -= 1 # Step 2. 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: # This should never happen raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record') del self.inodes[found_index] num_bytes_to_remove += rec.get_data_length() # Step 3. if rec.inode.num_udf == 0: num_bytes_to_remove += logical_block_size else: # If rec.inode is None, then we are just removing the UDF File # Entry. num_bytes_to_remove += logical_block_size # Step 4. 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)
python
def _rm_udf_link(self, rec): # type: (udfmod.UDFFileEntry) -> int ''' An internal method to remove a UDF File Entry link. Parameters: rec - The UDF File Entry to remove. Returns: The number of bytes to remove from the ISO. ''' 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)') # To remove something from UDF, we have to: # 1. Remove it from the list of linked_records on the Inode. # 2. If the number of links to the Inode is now 0, remove the Inode. # 3. If the number of links to the UDF File Entry this uses is 0, # remove the UDF File Entry. # 4. Remove the UDF File Identifier from the parent. logical_block_size = self.pvd.logical_block_size() num_bytes_to_remove = 0 if rec.inode is not None: # Step 1. found_index = None for index, link in enumerate(rec.inode.linked_records): if id(link) == id(rec): found_index = index break else: # This should never happen raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record') del rec.inode.linked_records[found_index] rec.inode.num_udf -= 1 # Step 2. 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: # This should never happen raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record') del self.inodes[found_index] num_bytes_to_remove += rec.get_data_length() # Step 3. if rec.inode.num_udf == 0: num_bytes_to_remove += logical_block_size else: # If rec.inode is None, then we are just removing the UDF File # Entry. num_bytes_to_remove += logical_block_size # Step 4. 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)
[ "def", "_rm_udf_link", "(", "self", ",", "rec", ")", ":", "# type: (udfmod.UDFFileEntry) -> int", "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)'", ")", "# To remove something from UDF, we have to:", "# 1. Remove it from the list of linked_records on the Inode.", "# 2. If the number of links to the Inode is now 0, remove the Inode.", "# 3. If the number of links to the UDF File Entry this uses is 0,", "# remove the UDF File Entry.", "# 4. Remove the UDF File Identifier from the parent.", "logical_block_size", "=", "self", ".", "pvd", ".", "logical_block_size", "(", ")", "num_bytes_to_remove", "=", "0", "if", "rec", ".", "inode", "is", "not", "None", ":", "# Step 1.", "found_index", "=", "None", "for", "index", ",", "link", "in", "enumerate", "(", "rec", ".", "inode", ".", "linked_records", ")", ":", "if", "id", "(", "link", ")", "==", "id", "(", "rec", ")", ":", "found_index", "=", "index", "break", "else", ":", "# This should never happen", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Could not find inode corresponding to record'", ")", "del", "rec", ".", "inode", ".", "linked_records", "[", "found_index", "]", "rec", ".", "inode", ".", "num_udf", "-=", "1", "# Step 2.", "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", ":", "# This should never happen", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Could not find inode corresponding to record'", ")", "del", "self", ".", "inodes", "[", "found_index", "]", "num_bytes_to_remove", "+=", "rec", ".", "get_data_length", "(", ")", "# Step 3.", "if", "rec", ".", "inode", ".", "num_udf", "==", "0", ":", "num_bytes_to_remove", "+=", "logical_block_size", "else", ":", "# If rec.inode is None, then we are just removing the UDF File", "# Entry.", "num_bytes_to_remove", "+=", "logical_block_size", "# Step 4.", "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. Parameters: rec - The UDF File Entry to remove. Returns: The number of bytes to remove from the ISO.
[ "An", "internal", "method", "to", "remove", "a", "UDF", "File", "Entry", "link", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L3513-L3578
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._add_joliet_dir
def _add_joliet_dir(self, joliet_path): # type: (bytes) -> int ''' An internal method to add a joliet directory to the ISO. Parameters: joliet_path - The path to add to the Joliet portion of the ISO. Returns: The number of additional bytes needed on the ISO to fit this directory. ''' 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 # We always need to add an entry to the path table record ptr = path_table_record.PathTableRecord() ptr.new_dir(joliet_name) rec.set_ptr(ptr) return num_bytes_to_add
python
def _add_joliet_dir(self, joliet_path): # type: (bytes) -> int ''' An internal method to add a joliet directory to the ISO. Parameters: joliet_path - The path to add to the Joliet portion of the ISO. Returns: The number of additional bytes needed on the ISO to fit this directory. ''' 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 # We always need to add an entry to the path table record ptr = path_table_record.PathTableRecord() ptr.new_dir(joliet_name) rec.set_ptr(ptr) return num_bytes_to_add
[ "def", "_add_joliet_dir", "(", "self", ",", "joliet_path", ")", ":", "# type: (bytes) -> int", "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", "# We always need to add an entry to the path table record", "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. Parameters: joliet_path - The path to add to the Joliet portion of the ISO. Returns: The number of additional bytes needed on the ISO to fit this directory.
[ "An", "internal", "method", "to", "add", "a", "joliet", "directory", "to", "the", "ISO", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L3580-L3617
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._rm_joliet_dir
def _rm_joliet_dir(self, joliet_path): # type: (bytes) -> int ''' An internal method to remove a directory from the Joliet portion of the ISO. Parameters: joliet_path - The Joliet directory to remove. Returns: The number of bytes to remove from the ISO for this Joliet directory. ''' 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
python
def _rm_joliet_dir(self, joliet_path): # type: (bytes) -> int ''' An internal method to remove a directory from the Joliet portion of the ISO. Parameters: joliet_path - The Joliet directory to remove. Returns: The number of bytes to remove from the ISO for this Joliet directory. ''' 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
[ "def", "_rm_joliet_dir", "(", "self", ",", "joliet_path", ")", ":", "# type: (bytes) -> int", "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. Parameters: joliet_path - The Joliet directory to remove. Returns: The number of bytes to remove from the ISO for this Joliet directory.
[ "An", "internal", "method", "to", "remove", "a", "directory", "from", "the", "Joliet", "portion", "of", "the", "ISO", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L3619-L3643
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._get_entry
def _get_entry(self, iso_path, rr_path, joliet_path): # type: (Optional[bytes], Optional[bytes], Optional[bytes]) -> dr.DirectoryRecord ''' Internal method to get the directory record for a particular path. Parameters: iso_path - The path on the ISO filesystem to look up the record for. rr_path - The Rock Ridge path on the ISO filesystem to look up the record for. joliet_path - The path on the Joliet filesystem to look up the record for. Returns: A dr.DirectoryRecord object representing the 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
python
def _get_entry(self, iso_path, rr_path, joliet_path): # type: (Optional[bytes], Optional[bytes], Optional[bytes]) -> dr.DirectoryRecord ''' Internal method to get the directory record for a particular path. Parameters: iso_path - The path on the ISO filesystem to look up the record for. rr_path - The Rock Ridge path on the ISO filesystem to look up the record for. joliet_path - The path on the Joliet filesystem to look up the record for. Returns: A dr.DirectoryRecord object representing the 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
[ "def", "_get_entry", "(", "self", ",", "iso_path", ",", "rr_path", ",", "joliet_path", ")", ":", "# type: (Optional[bytes], Optional[bytes], Optional[bytes]) -> dr.DirectoryRecord", "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. Parameters: iso_path - The path on the ISO filesystem to look up the record for. rr_path - The Rock Ridge path on the ISO filesystem to look up the record for. joliet_path - The path on the Joliet filesystem to look up the record for. Returns: A dr.DirectoryRecord object representing the path.
[ "Internal", "method", "to", "get", "the", "directory", "record", "for", "a", "particular", "path", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L3645-L3673
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._get_udf_entry
def _get_udf_entry(self, udf_path): # type: (str) -> udfmod.UDFFileEntry ''' Internal method to get the UDF File Entry for a particular path. Parameters: udf_path - The path on the UDF filesystem to look up the record for. Returns: A udfmod.UDFFileEntry object representing the 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
python
def _get_udf_entry(self, udf_path): # type: (str) -> udfmod.UDFFileEntry ''' Internal method to get the UDF File Entry for a particular path. Parameters: udf_path - The path on the UDF filesystem to look up the record for. Returns: A udfmod.UDFFileEntry object representing the 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
[ "def", "_get_udf_entry", "(", "self", ",", "udf_path", ")", ":", "# type: (str) -> udfmod.UDFFileEntry", "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. Parameters: udf_path - The path on the UDF filesystem to look up the record for. Returns: A udfmod.UDFFileEntry object representing the path.
[ "Internal", "method", "to", "get", "the", "UDF", "File", "Entry", "for", "a", "particular", "path", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L3675-L3692
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._create_dot
def _create_dot(self, vd, parent, rock_ridge, xa, file_mode): # type: (headervd.PrimaryOrSupplementaryVD, dr.DirectoryRecord, str, bool, int) -> None ''' An internal method to create a new 'dot' Directory Record. Parameters: vd - The volume descriptor to attach the 'dot' Directory Record to. parent - The parent Directory Record for new Directory Record. rock_ridge - The Rock Ridge version to use for this entry (if any). xa - Whether this Directory Record should have extended attributes. file_mode - The mode to assign to the dot directory (only applies to Rock Ridge). Returns: Nothing. ''' 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())
python
def _create_dot(self, vd, parent, rock_ridge, xa, file_mode): # type: (headervd.PrimaryOrSupplementaryVD, dr.DirectoryRecord, str, bool, int) -> None ''' An internal method to create a new 'dot' Directory Record. Parameters: vd - The volume descriptor to attach the 'dot' Directory Record to. parent - The parent Directory Record for new Directory Record. rock_ridge - The Rock Ridge version to use for this entry (if any). xa - Whether this Directory Record should have extended attributes. file_mode - The mode to assign to the dot directory (only applies to Rock Ridge). Returns: Nothing. ''' 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())
[ "def", "_create_dot", "(", "self", ",", "vd", ",", "parent", ",", "rock_ridge", ",", "xa", ",", "file_mode", ")", ":", "# type: (headervd.PrimaryOrSupplementaryVD, dr.DirectoryRecord, str, bool, int) -> None", "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. Parameters: vd - The volume descriptor to attach the 'dot' Directory Record to. parent - The parent Directory Record for new Directory Record. rock_ridge - The Rock Ridge version to use for this entry (if any). xa - Whether this Directory Record should have extended attributes. file_mode - The mode to assign to the dot directory (only applies to Rock Ridge). Returns: Nothing.
[ "An", "internal", "method", "to", "create", "a", "new", "dot", "Directory", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L3694-L3711
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib._create_dotdot
def _create_dotdot(self, vd, parent, rock_ridge, relocated, xa, file_mode): # type: (headervd.PrimaryOrSupplementaryVD, dr.DirectoryRecord, str, bool, bool, int) -> dr.DirectoryRecord ''' An internal method to create a new 'dotdot' Directory Record. Parameters: vd - The volume descriptor to attach the 'dotdot' Directory Record to. parent - The parent Directory Record for new Directory Record. rock_ridge - The Rock Ridge version to use for this entry (if any). relocated - Whether this Directory Record is a Rock Ridge relocated entry. xa - Whether this Directory Record should have extended attributes. file_mode - The mode to assign to the dot directory (only applies to Rock Ridge). Returns: Nothing. ''' 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
python
def _create_dotdot(self, vd, parent, rock_ridge, relocated, xa, file_mode): # type: (headervd.PrimaryOrSupplementaryVD, dr.DirectoryRecord, str, bool, bool, int) -> dr.DirectoryRecord ''' An internal method to create a new 'dotdot' Directory Record. Parameters: vd - The volume descriptor to attach the 'dotdot' Directory Record to. parent - The parent Directory Record for new Directory Record. rock_ridge - The Rock Ridge version to use for this entry (if any). relocated - Whether this Directory Record is a Rock Ridge relocated entry. xa - Whether this Directory Record should have extended attributes. file_mode - The mode to assign to the dot directory (only applies to Rock Ridge). Returns: Nothing. ''' 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
[ "def", "_create_dotdot", "(", "self", ",", "vd", ",", "parent", ",", "rock_ridge", ",", "relocated", ",", "xa", ",", "file_mode", ")", ":", "# type: (headervd.PrimaryOrSupplementaryVD, dr.DirectoryRecord, str, bool, bool, int) -> dr.DirectoryRecord", "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. Parameters: vd - The volume descriptor to attach the 'dotdot' Directory Record to. parent - The parent Directory Record for new Directory Record. rock_ridge - The Rock Ridge version to use for this entry (if any). relocated - Whether this Directory Record is a Rock Ridge relocated entry. xa - Whether this Directory Record should have extended attributes. file_mode - The mode to assign to the dot directory (only applies to Rock Ridge). Returns: Nothing.
[ "An", "internal", "method", "to", "create", "a", "new", "dotdot", "Directory", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L3713-L3732
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib.open
def open(self, filename): # type: (str) -> None ''' Open up an existing ISO for inspection and modification. Parameters: filename - The filename containing the ISO to open up. Returns: Nothing. ''' 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
python
def open(self, filename): # type: (str) -> None ''' Open up an existing ISO for inspection and modification. Parameters: filename - The filename containing the ISO to open up. Returns: Nothing. ''' 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
[ "def", "open", "(", "self", ",", "filename", ")", ":", "# type: (str) -> None", "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. Parameters: filename - The filename containing the ISO to open up. Returns: Nothing.
[ "Open", "up", "an", "existing", "ISO", "for", "inspection", "and", "modification", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L4025-L4044
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib.open_fp
def open_fp(self, fp): # type: (BinaryIO) -> None ''' 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. Parameters: fp - The file object containing the ISO to open up. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInvalidInput('This object already has an ISO; either close it or create a new object') self._open_fp(fp)
python
def open_fp(self, fp): # type: (BinaryIO) -> None ''' 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. Parameters: fp - The file object containing the ISO to open up. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInvalidInput('This object already has an ISO; either close it or create a new object') self._open_fp(fp)
[ "def", "open_fp", "(", "self", ",", "fp", ")", ":", "# type: (BinaryIO) -> None", "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. Parameters: fp - The file object containing the ISO to open up. Returns: Nothing.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L4046-L4063
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib.get_file_from_iso
def get_file_from_iso(self, local_path, **kwargs): # type: (str, Any) -> None ''' A method to fetch a single file from the ISO and write it out to a local file. Parameters: local_path - The local file to write to. blocksize - The number of bytes in each transfer. iso_path - The absolute ISO9660 path to lookup on the ISO (exclusive with rr_path, joliet_path, and udf_path). rr_path - The absolute Rock Ridge path to lookup on the ISO (exclusive with iso_path, joliet_path, and udf_path). joliet_path - The absolute Joliet path to lookup on the ISO (exclusive with iso_path, rr_path, and udf_path). udf_path - The absolute UDF path to lookup on the ISO (exclusive with iso_path, rr_path, and joliet_path). Returns: Nothing. ''' 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)
python
def get_file_from_iso(self, local_path, **kwargs): # type: (str, Any) -> None ''' A method to fetch a single file from the ISO and write it out to a local file. Parameters: local_path - The local file to write to. blocksize - The number of bytes in each transfer. iso_path - The absolute ISO9660 path to lookup on the ISO (exclusive with rr_path, joliet_path, and udf_path). rr_path - The absolute Rock Ridge path to lookup on the ISO (exclusive with iso_path, joliet_path, and udf_path). joliet_path - The absolute Joliet path to lookup on the ISO (exclusive with iso_path, rr_path, and udf_path). udf_path - The absolute UDF path to lookup on the ISO (exclusive with iso_path, rr_path, and joliet_path). Returns: Nothing. ''' 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)
[ "def", "get_file_from_iso", "(", "self", ",", "local_path", ",", "*", "*", "kwargs", ")", ":", "# type: (str, Any) -> None", "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. Parameters: local_path - The local file to write to. blocksize - The number of bytes in each transfer. iso_path - The absolute ISO9660 path to lookup on the ISO (exclusive with rr_path, joliet_path, and udf_path). rr_path - The absolute Rock Ridge path to lookup on the ISO (exclusive with iso_path, joliet_path, and udf_path). joliet_path - The absolute Joliet path to lookup on the ISO (exclusive with iso_path, rr_path, and udf_path). udf_path - The absolute UDF path to lookup on the ISO (exclusive with iso_path, rr_path, and joliet_path). Returns: Nothing.
[ "A", "method", "to", "fetch", "a", "single", "file", "from", "the", "ISO", "and", "write", "it", "out", "to", "a", "local", "file", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L4065-L4119
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib.get_file_from_iso_fp
def get_file_from_iso_fp(self, outfp, **kwargs): # type: (BinaryIO, Any) -> None ''' A method to fetch a single file from the ISO and write it out to the file object. Parameters: outfp - The file object to write data to. blocksize - The number of bytes in each transfer. iso_path - The absolute ISO9660 path to lookup on the ISO (exclusive with rr_path, joliet_path, and udf_path). rr_path - The absolute Rock Ridge path to lookup on the ISO (exclusive with iso_path, joliet_path, and udf_path). joliet_path - The absolute Joliet path to lookup on the ISO (exclusive with iso_path, rr_path, and udf_path). udf_path - The absolute UDF path to lookup on the ISO (exclusive with iso_path, rr_path, and joliet_path). Returns: Nothing. ''' 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)
python
def get_file_from_iso_fp(self, outfp, **kwargs): # type: (BinaryIO, Any) -> None ''' A method to fetch a single file from the ISO and write it out to the file object. Parameters: outfp - The file object to write data to. blocksize - The number of bytes in each transfer. iso_path - The absolute ISO9660 path to lookup on the ISO (exclusive with rr_path, joliet_path, and udf_path). rr_path - The absolute Rock Ridge path to lookup on the ISO (exclusive with iso_path, joliet_path, and udf_path). joliet_path - The absolute Joliet path to lookup on the ISO (exclusive with iso_path, rr_path, and udf_path). udf_path - The absolute UDF path to lookup on the ISO (exclusive with iso_path, rr_path, and joliet_path). Returns: Nothing. ''' 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)
[ "def", "get_file_from_iso_fp", "(", "self", ",", "outfp", ",", "*", "*", "kwargs", ")", ":", "# type: (BinaryIO, Any) -> None", "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. Parameters: outfp - The file object to write data to. blocksize - The number of bytes in each transfer. iso_path - The absolute ISO9660 path to lookup on the ISO (exclusive with rr_path, joliet_path, and udf_path). rr_path - The absolute Rock Ridge path to lookup on the ISO (exclusive with iso_path, joliet_path, and udf_path). joliet_path - The absolute Joliet path to lookup on the ISO (exclusive with iso_path, rr_path, and udf_path). udf_path - The absolute UDF path to lookup on the ISO (exclusive with iso_path, rr_path, and joliet_path). Returns: Nothing.
[ "A", "method", "to", "fetch", "a", "single", "file", "from", "the", "ISO", "and", "write", "it", "out", "to", "the", "file", "object", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L4121-L4174
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib.write
def write(self, filename, blocksize=32768, progress_cb=None, progress_opaque=None): # type: (str, int, Optional[Callable[[int, int, Any], None]], Optional[Any]) -> None ''' Write a properly formatted ISO out to the filename passed in. This also goes by the name of 'mastering'. Parameters: filename - The filename to write the data to. blocksize - The blocksize to use when copying data; set to 32768 by default. progress_cb - If not None, a function to call as the write call does its work. The callback function must have a signature of: def func(done, total, opaque). progress_opaque - User data to be passed to the progress callback. Returns: Nothing. ''' 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)
python
def write(self, filename, blocksize=32768, progress_cb=None, progress_opaque=None): # type: (str, int, Optional[Callable[[int, int, Any], None]], Optional[Any]) -> None ''' Write a properly formatted ISO out to the filename passed in. This also goes by the name of 'mastering'. Parameters: filename - The filename to write the data to. blocksize - The blocksize to use when copying data; set to 32768 by default. progress_cb - If not None, a function to call as the write call does its work. The callback function must have a signature of: def func(done, total, opaque). progress_opaque - User data to be passed to the progress callback. Returns: Nothing. ''' 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)
[ "def", "write", "(", "self", ",", "filename", ",", "blocksize", "=", "32768", ",", "progress_cb", "=", "None", ",", "progress_opaque", "=", "None", ")", ":", "# type: (str, int, Optional[Callable[[int, int, Any], None]], Optional[Any]) -> 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'. Parameters: filename - The filename to write the data to. blocksize - The blocksize to use when copying data; set to 32768 by default. progress_cb - If not None, a function to call as the write call does its work. The callback function must have a signature of: def func(done, total, opaque). progress_opaque - User data to be passed to the progress callback. Returns: Nothing.
[ "Write", "a", "properly", "formatted", "ISO", "out", "to", "the", "filename", "passed", "in", ".", "This", "also", "goes", "by", "the", "name", "of", "mastering", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L4224-L4244
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib.add_file
def add_file(self, filename, iso_path, rr_name=None, joliet_path=None, file_mode=None, udf_path=None): # type: (Any, str, Optional[str], str, Optional[int], Optional[str]) -> None ''' 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. Parameters: filename - The filename to use for the data contents for the new file. iso_path - The ISO9660 absolute path to the file destination on the ISO. rr_name - The Rock Ridge name of the file destination on the ISO. joliet_path - The Joliet absolute path to the file destination on the ISO. file_mode - The POSIX file_mode to apply to this file. This only applies if this is a Rock Ridge ISO. If this is None (the default), the permissions from the original file are used. udf_path - The UDF name of the file destination on the ISO. Returns: Nothing. ''' 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)
python
def add_file(self, filename, iso_path, rr_name=None, joliet_path=None, file_mode=None, udf_path=None): # type: (Any, str, Optional[str], str, Optional[int], Optional[str]) -> None ''' 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. Parameters: filename - The filename to use for the data contents for the new file. iso_path - The ISO9660 absolute path to the file destination on the ISO. rr_name - The Rock Ridge name of the file destination on the ISO. joliet_path - The Joliet absolute path to the file destination on the ISO. file_mode - The POSIX file_mode to apply to this file. This only applies if this is a Rock Ridge ISO. If this is None (the default), the permissions from the original file are used. udf_path - The UDF name of the file destination on the ISO. Returns: Nothing. ''' 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)
[ "def", "add_file", "(", "self", ",", "filename", ",", "iso_path", ",", "rr_name", "=", "None", ",", "joliet_path", "=", "None", ",", "file_mode", "=", "None", ",", "udf_path", "=", "None", ")", ":", "# type: (Any, str, Optional[str], str, Optional[int], Optional[str]) -> 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. Parameters: filename - The filename to use for the data contents for the new file. iso_path - The ISO9660 absolute path to the file destination on the ISO. rr_name - The Rock Ridge name of the file destination on the ISO. joliet_path - The Joliet absolute path to the file destination on the ISO. file_mode - The POSIX file_mode to apply to this file. This only applies if this is a Rock Ridge ISO. If this is None (the default), the permissions from the original file are used. udf_path - The UDF name of the file destination on the ISO. Returns: Nothing.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L4303-L4331
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib.rm_file
def rm_file(self, iso_path, rr_name=None, joliet_path=None, udf_path=None): # pylint: disable=unused-argument # type: (str, Optional[str], Optional[str], Optional[str]) -> None ''' Remove a file from the ISO. Parameters: iso_path - The path to the file to remove. rr_name - The Rock Ridge name of the file to remove. joliet_path - The Joliet path to the file to remove. udf_path - The UDF path to the file to remove. Returns: Nothing. ''' 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)') # We also want to check to see if this Directory Record is currently # being used as an El Torito Boot Catalog, Initial Entry, or Section # Entry. If it is, we throw an exception; we don't know if the user # meant to remove El Torito from this ISO, or if they meant to 'hide' # the entry, but we need them to call the correct API to let us know. 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: # Find the UDF record if the udf_path was specified; this may be # used later on. 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 the child is a Rock Ridge symlink, then it has no inode since # there is no data attached to it. 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: # This should never happen 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: # If the udf_path was specified, go looking for the UDF File Ident # that corresponds to this record. If the UDF File Ident exists, # and the File Entry is None, this means that it is an "zeroed" # UDF File Entry and we have to remove it by hand. self._rm_udf_file_ident(udf_file_ident.parent, udf_file_ident.fi) # We also have to remove the "zero" UDF File Entry, since nothing # else will. num_bytes_to_remove += self.pvd.logical_block_size() self._finish_remove(num_bytes_to_remove, True)
python
def rm_file(self, iso_path, rr_name=None, joliet_path=None, udf_path=None): # pylint: disable=unused-argument # type: (str, Optional[str], Optional[str], Optional[str]) -> None ''' Remove a file from the ISO. Parameters: iso_path - The path to the file to remove. rr_name - The Rock Ridge name of the file to remove. joliet_path - The Joliet path to the file to remove. udf_path - The UDF path to the file to remove. Returns: Nothing. ''' 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)') # We also want to check to see if this Directory Record is currently # being used as an El Torito Boot Catalog, Initial Entry, or Section # Entry. If it is, we throw an exception; we don't know if the user # meant to remove El Torito from this ISO, or if they meant to 'hide' # the entry, but we need them to call the correct API to let us know. 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: # Find the UDF record if the udf_path was specified; this may be # used later on. 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 the child is a Rock Ridge symlink, then it has no inode since # there is no data attached to it. 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: # This should never happen 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: # If the udf_path was specified, go looking for the UDF File Ident # that corresponds to this record. If the UDF File Ident exists, # and the File Entry is None, this means that it is an "zeroed" # UDF File Entry and we have to remove it by hand. self._rm_udf_file_ident(udf_file_ident.parent, udf_file_ident.fi) # We also have to remove the "zero" UDF File Entry, since nothing # else will. num_bytes_to_remove += self.pvd.logical_block_size() self._finish_remove(num_bytes_to_remove, True)
[ "def", "rm_file", "(", "self", ",", "iso_path", ",", "rr_name", "=", "None", ",", "joliet_path", "=", "None", ",", "udf_path", "=", "None", ")", ":", "# pylint: disable=unused-argument", "# type: (str, Optional[str], Optional[str], Optional[str]) -> 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)'", ")", "# We also want to check to see if this Directory Record is currently", "# being used as an El Torito Boot Catalog, Initial Entry, or Section", "# Entry. If it is, we throw an exception; we don't know if the user", "# meant to remove El Torito from this ISO, or if they meant to 'hide'", "# the entry, but we need them to call the correct API to let us know.", "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", ":", "# Find the UDF record if the udf_path was specified; this may be", "# used later on.", "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 the child is a Rock Ridge symlink, then it has no inode since", "# there is no data attached to it.", "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", ":", "# This should never happen", "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", ":", "# If the udf_path was specified, go looking for the UDF File Ident", "# that corresponds to this record. If the UDF File Ident exists,", "# and the File Entry is None, this means that it is an \"zeroed\"", "# UDF File Entry and we have to remove it by hand.", "self", ".", "_rm_udf_file_ident", "(", "udf_file_ident", ".", "parent", ",", "udf_file_ident", ".", "fi", ")", "# We also have to remove the \"zero\" UDF File Entry, since nothing", "# else will.", "num_bytes_to_remove", "+=", "self", ".", "pvd", ".", "logical_block_size", "(", ")", "self", ".", "_finish_remove", "(", "num_bytes_to_remove", ",", "True", ")" ]
Remove a file from the ISO. Parameters: iso_path - The path to the file to remove. rr_name - The Rock Ridge name of the file to remove. joliet_path - The Joliet path to the file to remove. udf_path - The UDF path to the file to remove. Returns: Nothing.
[ "Remove", "a", "file", "from", "the", "ISO", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L4797-L4883
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib.get_record
def get_record(self, **kwargs): # type: (str) -> Union[dr.DirectoryRecord, udfmod.UDFFileEntry] ''' Get the directory record for a particular path. Parameters: iso_path - The absolute path on the ISO9660 filesystem to get the record for. rr_path - The absolute path on the Rock Ridge filesystem to get the record for. joliet_path - The absolute path on the Joliet filesystem to get the record for. udf_path - The absolute path on the UDF filesystem to get the record for. Returns: An object that represents the path. This may be a dr.DirectoryRecord object (in the cases of iso_path, rr_path, or joliet_path), or a udf.UDFFileEntry object (in the case of udf_path). ''' 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)
python
def get_record(self, **kwargs): # type: (str) -> Union[dr.DirectoryRecord, udfmod.UDFFileEntry] ''' Get the directory record for a particular path. Parameters: iso_path - The absolute path on the ISO9660 filesystem to get the record for. rr_path - The absolute path on the Rock Ridge filesystem to get the record for. joliet_path - The absolute path on the Joliet filesystem to get the record for. udf_path - The absolute path on the UDF filesystem to get the record for. Returns: An object that represents the path. This may be a dr.DirectoryRecord object (in the cases of iso_path, rr_path, or joliet_path), or a udf.UDFFileEntry object (in the case of udf_path). ''' 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)
[ "def", "get_record", "(", "self", ",", "*", "*", "kwargs", ")", ":", "# type: (str) -> Union[dr.DirectoryRecord, udfmod.UDFFileEntry]", "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. Parameters: iso_path - The absolute path on the ISO9660 filesystem to get the record for. rr_path - The absolute path on the Rock Ridge filesystem to get the record for. joliet_path - The absolute path on the Joliet filesystem to get the record for. udf_path - The absolute path on the UDF filesystem to get the record for. Returns: An object that represents the path. This may be a dr.DirectoryRecord object (in the cases of iso_path, rr_path, or joliet_path), or a udf.UDFFileEntry object (in the case of udf_path).
[ "Get", "the", "directory", "record", "for", "a", "particular", "path", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L5489-L5528
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib.full_path_from_dirrecord
def full_path_from_dirrecord(self, rec, rockridge=False): # type: (Union[dr.DirectoryRecord, udfmod.UDFFileEntry], bool) -> str ''' A method to get the absolute path of a directory record. Parameters: rec - The directory record to get the full path for. rockridge - Whether to get the rock ridge full path. Returns: A string representing the absolute path to the file on the ISO. ''' 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) # A root entry has no Rock Ridge entry, even on a Rock Ridge ISO. Just # always return / here. 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 # type: Optional[dr.DirectoryRecord] 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 # type: Optional[udfmod.UDFFileEntry] 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): # Python 3, just return the encoded version return ret.decode(encoding) # Python 2. return ret.decode(encoding).encode('utf-8')
python
def full_path_from_dirrecord(self, rec, rockridge=False): # type: (Union[dr.DirectoryRecord, udfmod.UDFFileEntry], bool) -> str ''' A method to get the absolute path of a directory record. Parameters: rec - The directory record to get the full path for. rockridge - Whether to get the rock ridge full path. Returns: A string representing the absolute path to the file on the ISO. ''' 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) # A root entry has no Rock Ridge entry, even on a Rock Ridge ISO. Just # always return / here. 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 # type: Optional[dr.DirectoryRecord] 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 # type: Optional[udfmod.UDFFileEntry] 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): # Python 3, just return the encoded version return ret.decode(encoding) # Python 2. return ret.decode(encoding).encode('utf-8')
[ "def", "full_path_from_dirrecord", "(", "self", ",", "rec", ",", "rockridge", "=", "False", ")", ":", "# type: (Union[dr.DirectoryRecord, udfmod.UDFFileEntry], bool) -> str", "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", ")", "# A root entry has no Rock Ridge entry, even on a Rock Ridge ISO. Just", "# always return / here.", "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", "# type: Optional[dr.DirectoryRecord]", "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", "# type: Optional[udfmod.UDFFileEntry]", "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", ")", ":", "# Python 3, just return the encoded version", "return", "ret", ".", "decode", "(", "encoding", ")", "# Python 2.", "return", "ret", ".", "decode", "(", "encoding", ")", ".", "encode", "(", "'utf-8'", ")" ]
A method to get the absolute path of a directory record. Parameters: rec - The directory record to get the full path for. rockridge - Whether to get the rock ridge full path. Returns: A string representing the absolute path to the file on the ISO.
[ "A", "method", "to", "get", "the", "absolute", "path", "of", "a", "directory", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L5593-L5650
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib.duplicate_pvd
def duplicate_pvd(self): # type: () -> None ''' 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. Parameters: None. Returns: Nothing. ''' 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)
python
def duplicate_pvd(self): # type: () -> None ''' 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. Parameters: None. Returns: Nothing. ''' 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)
[ "def", "duplicate_pvd", "(", "self", ")", ":", "# type: () -> None", "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. Parameters: None. Returns: Nothing.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L5652-L5671
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib.clear_hidden
def clear_hidden(self, iso_path=None, rr_path=None, joliet_path=None): # type: (Optional[str], Optional[str], Optional[str]) -> None ''' 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. Parameters: iso_path - The path on the ISO to clear the hidden bit from. rr_path - The Rock Ridge path on the ISO to clear the hidden bit from. joliet_path - The Joliet path on the ISO to clear the hidden bit from. Returns: Nothing. ''' 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)
python
def clear_hidden(self, iso_path=None, rr_path=None, joliet_path=None): # type: (Optional[str], Optional[str], Optional[str]) -> None ''' 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. Parameters: iso_path - The path on the ISO to clear the hidden bit from. rr_path - The Rock Ridge path on the ISO to clear the hidden bit from. joliet_path - The Joliet path on the ISO to clear the hidden bit from. Returns: Nothing. ''' 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)
[ "def", "clear_hidden", "(", "self", ",", "iso_path", "=", "None", ",", "rr_path", "=", "None", ",", "joliet_path", "=", "None", ")", ":", "# type: (Optional[str], Optional[str], Optional[str]) -> 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. Parameters: iso_path - The path on the ISO to clear the hidden bit from. rr_path - The Rock Ridge path on the ISO to clear the hidden bit from. joliet_path - The Joliet path on the ISO to clear the hidden bit from. Returns: Nothing.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L5703-L5731
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib.set_relocated_name
def set_relocated_name(self, name, rr_name): # type: (str, str) -> None ''' 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. Parameters: name - The name for a relocated directory. rr_name - The Rock Ridge name for a relocated directory. Returns: Nothing. ''' 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
python
def set_relocated_name(self, name, rr_name): # type: (str, str) -> None ''' 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. Parameters: name - The name for a relocated directory. rr_name - The Rock Ridge name for a relocated directory. Returns: Nothing. ''' 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
[ "def", "set_relocated_name", "(", "self", ",", "name", ",", "rr_name", ")", ":", "# type: (str, str) -> None", "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. Parameters: name - The name for a relocated directory. rr_name - The Rock Ridge name for a relocated directory. Returns: Nothing.
[ "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", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L5753-L5781
train
clalancette/pycdlib
pycdlib/pycdlib.py
PyCdlib.close
def close(self): # type: () -> None ''' Close the PyCdlib object, and re-initialize the object to the defaults. The object can then be re-used for manipulation of another ISO. Parameters: None. Returns: Nothing. ''' 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: # In this case, we are managing self._cdfp, so we need to close it self._cdfp.close() self._initialize()
python
def close(self): # type: () -> None ''' Close the PyCdlib object, and re-initialize the object to the defaults. The object can then be re-used for manipulation of another ISO. Parameters: None. Returns: Nothing. ''' 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: # In this case, we are managing self._cdfp, so we need to close it self._cdfp.close() self._initialize()
[ "def", "close", "(", "self", ")", ":", "# type: () -> None", "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", ":", "# In this case, we are managing self._cdfp, so we need to close it", "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. Parameters: None. Returns: Nothing.
[ "Close", "the", "PyCdlib", "object", "and", "re", "-", "initialize", "the", "object", "to", "the", "defaults", ".", "The", "object", "can", "then", "be", "re", "-", "used", "for", "manipulation", "of", "another", "ISO", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/pycdlib.py#L5936-L5954
train
sashahart/vex
vex/options.py
make_arg_parser
def make_arg_parser(): """Return a standard ArgumentParser object. """ 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
python
def make_arg_parser(): """Return a standard ArgumentParser object. """ 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
[ "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.
[ "Return", "a", "standard", "ArgumentParser", "object", "." ]
b7680c40897b8cbe6aae55ec9812b4fb11738192
https://github.com/sashahart/vex/blob/b7680c40897b8cbe6aae55ec9812b4fb11738192/vex/options.py#L5-L90
train
sashahart/vex
vex/options.py
get_options
def get_options(argv): """Called to parse the given list as command-line arguments. :returns: an options object as returned by argparse. """ 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
python
def get_options(argv): """Called to parse the given list as command-line arguments. :returns: an options object as returned by argparse. """ 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
[ "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. :returns: an options object as returned by argparse.
[ "Called", "to", "parse", "the", "given", "list", "as", "command", "-", "line", "arguments", "." ]
b7680c40897b8cbe6aae55ec9812b4fb11738192
https://github.com/sashahart/vex/blob/b7680c40897b8cbe6aae55ec9812b4fb11738192/vex/options.py#L94-L107
train
unixsurfer/anycast_healthchecker
anycast_healthchecker/healthchecker.py
HealthChecker._update_bird_conf_file
def _update_bird_conf_file(self, operation): """Update BIRD configuration. It adds to or removes IP prefix from BIRD configuration. It also updates generation time stamp in the configuration file. Main program will exit if configuration file cant be read/written. Arguments: operation (obj): Either an AddOperation or DeleteOperation object Returns: True if BIRD configuration was updated otherwise False. """ 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)) # This is faster than using lambda and filter. # NOTE: We don't use remove method as we want to remove more than # occurrences of the IP prefixes without check. prefixes[:] = (ip for ip in prefixes if ip not in ip_prefixes_without_check) conf_updated = True # Update the list of IP prefixes based on the status of health check. 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) # some IP prefixes are either removed or added, create # configuration with new data. 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) # dummy_ip_prefix is always there 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
python
def _update_bird_conf_file(self, operation): """Update BIRD configuration. It adds to or removes IP prefix from BIRD configuration. It also updates generation time stamp in the configuration file. Main program will exit if configuration file cant be read/written. Arguments: operation (obj): Either an AddOperation or DeleteOperation object Returns: True if BIRD configuration was updated otherwise False. """ 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)) # This is faster than using lambda and filter. # NOTE: We don't use remove method as we want to remove more than # occurrences of the IP prefixes without check. prefixes[:] = (ip for ip in prefixes if ip not in ip_prefixes_without_check) conf_updated = True # Update the list of IP prefixes based on the status of health check. 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) # some IP prefixes are either removed or added, create # configuration with new data. 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) # dummy_ip_prefix is always there 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
[ "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", ")", ")", "# This is faster than using lambda and filter.", "# NOTE: We don't use remove method as we want to remove more than", "# occurrences of the IP prefixes without check.", "prefixes", "[", ":", "]", "=", "(", "ip", "for", "ip", "in", "prefixes", "if", "ip", "not", "in", "ip_prefixes_without_check", ")", "conf_updated", "=", "True", "# Update the list of IP prefixes based on the status of health check.", "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", ")", "# some IP prefixes are either removed or added, create", "# configuration with new data.", "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", ")", "# dummy_ip_prefix is always there", "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. It adds to or removes IP prefix from BIRD configuration. It also updates generation time stamp in the configuration file. Main program will exit if configuration file cant be read/written. Arguments: operation (obj): Either an AddOperation or DeleteOperation object Returns: True if BIRD configuration was updated otherwise False.
[ "Update", "BIRD", "configuration", "." ]
3ab9c1d65d550eb30621ced2434252f61d1fdd33
https://github.com/unixsurfer/anycast_healthchecker/blob/3ab9c1d65d550eb30621ced2434252f61d1fdd33/anycast_healthchecker/healthchecker.py#L78-L174
train
unixsurfer/anycast_healthchecker
anycast_healthchecker/healthchecker.py
HealthChecker.run
def run(self): """Lunch checks and triggers updates on BIRD configuration.""" # Lunch a thread for each configuration 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 # for optional settings _thread = ServiceCheck(service, _config, self.action, splay_startup) _thread.start() # Stay running until we are stopped while True: # Fetch items from action queue 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)
python
def run(self): """Lunch checks and triggers updates on BIRD configuration.""" # Lunch a thread for each configuration 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 # for optional settings _thread = ServiceCheck(service, _config, self.action, splay_startup) _thread.start() # Stay running until we are stopped while True: # Fetch items from action queue 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)
[ "def", "run", "(", "self", ")", ":", "# Lunch a thread for each configuration", "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", "# for optional settings", "_thread", "=", "ServiceCheck", "(", "service", ",", "_config", ",", "self", ".", "action", ",", "splay_startup", ")", "_thread", ".", "start", "(", ")", "# Stay running until we are stopped", "while", "True", ":", "# Fetch items from action queue", "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.
[ "Lunch", "checks", "and", "triggers", "updates", "on", "BIRD", "configuration", "." ]
3ab9c1d65d550eb30621ced2434252f61d1fdd33
https://github.com/unixsurfer/anycast_healthchecker/blob/3ab9c1d65d550eb30621ced2434252f61d1fdd33/anycast_healthchecker/healthchecker.py#L176-L228
train