_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q236900
_find_dr_record_by_name
train
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 ...
python
{ "resource": "" }
q236901
PyCdlibIO.read
train
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: ...
python
{ "resource": "" }
q236902
PyCdlibIO.readall
train
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. ''' i...
python
{ "resource": "" }
q236903
PyCdlib._parse_volume_descriptors
train
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 # de...
python
{ "resource": "" }
q236904
PyCdlib._seek_to_extent
train
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_si...
python
{ "resource": "" }
q236905
PyCdlib._find_rr_record
train
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 ...
python
{ "resource": "" }
q236906
PyCdlib._find_joliet_record
train
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...
python
{ "resource": "" }
q236907
PyCdlib._find_udf_record
train
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 corresp...
python
{ "resource": "" }
q236908
PyCdlib._iso_name_and_parent_from_path
train
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 paren...
python
{ "resource": "" }
q236909
PyCdlib._joliet_name_and_parent_from_path
train
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 t...
python
{ "resource": "" }
q236910
PyCdlib._udf_name_and_parent_from_path
train
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 paren...
python
{ "resource": "" }
q236911
PyCdlib._set_rock_ridge
train
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....
python
{ "resource": "" }
q236912
PyCdlib._parse_path_table
train
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 create...
python
{ "resource": "" }
q236913
PyCdlib._check_and_parse_eltorito
train
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 ent...
python
{ "resource": "" }
q236914
PyCdlib._remove_child_from_dr
train
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...
python
{ "resource": "" }
q236915
PyCdlib._add_to_ptr_size
train
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 tha...
python
{ "resource": "" }
q236916
PyCdlib._remove_from_ptr_size
train
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 b...
python
{ "resource": "" }
q236917
PyCdlib._calculate_eltorito_boot_info_table_csum
train
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 righ...
python
{ "resource": "" }
q236918
PyCdlib._check_for_eltorito_boot_info_table
train
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. ...
python
{ "resource": "" }
q236919
PyCdlib._check_rr_name
train
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...
python
{ "resource": "" }
q236920
PyCdlib._normalize_joliet_path
train
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 jolie...
python
{ "resource": "" }
q236921
PyCdlib._link_eltorito
train
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. Parame...
python
{ "resource": "" }
q236922
PyCdlib._parse_udf_vol_descs
train
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 f...
python
{ "resource": "" }
q236923
PyCdlib._parse_udf_descriptors
train
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. Retu...
python
{ "resource": "" }
q236924
PyCdlib._parse_udf_file_entry
train
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: ...
python
{ "resource": "" }
q236925
PyCdlib._walk_udf_directories
train
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: ...
python
{ "resource": "" }
q236926
PyCdlib._udf_get_file_from_iso_fp
train
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. blo...
python
{ "resource": "" }
q236927
PyCdlib._outfp_write_with_check
train
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 fi...
python
{ "resource": "" }
q236928
PyCdlib._output_file_data
train
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 o...
python
{ "resource": "" }
q236929
PyCdlib._write_directory_records
train
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 Descripto...
python
{ "resource": "" }
q236930
PyCdlib._write_udf_descs
train
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 fil...
python
{ "resource": "" }
q236931
PyCdlib._update_rr_ce_entry
train
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...
python
{ "resource": "" }
q236932
PyCdlib._finish_add
train
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:...
python
{ "resource": "" }
q236933
PyCdlib._finish_remove
train
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: ...
python
{ "resource": "" }
q236934
PyCdlib._rm_dr_link
train
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. ''' ...
python
{ "resource": "" }
q236935
PyCdlib._rm_udf_file_ident
train
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 UD...
python
{ "resource": "" }
q236936
PyCdlib._rm_udf_link
train
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...
python
{ "resource": "" }
q236937
PyCdlib._add_joliet_dir
train
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 ...
python
{ "resource": "" }
q236938
PyCdlib._rm_joliet_dir
train
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...
python
{ "resource": "" }
q236939
PyCdlib._get_entry
train
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 re...
python
{ "resource": "" }
q236940
PyCdlib._get_udf_entry
train
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 ...
python
{ "resource": "" }
q236941
PyCdlib._create_dot
train
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' Direct...
python
{ "resource": "" }
q236942
PyCdlib._create_dotdot
train
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 ...
python
{ "resource": "" }
q236943
PyCdlib.open
train
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 pycdlib...
python
{ "resource": "" }
q236944
PyCdlib.open_fp
train
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 opera...
python
{ "resource": "" }
q236945
PyCdlib.get_file_from_iso
train
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 transfe...
python
{ "resource": "" }
q236946
PyCdlib.get_file_from_iso_fp
train
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 ...
python
{ "resource": "" }
q236947
PyCdlib.write
train
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'. ...
python
{ "resource": "" }
q236948
PyCdlib.add_file
train
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 als...
python
{ "resource": "" }
q236949
PyCdlib.rm_file
train
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_n...
python
{ "resource": "" }
q236950
PyCdlib.get_record
train
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 - T...
python
{ "resource": "" }
q236951
PyCdlib.full_path_from_dirrecord
train
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 - Whe...
python
{ "resource": "" }
q236952
PyCdlib.duplicate_pvd
train
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. ''...
python
{ "resource": "" }
q236953
PyCdlib.clear_hidden
train
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. E...
python
{ "resource": "" }
q236954
PyCdlib.set_relocated_name
train
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...
python
{ "resource": "" }
q236955
PyCdlib.close
train
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._initiali...
python
{ "resource": "" }
q236956
make_arg_parser
train
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') ...
python
{ "resource": "" }
q236957
get_options
train
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 exce...
python
{ "resource": "" }
q236958
HealthChecker._update_bird_conf_file
train
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: ...
python
{ "resource": "" }
q236959
HealthChecker.run
train
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)) ...
python
{ "resource": "" }
q236960
valid_ip_prefix
train
def valid_ip_prefix(ip_prefix): """Perform a sanity check on ip_prefix. Arguments: ip_prefix (str): The IP-Prefix to validate Returns: True if ip_prefix is a valid IPv4 address with prefix length 32 or a valid IPv6 address with prefix length 128, otherwise False """ try: ...
python
{ "resource": "" }
q236961
get_ip_prefixes_from_config
train
def get_ip_prefixes_from_config(config, services, ip_version): """Build a set of IP prefixes found in service configuration files. Arguments: config (obg): A configparser object which holds our configuration. services (list): A list of section names which are the name of the service che...
python
{ "resource": "" }
q236962
ip_prefixes_sanity_check
train
def ip_prefixes_sanity_check(config, bird_configuration): """Sanity check on IP prefixes. Arguments: config (obg): A configparser object which holds our configuration. bird_configuration (dict): A dictionary, which holds Bird configuration per IP protocol version. """ for ip_ve...
python
{ "resource": "" }
q236963
modify_ip_prefixes
train
def modify_ip_prefixes( config, config_file, variable_name, dummy_ip_prefix, reconfigure_cmd, keep_changes, changes_counter, ip_version): """Modify IP prefixes in Bird configuration. Depending on the configuration either removes or reports IP pref...
python
{ "resource": "" }
q236964
load_configuration
train
def load_configuration(config_file, config_dir, service_file): """Build configuration objects. If all sanity checks against daemon and service check settings are passed then it builds a ConfigParser object which holds all our configuration and a dictionary data structure which holds Bird configuration ...
python
{ "resource": "" }
q236965
configuration_check
train
def configuration_check(config): """Perform a sanity check on configuration. First it performs a sanity check against settings for daemon and then against settings for each service check. Arguments: config (obj): A configparser object which holds our configuration. Returns: None i...
python
{ "resource": "" }
q236966
build_bird_configuration
train
def build_bird_configuration(config): """Build bird configuration structure. First it performs a sanity check against bird settings and then builds a dictionary structure with bird configuration per IP version. Arguments: config (obj): A configparser object which holds our configuration. ...
python
{ "resource": "" }
q236967
get_variable_name_from_bird
train
def get_variable_name_from_bird(bird_conf): """Return the variable name set in Bird configuration. The variable name in Bird configuration is set with the keyword 'define', here is an example: define ACAST_PS_ADVERTISE = and we exract the string between the word 'define' and the equals sign. ...
python
{ "resource": "" }
q236968
create_bird_config_files
train
def create_bird_config_files(bird_configuration): """Create bird configuration files per IP version. Creates bird configuration files if they don't exist. It also creates the directories where we store the history of changes, if this functionality is enabled. Arguments: bird_configuration ...
python
{ "resource": "" }
q236969
running
train
def running(processid): """Check the validity of a process ID. Arguments: processid (int): Process ID number. Returns: True if process ID is found otherwise False. """ try: # From kill(2) # If sig is 0 (the null signal), error checking is performed but no ...
python
{ "resource": "" }
q236970
get_ip_prefixes_from_bird
train
def get_ip_prefixes_from_bird(filename): """Build a list of IP prefixes found in Bird configuration. Arguments: filename (str): The absolute path of the Bird configuration file. Notes: It can only parse a file with the following format define ACAST_PS_ADVERTISE = ...
python
{ "resource": "" }
q236971
reconfigure_bird
train
def reconfigure_bird(cmd): """Reconfigure BIRD daemon. Arguments: cmd (string): A command to trigger a reconfiguration of Bird daemon Notes: Runs 'birdc configure' to reconfigure BIRD. Some useful information on how birdc tool works: -- Returns a non-zero exit code only...
python
{ "resource": "" }
q236972
write_temp_bird_conf
train
def write_temp_bird_conf(dummy_ip_prefix, config_file, variable_name, prefixes): """Write in a temporary file the list of IP-Prefixes. A failure to create and write the temporary file will exit main program. Arguments: dumm...
python
{ "resource": "" }
q236973
archive_bird_conf
train
def archive_bird_conf(config_file, changes_counter): """Keep a history of Bird configuration files. Arguments: config_file (str): file name of bird configuration changes_counter (int): number of configuration files to keep in the history """ log = logging.getLogger(PROGRAM_NAME)...
python
{ "resource": "" }
q236974
update_pidfile
train
def update_pidfile(pidfile): """Update pidfile. Notice: We should call this function only after we have successfully acquired a lock and never before. It exits main program if it fails to parse and/or write pidfile. Arguments: pidfile (str): pidfile to update """ t...
python
{ "resource": "" }
q236975
write_pid
train
def write_pid(pidfile): """Write processID to the pidfile. Notice: It exits main program if it fails to write pidfile. Arguments: pidfile (str): pidfile to update """ pid = str(os.getpid()) try: with open(pidfile, mode='w') as _file: print("writing processI...
python
{ "resource": "" }
q236976
shutdown
train
def shutdown(pidfile, signalnb=None, frame=None): """Clean up pidfile upon shutdown. Notice: We should register this function as signal handler for the following termination signals: SIGHUP SIGTERM SIGABRT SIGINT Arguments: pidfile (s...
python
{ "resource": "" }
q236977
setup_logger
train
def setup_logger(config): """Configure the logging environment. Notice: By default logging will go to STDOUT and messages for unhandled exceptions or crashes will go to STDERR. If log_file and/or log_server is set then we don't log to STDOUT. Messages for unhandled exceptions or...
python
{ "resource": "" }
q236978
run_custom_bird_reconfigure
train
def run_custom_bird_reconfigure(operation): """Reconfigure BIRD daemon by running a custom command. It adds one argument to the command, either "up" or "down". If command times out then we kill it. In order to avoid leaving any orphan processes, that may have been started by the command, we start a new...
python
{ "resource": "" }
q236979
AddOperation.update
train
def update(self, prefixes): """Add a value to the list. Arguments: prefixes(list): A list to add the value """ if self.ip_prefix not in prefixes: prefixes.append(self.ip_prefix) self.log.info("announcing %s for %s", self.ip_prefix, self.name) ...
python
{ "resource": "" }
q236980
CustomLogger.write
train
def write(self, string): """Erase newline from a string and write to the logger.""" string = string.rstrip() if string: # Don't log empty lines self.logger.critical(string)
python
{ "resource": "" }
q236981
CustomJsonFormatter.process_log_record
train
def process_log_record(self, log_record): """Add customer record keys and rename threadName key.""" log_record["version"] = __version__ log_record["program"] = PROGRAM_NAME log_record["service_name"] = log_record.pop('threadName', None) # return jsonlogger.JsonFormatter.process_l...
python
{ "resource": "" }
q236982
get_vexrc
train
def get_vexrc(options, environ): """Get a representation of the contents of the config file. :returns: a Vexrc instance. """ # Complain if user specified nonexistent file with --config. # But we don't want to complain just because ~/.vexrc doesn't exist. if options.config and not os.pat...
python
{ "resource": "" }
q236983
get_cwd
train
def get_cwd(options): """Discover what directory the command should run in. """ if not options.cwd: return None if not os.path.exists(options.cwd): raise exceptions.InvalidCwd( "can't --cwd to invalid path {0!r}".format(options.cwd)) return options.cwd
python
{ "resource": "" }
q236984
get_virtualenv_path
train
def get_virtualenv_path(ve_base, ve_name): """Check a virtualenv path, raising exceptions to explain problems. """ if not ve_base: raise exceptions.NoVirtualenvsDirectory( "could not figure out a virtualenvs directory. " "make sure $HOME is set, or $WORKON_HOME," ...
python
{ "resource": "" }
q236985
get_command
train
def get_command(options, vexrc, environ): """Get a command to run. :returns: a list of strings representing a command to be passed to Popen. """ command = options.rest if not command: command = vexrc.get_shell(environ) if command and command[0].startswith('--'): raise ex...
python
{ "resource": "" }
q236986
main
train
def main(): """The main command-line entry point, with system interactions. """ argv = sys.argv[1:] returncode = 1 try: returncode = _main(os.environ, argv) except exceptions.InvalidArgument as error: if error.message: sys.stderr.write("Error: " + error.message + '\n'...
python
{ "resource": "" }
q236987
get_processid
train
def get_processid(config): """Return process id of anycast-healthchecker. Arguments: config (obj): A configparser object with the configuration of anycast-healthchecker. Returns: The process id found in the pid file Raises: ValueError in the following cases - p...
python
{ "resource": "" }
q236988
parse_services
train
def parse_services(config, services): """Parse configuration to return number of enabled service checks. Arguments: config (obj): A configparser object with the configuration of anycast-healthchecker. services (list): A list of section names which holds configuration for each se...
python
{ "resource": "" }
q236989
main
train
def main(): """Run check. anycast-healthchecker is a multi-threaded software and for each service check it holds a thread. If a thread dies then the service is not monitored anymore and the route for the IP associated with service it wont be withdrawn in case service goes down in the meantime. ...
python
{ "resource": "" }
q236990
scary_path
train
def scary_path(path): """Whitelist the WORKON_HOME strings we're willing to substitute in to strings that we provide for user's shell to evaluate. If it smells at all bad, return True. """ if not path: return True assert isinstance(path, bytes) return not NOT_SCARY.match(path)
python
{ "resource": "" }
q236991
shell_config_for
train
def shell_config_for(shell, vexrc, environ): """return completion config for the named shell. """ here = os.path.dirname(os.path.abspath(__file__)) path = os.path.join(here, 'shell_configs', shell) try: with open(path, 'rb') as inp: data = inp.read() except FileNotFoundError ...
python
{ "resource": "" }
q236992
ServiceCheck._run_check
train
def _run_check(self): """Execute a check command. Returns: True if the exit code of the command is 0 otherwise False. """ cmd = shlex.split(self.config['check_cmd']) self.log.info("running %s", ' '.join(cmd)) proc = subprocess.Popen(cmd, stdout=subprocess.PI...
python
{ "resource": "" }
q236993
ServiceCheck._ip_assigned
train
def _ip_assigned(self): """Check if IP prefix is assigned to loopback interface. Returns: True if IP prefix found assigned otherwise False. """ output = [] cmd = [ '/sbin/ip', 'address', 'show', 'dev', self...
python
{ "resource": "" }
q236994
ServiceCheck._check_disabled
train
def _check_disabled(self): """Check if health check is disabled. It logs a message if health check is disabled and it also adds an item to the action queue based on 'on_disabled' setting. Returns: True if check is disabled otherwise False. """ if self.confi...
python
{ "resource": "" }
q236995
ServiceCheck.run
train
def run(self): """Wrap _run method.""" # Catch all possible exceptions raised by the running thread # and let parent process know about it. try: self._run() except Exception: # pylint: disable=broad-except self.action.put( ServiceCheckDied...
python
{ "resource": "" }
q236996
main
train
def main(): """Parse CLI and starts main program.""" args = docopt(__doc__, version=__version__) if args['--print']: for section in DEFAULT_OPTIONS: print("[{}]".format(section)) for key, value in DEFAULT_OPTIONS[section].items(): print("{k} = {v}".format(k=ke...
python
{ "resource": "" }
q236997
get_environ
train
def get_environ(environ, defaults, ve_path): """Make an environment to run with. """ # Copy the parent environment, add in defaults from .vexrc. env = environ.copy() env.update(defaults) # Leaving in existing PYTHONHOME can cause some errors if 'PYTHONHOME' in env: del env['PYTHONHO...
python
{ "resource": "" }
q236998
extract_key_value
train
def extract_key_value(line, environ): """Return key, value from given line if present, else return None. """ segments = line.split("=", 1) if len(segments) < 2: return None key, value = segments # foo passes through as-is (with spaces stripped) # '{foo}' passes through literally ...
python
{ "resource": "" }
q236999
Vexrc.from_file
train
def from_file(cls, path, environ): """Make a Vexrc instance from given file in given environ. """ instance = cls() instance.read(path, environ) return instance
python
{ "resource": "" }