_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q228900 | TocFetcher._toc_fetch_finished | train | def _toc_fetch_finished(self):
"""Callback for when the TOC fetching is finished"""
self.cf.remove_port_callback(self.port, self._new_packet_cb)
logger.debug('[%d]: Done!', self.port)
self.finished_callback() | python | {
"resource": ""
} |
q228901 | TocFetcher._new_packet_cb | train | def _new_packet_cb(self, packet):
"""Handle a newly arrived packet"""
chan = packet.channel
if (chan != 0):
return
payload = packet.data[1:]
if (self.state == GET_TOC_INFO):
if self._useV2:
[self.nbr_of_items, self._crc] = struct.unpack(
... | python | {
"resource": ""
} |
q228902 | TocFetcher._request_toc_element | train | def _request_toc_element(self, index):
"""Request information about a specific item in the TOC"""
logger.debug('Requesting index %d on port %d', index, self.port)
pk = CRTPPacket()
if self._useV2:
pk.set_header(self.port, TOC_CHANNEL)
pk.data = (CMD_TOC_ITEM_V2, i... | python | {
"resource": ""
} |
q228903 | Crazyflie._start_connection_setup | train | def _start_connection_setup(self):
"""Start the connection setup by refreshing the TOCs"""
logger.info('We are connected[%s], request connection setup',
self.link_uri)
self.platform.fetch_platform_informations(self._platform_info_fetched) | python | {
"resource": ""
} |
q228904 | Crazyflie._param_toc_updated_cb | train | def _param_toc_updated_cb(self):
"""Called when the param TOC has been fully updated"""
logger.info('Param TOC finished updating')
self.connected_ts = datetime.datetime.now()
self.connected.call(self.link_uri)
# Trigger the update for all the parameters
self.param.request... | python | {
"resource": ""
} |
q228905 | Crazyflie._mems_updated_cb | train | def _mems_updated_cb(self):
"""Called when the memories have been identified"""
logger.info('Memories finished updating')
self.param.refresh_toc(self._param_toc_updated_cb, self._toc_cache) | python | {
"resource": ""
} |
q228906 | Crazyflie._link_error_cb | train | def _link_error_cb(self, errmsg):
"""Called from the link driver when there's an error"""
logger.warning('Got link error callback [%s] in state [%s]',
errmsg, self.state)
if (self.link is not None):
self.link.close()
self.link = None
if (self.st... | python | {
"resource": ""
} |
q228907 | Crazyflie._check_for_initial_packet_cb | train | def _check_for_initial_packet_cb(self, data):
"""
Called when first packet arrives from Crazyflie.
This is used to determine if we are connected to something that is
answering.
"""
self.state = State.CONNECTED
self.link_established.call(self.link_uri)
sel... | python | {
"resource": ""
} |
q228908 | Crazyflie.close_link | train | def close_link(self):
"""Close the communication link."""
logger.info('Closing link')
if (self.link is not None):
self.commander.send_setpoint(0, 0, 0, 0)
if (self.link is not None):
self.link.close()
self.link = None
self._answer_patterns = {}... | python | {
"resource": ""
} |
q228909 | Crazyflie._no_answer_do_retry | train | def _no_answer_do_retry(self, pk, pattern):
"""Resend packets that we have not gotten answers to"""
logger.info('Resending for pattern %s', pattern)
# Set the timer to None before trying to send again
self.send_packet(pk, expected_reply=pattern, resend=True) | python | {
"resource": ""
} |
q228910 | Crazyflie._check_for_answers | train | def _check_for_answers(self, pk):
"""
Callback called for every packet received to check if we are
waiting for an answer on this port. If so, then cancel the retry
timer.
"""
longest_match = ()
if len(self._answer_patterns) > 0:
data = (pk.header,) + t... | python | {
"resource": ""
} |
q228911 | Crazyflie.send_packet | train | def send_packet(self, pk, expected_reply=(), resend=False, timeout=0.2):
"""
Send a packet through the link interface.
pk -- Packet to send
expect_answer -- True if a packet from the Crazyflie is expected to
be sent back, otherwise false
"""
sel... | python | {
"resource": ""
} |
q228912 | _IncomingPacketHandler.add_port_callback | train | def add_port_callback(self, port, cb):
"""Add a callback for data that comes on a specific port"""
logger.debug('Adding callback on port [%d] to [%s]', port, cb)
self.add_header_callback(cb, port, 0, 0xff, 0x0) | python | {
"resource": ""
} |
q228913 | _IncomingPacketHandler.remove_port_callback | train | def remove_port_callback(self, port, cb):
"""Remove a callback for data that comes on a specific port"""
logger.debug('Removing callback on port [%d] to [%s]', port, cb)
for port_callback in self.cb:
if port_callback.port == port and port_callback.callback == cb:
self... | python | {
"resource": ""
} |
q228914 | LogConfig.add_variable | train | def add_variable(self, name, fetch_as=None):
"""Add a new variable to the configuration.
name - Complete name of the variable in the form group.name
fetch_as - String representation of the type the variable should be
fetched as (i.e uint8_t, float, FP16, etc)
If no f... | python | {
"resource": ""
} |
q228915 | LogConfig.add_memory | train | def add_memory(self, name, fetch_as, stored_as, address):
"""Add a raw memory position to log.
name - Arbitrary name of the variable
fetch_as - String representation of the type of the data the memory
should be fetch as (i.e uint8_t, float, FP16)
stored_as - String re... | python | {
"resource": ""
} |
q228916 | LogConfig.create | train | def create(self):
"""Save the log configuration in the Crazyflie"""
pk = CRTPPacket()
pk.set_header(5, CHAN_SETTINGS)
if self.useV2:
pk.data = (CMD_CREATE_BLOCK_V2, self.id)
else:
pk.data = (CMD_CREATE_BLOCK, self.id)
for var in self.variables:
... | python | {
"resource": ""
} |
q228917 | LogConfig.start | train | def start(self):
"""Start the logging for this entry"""
if (self.cf.link is not None):
if (self._added is False):
self.create()
logger.debug('First time block is started, add block')
else:
logger.debug('Block already registered, sta... | python | {
"resource": ""
} |
q228918 | LogConfig.stop | train | def stop(self):
"""Stop the logging for this entry"""
if (self.cf.link is not None):
if (self.id is None):
logger.warning('Stopping block, but no block registered')
else:
logger.debug('Sending stop logging for block id=%d', self.id)
... | python | {
"resource": ""
} |
q228919 | LogConfig.delete | train | def delete(self):
"""Delete this entry in the Crazyflie"""
if (self.cf.link is not None):
if (self.id is None):
logger.warning('Delete block, but no block registered')
else:
logger.debug('LogEntry: Sending delete logging for block id=%d'
... | python | {
"resource": ""
} |
q228920 | LogConfig.unpack_log_data | train | def unpack_log_data(self, log_data, timestamp):
"""Unpack received logging data so it represent real values according
to the configuration in the entry"""
ret_data = {}
data_index = 0
for var in self.variables:
size = LogTocElement.get_size_from_id(var.fetch_as)
... | python | {
"resource": ""
} |
q228921 | LogTocElement.get_id_from_cstring | train | def get_id_from_cstring(name):
"""Return variable type id given the C-storage name"""
for key in list(LogTocElement.types.keys()):
if (LogTocElement.types[key][0] == name):
return key
raise KeyError('Type [%s] not found in LogTocElement.types!' % name) | python | {
"resource": ""
} |
q228922 | Log.add_config | train | def add_config(self, logconf):
"""Add a log configuration to the logging framework.
When doing this the contents of the log configuration will be validated
and listeners for new log configurations will be notified. When
validating the configuration the variables are checked against the ... | python | {
"resource": ""
} |
q228923 | Log.refresh_toc | train | def refresh_toc(self, refresh_done_callback, toc_cache):
"""Start refreshing the table of loggale variables"""
self._useV2 = self.cf.platform.get_protocol_version() >= 4
self._toc_cache = toc_cache
self._refresh_callback = refresh_done_callback
self.toc = None
pk = CRT... | python | {
"resource": ""
} |
q228924 | init_drivers | train | def init_drivers(enable_debug_driver=False):
"""Initialize all the drivers."""
for driver in DRIVERS:
try:
if driver != DebugDriver or enable_debug_driver:
CLASSES.append(driver)
except Exception: # pylint: disable=W0703
continue | python | {
"resource": ""
} |
q228925 | scan_interfaces | train | def scan_interfaces(address=None):
""" Scan all the interfaces for available Crazyflies """
available = []
found = []
for driverClass in CLASSES:
try:
logger.debug('Scanning: %s', driverClass)
instance = driverClass()
found = instance.scan_interface(address)
... | python | {
"resource": ""
} |
q228926 | get_interfaces_status | train | def get_interfaces_status():
"""Get the status of all the interfaces"""
status = {}
for driverClass in CLASSES:
try:
instance = driverClass()
status[instance.get_name()] = instance.get_status()
except Exception:
raise
return status | python | {
"resource": ""
} |
q228927 | get_link_driver | train | def get_link_driver(uri, link_quality_callback=None, link_error_callback=None):
"""Return the link driver for the given URI. Returns None if no driver
was found for the URI or the URI was not well formatted for the matching
driver."""
for driverClass in CLASSES:
try:
instance = drive... | python | {
"resource": ""
} |
q228928 | Localization.send_short_lpp_packet | train | def send_short_lpp_packet(self, dest_id, data):
"""
Send ultra-wide-band LPP packet to dest_id
"""
pk = CRTPPacket()
pk.port = CRTPPort.LOCALIZATION
pk.channel = self.GENERIC_CH
pk.data = struct.pack('<BB', self.LPS_SHORT_LPP_PACKET, dest_id) + data
self.... | python | {
"resource": ""
} |
q228929 | Commander.send_velocity_world_setpoint | train | def send_velocity_world_setpoint(self, vx, vy, vz, yawrate):
"""
Send Velocity in the world frame of reference setpoint.
vx, vy, vz are in m/s
yawrate is in degrees/s
"""
pk = CRTPPacket()
pk.port = CRTPPort.COMMANDER_GENERIC
pk.data = struct.pack('<Bffff... | python | {
"resource": ""
} |
q228930 | Commander.send_position_setpoint | train | def send_position_setpoint(self, x, y, z, yaw):
"""
Control mode where the position is sent as absolute x,y,z coordinate in
meter and the yaw is the absolute orientation.
x and y are in m
yaw is in degrees
"""
pk = CRTPPacket()
pk.port = CRTPPort.COMMANDE... | python | {
"resource": ""
} |
q228931 | MemoryElement.type_to_string | train | def type_to_string(t):
"""Get string representation of memory type"""
if t == MemoryElement.TYPE_I2C:
return 'I2C'
if t == MemoryElement.TYPE_1W:
return '1-wire'
if t == MemoryElement.TYPE_DRIVER_LED:
return 'LED driver'
if t == MemoryElement.T... | python | {
"resource": ""
} |
q228932 | LEDDriverMemory.write_data | train | def write_data(self, write_finished_cb):
"""Write the saved LED-ring data to the Crazyflie"""
self._write_finished_cb = write_finished_cb
data = bytearray()
for led in self.leds:
# In order to fit all the LEDs in one radio packet RGB565 is used
# to compress the c... | python | {
"resource": ""
} |
q228933 | OWElement._parse_and_check_elements | train | def _parse_and_check_elements(self, data):
"""
Parse and check the CRC and length of the elements part of the memory
"""
crc = data[-1]
test_crc = crc32(data[:-1]) & 0x0ff
elem_data = data[2:-1]
if test_crc == crc:
while len(elem_data) > 0:
... | python | {
"resource": ""
} |
q228934 | OWElement._parse_and_check_header | train | def _parse_and_check_header(self, data):
"""Parse and check the CRC of the header part of the memory"""
(start, self.pins, self.vid, self.pid, crc) = struct.unpack('<BIBBB',
data)
test_crc = crc32(data[:-1]) & 0x0ff
if s... | python | {
"resource": ""
} |
q228935 | LocoMemory2.update_id_list | train | def update_id_list(self, update_ids_finished_cb):
"""Request an update of the id list"""
if not self._update_ids_finished_cb:
self._update_ids_finished_cb = update_ids_finished_cb
self.anchor_ids = []
self.active_anchor_ids = []
self.anchor_data = {}
... | python | {
"resource": ""
} |
q228936 | LocoMemory2.update_active_id_list | train | def update_active_id_list(self, update_active_ids_finished_cb):
"""Request an update of the active id list"""
if not self._update_active_ids_finished_cb:
self._update_active_ids_finished_cb = update_active_ids_finished_cb
self.active_anchor_ids = []
self.active_ids_v... | python | {
"resource": ""
} |
q228937 | LocoMemory2.update_data | train | def update_data(self, update_data_finished_cb):
"""Request an update of the anchor data"""
if not self._update_data_finished_cb and self.nr_of_anchors > 0:
self._update_data_finished_cb = update_data_finished_cb
self.anchor_data = {}
self.data_valid = False
... | python | {
"resource": ""
} |
q228938 | TrajectoryMemory.write_data | train | def write_data(self, write_finished_cb):
"""Write trajectory data to the Crazyflie"""
self._write_finished_cb = write_finished_cb
data = bytearray()
for poly4D in self.poly4Ds:
data += struct.pack('<ffffffff', *poly4D.x.values)
data += struct.pack('<ffffffff', *p... | python | {
"resource": ""
} |
q228939 | Memory.get_mem | train | def get_mem(self, id):
"""Fetch the memory with the supplied id"""
for m in self.mems:
if m.id == id:
return m
return None | python | {
"resource": ""
} |
q228940 | Memory.get_mems | train | def get_mems(self, type):
"""Fetch all the memories of the supplied type"""
ret = ()
for m in self.mems:
if m.type == type:
ret += (m,)
return ret | python | {
"resource": ""
} |
q228941 | Memory.write | train | def write(self, memory, addr, data, flush_queue=False):
"""Write the specified data to the given memory at the given address"""
wreq = _WriteRequest(memory, addr, data, self.cf)
if memory.id not in self._write_requests:
self._write_requests[memory.id] = []
# Workaround until... | python | {
"resource": ""
} |
q228942 | Memory.read | train | def read(self, memory, addr, length):
"""
Read the specified amount of bytes from the given memory at the given
address
"""
if memory.id in self._read_requests:
logger.warning('There is already a read operation ongoing for '
'memory id {}'.f... | python | {
"resource": ""
} |
q228943 | Memory.refresh | train | def refresh(self, refresh_done_callback):
"""Start fetching all the detected memories"""
self._refresh_callback = refresh_done_callback
self._fetch_id = 0
for m in self.mems:
try:
self.mem_read_cb.remove_callback(m.new_data)
m.disconnect()
... | python | {
"resource": ""
} |
q228944 | Cloader.reset_to_bootloader1 | train | def reset_to_bootloader1(self, cpu_id):
""" Reset to the bootloader
The parameter cpuid shall correspond to the device to reset.
Return true if the reset has been done and the contact with the
bootloader is established.
"""
# Send an echo request and wait for the answer
... | python | {
"resource": ""
} |
q228945 | Cloader.reset_to_firmware | train | def reset_to_firmware(self, target_id):
""" Reset to firmware
The parameter cpuid shall correspond to the device to reset.
Return true if the reset has been done
"""
# The fake CPU ID is legacy from the Crazyflie 1.0
# In order to reset the CPU id had to be sent, but thi... | python | {
"resource": ""
} |
q228946 | Cloader.check_link_and_get_info | train | def check_link_and_get_info(self, target_id=0xFF):
"""Try to get a connection with the bootloader by requesting info
5 times. This let roughly 10 seconds to boot the copter ..."""
for _ in range(0, 5):
if self._update_info(target_id):
if self._in_boot_cb:
... | python | {
"resource": ""
} |
q228947 | Cloader._update_info | train | def _update_info(self, target_id):
""" Call the command getInfo and fill up the information received in
the fields of the object
"""
# Call getInfo ...
pk = CRTPPacket()
pk.set_header(0xFF, 0xFF)
pk.data = (target_id, 0x10)
self.link.send_packet(pk)
... | python | {
"resource": ""
} |
q228948 | Cloader.upload_buffer | train | def upload_buffer(self, target_id, page, address, buff):
"""Upload data into a buffer on the Crazyflie"""
# print len(buff)
count = 0
pk = CRTPPacket()
pk.set_header(0xFF, 0xFF)
pk.data = struct.pack('=BBHH', target_id, 0x14, page, address)
for i in range(0, len(... | python | {
"resource": ""
} |
q228949 | Cloader.read_flash | train | def read_flash(self, addr=0xFF, page=0x00):
"""Read back a flash page from the Crazyflie and return it"""
buff = bytearray()
page_size = self.targets[addr].page_size
for i in range(0, int(math.ceil(page_size / 25.0))):
pk = None
retry_counter = 5
whi... | python | {
"resource": ""
} |
q228950 | Cloader.write_flash | train | def write_flash(self, addr, page_buffer, target_page, page_count):
"""Initiate flashing of data in the buffer to flash."""
# print "Write page", flashPage
# print "Writing page [%d] and [%d] forward" % (flashPage, nPage)
pk = None
# Flushing downlink ...
pk = self.link.r... | python | {
"resource": ""
} |
q228951 | Cloader.decode_cpu_id | train | def decode_cpu_id(self, cpuid):
"""Decode the CPU id into a string"""
ret = ()
for i in cpuid.split(':'):
ret += (eval('0x' + i),)
return ret | python | {
"resource": ""
} |
q228952 | CRTPPacket.set_header | train | def set_header(self, port, channel):
"""
Set the port and channel for this packet.
"""
self._port = port
self.channel = channel
self._update_header() | python | {
"resource": ""
} |
q228953 | CRTPPacket._set_data | train | def _set_data(self, data):
"""Set the packet data"""
if type(data) == bytearray:
self._data = data
elif type(data) == str:
if sys.version_info < (3,):
self._data = bytearray(data)
else:
self._data = bytearray(data.encode('ISO-88... | python | {
"resource": ""
} |
q228954 | MotionCommander.take_off | train | def take_off(self, height=None, velocity=VELOCITY):
"""
Takes off, that is starts the motors, goes straigt up and hovers.
Do not call this function if you use the with keyword. Take off is
done automatically when the context is created.
:param height: the height (meters) to hove... | python | {
"resource": ""
} |
q228955 | MotionCommander.turn_left | train | def turn_left(self, angle_degrees, rate=RATE):
"""
Turn to the left, staying on the spot
:param angle_degrees: How far to turn (degrees)
:param rate: The trurning speed (degrees/second)
:return:
"""
flight_time = angle_degrees / rate
self.start_turn_left... | python | {
"resource": ""
} |
q228956 | MotionCommander.turn_right | train | def turn_right(self, angle_degrees, rate=RATE):
"""
Turn to the right, staying on the spot
:param angle_degrees: How far to turn (degrees)
:param rate: The trurning speed (degrees/second)
:return:
"""
flight_time = angle_degrees / rate
self.start_turn_ri... | python | {
"resource": ""
} |
q228957 | MotionCommander.circle_left | train | def circle_left(self, radius_m, velocity=VELOCITY, angle_degrees=360.0):
"""
Go in circle, counter clock wise
:param radius_m: The radius of the circle (meters)
:param velocity: The velocity along the circle (meters/second)
:param angle_degrees: How far to go in the circle (degr... | python | {
"resource": ""
} |
q228958 | MotionCommander.circle_right | train | def circle_right(self, radius_m, velocity=VELOCITY, angle_degrees=360.0):
"""
Go in circle, clock wise
:param radius_m: The radius of the circle (meters)
:param velocity: The velocity along the circle (meters/second)
:param angle_degrees: How far to go in the circle (degrees)
... | python | {
"resource": ""
} |
q228959 | MotionCommander.start_circle_left | train | def start_circle_left(self, radius_m, velocity=VELOCITY):
"""
Start a circular motion to the left. This function returns immediately.
:param radius_m: The radius of the circle (meters)
:param velocity: The velocity of the motion (meters/second)
:return:
"""
circu... | python | {
"resource": ""
} |
q228960 | MotionCommander.start_linear_motion | train | def start_linear_motion(self, velocity_x_m, velocity_y_m, velocity_z_m):
"""
Start a linear motion. This function returns immediately.
positive X is forward
positive Y is left
positive Z is up
:param velocity_x_m: The velocity along the X-axis (meters/second)
:p... | python | {
"resource": ""
} |
q228961 | _SetPointThread.set_vel_setpoint | train | def set_vel_setpoint(self, velocity_x, velocity_y, velocity_z, rate_yaw):
"""Set the velocity setpoint to use for the future motion"""
self._queue.put((velocity_x, velocity_y, velocity_z, rate_yaw)) | python | {
"resource": ""
} |
q228962 | ParamExample._param_callback | train | def _param_callback(self, name, value):
"""Generic callback registered for all the groups"""
print('{0}: {1}'.format(name, value))
# Remove each parameter from the list and close the link when
# all are fetched
self._param_check_list.remove(name)
if len(self._param_check... | python | {
"resource": ""
} |
q228963 | ParamExample._a_pitch_kd_callback | train | def _a_pitch_kd_callback(self, name, value):
"""Callback for pid_attitude.pitch_kd"""
print('Readback: {0}={1}'.format(name, value))
# End the example by closing the link (will cause the app to quit)
self._cf.close_link() | python | {
"resource": ""
} |
q228964 | RadioDriver._scan_radio_channels | train | def _scan_radio_channels(self, cradio, start=0, stop=125):
""" Scan for Crazyflies between the supplied channels. """
return list(cradio.scan_channels(start, stop, (0xff,))) | python | {
"resource": ""
} |
q228965 | main | train | def main(client_secrets, scope, save, credentials, headless):
"""Command-line tool for obtaining authorization and credentials from a user.
This tool uses the OAuth 2.0 Authorization Code grant as described
in section 1.3.1 of RFC6749:
https://tools.ietf.org/html/rfc6749#section-1.3.1
This tool is... | python | {
"resource": ""
} |
q228966 | Flow.authorization_url | train | def authorization_url(self, **kwargs):
"""Generates an authorization URL.
This is the first step in the OAuth 2.0 Authorization Flow. The user's
browser should be redirected to the returned URL.
This method calls
:meth:`requests_oauthlib.OAuth2Session.authorization_url`
... | python | {
"resource": ""
} |
q228967 | Flow.fetch_token | train | def fetch_token(self, **kwargs):
"""Completes the Authorization Flow and obtains an access token.
This is the final step in the OAuth 2.0 Authorization Flow. This is
called after the user consents.
This method calls
:meth:`requests_oauthlib.OAuth2Session.fetch_token`
an... | python | {
"resource": ""
} |
q228968 | InstalledAppFlow.run_console | train | def run_console(
self,
authorization_prompt_message=_DEFAULT_AUTH_PROMPT_MESSAGE,
authorization_code_message=_DEFAULT_AUTH_CODE_MESSAGE,
**kwargs):
"""Run the flow using the console strategy.
The console strategy instructs the user to open the authorizati... | python | {
"resource": ""
} |
q228969 | InstalledAppFlow.run_local_server | train | def run_local_server(
self, host='localhost', port=8080,
authorization_prompt_message=_DEFAULT_AUTH_PROMPT_MESSAGE,
success_message=_DEFAULT_WEB_SUCCESS_MESSAGE,
open_browser=True,
**kwargs):
"""Run the flow using the server strategy.
The serv... | python | {
"resource": ""
} |
q228970 | Registry.install | train | def install(self, opener):
# type: (Union[Type[Opener], Opener, Callable[[], Opener]]) -> None
"""Install an opener.
Arguments:
opener (`Opener`): an `Opener` instance, or a callable that
returns an opener instance.
Note:
May be used as a class d... | python | {
"resource": ""
} |
q228971 | Registry.get_opener | train | def get_opener(self, protocol):
# type: (Text) -> Opener
"""Get the opener class associated to a given protocol.
Arguments:
protocol (str): A filesystem protocol.
Returns:
Opener: an opener instance.
Raises:
~fs.opener.errors.UnsupportedProt... | python | {
"resource": ""
} |
q228972 | Registry.open | train | def open(
self,
fs_url, # type: Text
writeable=True, # type: bool
create=False, # type: bool
cwd=".", # type: Text
default_protocol="osfs", # type: Text
):
# type: (...) -> Tuple[FS, Text]
"""Open a filesystem from a FS URL.
Returns a tup... | python | {
"resource": ""
} |
q228973 | Registry.manage_fs | train | def manage_fs(
self,
fs_url, # type: Union[FS, Text]
create=False, # type: bool
writeable=False, # type: bool
cwd=".", # type: Text
):
# type: (...) -> Iterator[FS]
"""Get a context manager to open and close a filesystem.
Arguments:
fs... | python | {
"resource": ""
} |
q228974 | copy_fs | train | def copy_fs(
src_fs, # type: Union[FS, Text]
dst_fs, # type: Union[FS, Text]
walker=None, # type: Optional[Walker]
on_copy=None, # type: Optional[_OnCopy]
workers=0, # type: int
):
# type: (...) -> None
"""Copy the contents of one filesystem to another.
Arguments:
src_fs (F... | python | {
"resource": ""
} |
q228975 | copy_fs_if_newer | train | def copy_fs_if_newer(
src_fs, # type: Union[FS, Text]
dst_fs, # type: Union[FS, Text]
walker=None, # type: Optional[Walker]
on_copy=None, # type: Optional[_OnCopy]
workers=0, # type: int
):
# type: (...) -> None
"""Copy the contents of one filesystem to another, checking times.
If ... | python | {
"resource": ""
} |
q228976 | _source_is_newer | train | def _source_is_newer(src_fs, src_path, dst_fs, dst_path):
# type: (FS, Text, FS, Text) -> bool
"""Determine if source file is newer than destination file.
Arguments:
src_fs (FS): Source filesystem (instance or URL).
src_path (str): Path to a file on the source filesystem.
dst_fs (FS... | python | {
"resource": ""
} |
q228977 | copy_file | train | def copy_file(
src_fs, # type: Union[FS, Text]
src_path, # type: Text
dst_fs, # type: Union[FS, Text]
dst_path, # type: Text
):
# type: (...) -> None
"""Copy a file from one filesystem to another.
If the destination exists, and is a file, it will be first truncated.
Arguments:
... | python | {
"resource": ""
} |
q228978 | copy_file_internal | train | def copy_file_internal(
src_fs, # type: FS
src_path, # type: Text
dst_fs, # type: FS
dst_path, # type: Text
):
# type: (...) -> None
"""Low level copy, that doesn't call manage_fs or lock.
If the destination exists, and is a file, it will be first truncated.
This method exists to o... | python | {
"resource": ""
} |
q228979 | copy_file_if_newer | train | def copy_file_if_newer(
src_fs, # type: Union[FS, Text]
src_path, # type: Text
dst_fs, # type: Union[FS, Text]
dst_path, # type: Text
):
# type: (...) -> bool
"""Copy a file from one filesystem to another, checking times.
If the destination exists, and is a file, it will be first trunca... | python | {
"resource": ""
} |
q228980 | copy_dir | train | def copy_dir(
src_fs, # type: Union[FS, Text]
src_path, # type: Text
dst_fs, # type: Union[FS, Text]
dst_path, # type: Text
walker=None, # type: Optional[Walker]
on_copy=None, # type: Optional[_OnCopy]
workers=0, # type: int
):
# type: (...) -> None
"""Copy a directory from on... | python | {
"resource": ""
} |
q228981 | copy_dir_if_newer | train | def copy_dir_if_newer(
src_fs, # type: Union[FS, Text]
src_path, # type: Text
dst_fs, # type: Union[FS, Text]
dst_path, # type: Text
walker=None, # type: Optional[Walker]
on_copy=None, # type: Optional[_OnCopy]
workers=0, # type: int
):
# type: (...) -> None
"""Copy a director... | python | {
"resource": ""
} |
q228982 | _parse_ftp_error | train | def _parse_ftp_error(error):
# type: (ftplib.Error) -> Tuple[Text, Text]
"""Extract code and message from ftp error."""
code, _, message = text_type(error).partition(" ")
return code, message | python | {
"resource": ""
} |
q228983 | FTPFile._open_ftp | train | def _open_ftp(self):
# type: () -> FTP
"""Open an ftp object for the file."""
ftp = self.fs._open_ftp()
ftp.voidcmd(str("TYPE I"))
return ftp | python | {
"resource": ""
} |
q228984 | FTPFS._parse_features | train | def _parse_features(cls, feat_response):
# type: (Text) -> Dict[Text, Text]
"""Parse a dict of features from FTP feat response.
"""
features = {}
if feat_response.split("-")[0] == "211":
for line in feat_response.splitlines():
if line.startswith(" "):
... | python | {
"resource": ""
} |
q228985 | FTPFS._open_ftp | train | def _open_ftp(self):
# type: () -> FTP
"""Open a new ftp object.
"""
_ftp = FTP()
_ftp.set_debuglevel(0)
with ftp_errors(self):
_ftp.connect(self.host, self.port, self.timeout)
_ftp.login(self.user, self.passwd, self.acct)
self._feature... | python | {
"resource": ""
} |
q228986 | FTPFS.ftp_url | train | def ftp_url(self):
# type: () -> Text
"""Get the FTP url this filesystem will open."""
url = (
"ftp://{}".format(self.host)
if self.port == 21
else "ftp://{}:{}".format(self.host, self.port)
)
return url | python | {
"resource": ""
} |
q228987 | FTPFS._parse_ftp_time | train | def _parse_ftp_time(cls, time_text):
# type: (Text) -> Optional[int]
"""Parse a time from an ftp directory listing.
"""
try:
tm_year = int(time_text[0:4])
tm_month = int(time_text[4:6])
tm_day = int(time_text[6:8])
tm_hour = int(time_text[8... | python | {
"resource": ""
} |
q228988 | write_zip | train | def write_zip(
src_fs, # type: FS
file, # type: Union[Text, BinaryIO]
compression=zipfile.ZIP_DEFLATED, # type: int
encoding="utf-8", # type: Text
walker=None, # type: Optional[Walker]
):
# type: (...) -> None
"""Write the contents of a filesystem to a zip file.
Arguments:
... | python | {
"resource": ""
} |
q228989 | write_tar | train | def write_tar(
src_fs, # type: FS
file, # type: Union[Text, BinaryIO]
compression=None, # type: Optional[Text]
encoding="utf-8", # type: Text
walker=None, # type: Optional[Walker]
):
# type: (...) -> None
"""Write the contents of a filesystem to a tar file.
Arguments:
file ... | python | {
"resource": ""
} |
q228990 | Globber.count_lines | train | def count_lines(self):
# type: () -> LineCounts
"""Count the lines in the matched files.
Returns:
`~LineCounts`: A named tuple containing line counts.
Example:
>>> import fs
>>> fs.open_fs('~/projects').glob('**/*.py').count_lines()
LineC... | python | {
"resource": ""
} |
q228991 | Globber.remove | train | def remove(self):
# type: () -> int
"""Removed all matched paths.
Returns:
int: Number of file and directories removed.
Example:
>>> import fs
>>> fs.open_fs('~/projects/my_project').glob('**/*.pyc').remove()
29
"""
remov... | python | {
"resource": ""
} |
q228992 | move_file | train | def move_file(
src_fs, # type: Union[Text, FS]
src_path, # type: Text
dst_fs, # type: Union[Text, FS]
dst_path, # type: Text
):
# type: (...) -> None
"""Move a file from one filesystem to another.
Arguments:
src_fs (FS or str): Source filesystem (instance or URL).
src_pa... | python | {
"resource": ""
} |
q228993 | move_dir | train | def move_dir(
src_fs, # type: Union[Text, FS]
src_path, # type: Text
dst_fs, # type: Union[Text, FS]
dst_path, # type: Text
workers=0, # type: int
):
# type: (...) -> None
"""Move a directory from one filesystem to another.
Arguments:
src_fs (FS or str): Source filesystem (... | python | {
"resource": ""
} |
q228994 | recursepath | train | def recursepath(path, reverse=False):
# type: (Text, bool) -> List[Text]
"""Get intermediate paths from the root to the given path.
Arguments:
path (str): A PyFilesystem path
reverse (bool): Reverses the order of the paths
(default `False`).
Returns:
list: A list of... | python | {
"resource": ""
} |
q228995 | join | train | def join(*paths):
# type: (*Text) -> Text
"""Join any number of paths together.
Arguments:
*paths (str): Paths to join, given as positional arguments.
Returns:
str: The joined path.
Example:
>>> join('foo', 'bar', 'baz')
'foo/bar/baz'
>>> join('foo/bar', '.... | python | {
"resource": ""
} |
q228996 | combine | train | def combine(path1, path2):
# type: (Text, Text) -> Text
"""Join two paths together.
This is faster than :func:`~fs.path.join`, but only works when the
second path is relative, and there are no back references in either
path.
Arguments:
path1 (str): A PyFilesytem path.
path2 (st... | python | {
"resource": ""
} |
q228997 | parts | train | def parts(path):
# type: (Text) -> List[Text]
"""Split a path in to its component parts.
Arguments:
path (str): Path to split in to parts.
Returns:
list: List of components
Example:
>>> parts('/foo/bar/baz')
['/', 'foo', 'bar', 'baz']
"""
_path = normpath(... | python | {
"resource": ""
} |
q228998 | splitext | train | def splitext(path):
# type: (Text) -> Tuple[Text, Text]
"""Split the extension from the path.
Arguments:
path (str): A path to split.
Returns:
(str, str): A tuple containing the path and the extension.
Example:
>>> splitext('baz.txt')
('baz', '.txt')
>>> sp... | python | {
"resource": ""
} |
q228999 | isbase | train | def isbase(path1, path2):
# type: (Text, Text) -> bool
"""Check if ``path1`` is a base of ``path2``.
Arguments:
path1 (str): A PyFilesytem path.
path2 (str): A PyFilesytem path.
Returns:
bool: `True` if ``path2`` starts with ``path1``
Example:
>>> isbase('foo/bar',... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.