autorino.download package

Submodules

autorino.download.dwl_cls module

class autorino.download.dwl_cls.DownloadGnss(access: dict, **kwargs)[source]

Bases: StepGnss

A class to handle the downloading of GNSS data.

Inherits from

arocmn.StepGnss

__init__(access: dict, **kwargs)[source]

Initialize the DownloadGnss object.

Parameters:
  • access (dict) – A dictionary containing access information such as protocol, hostname, login, and password.

  • **kwargs (keyword arguments) –

    Additional keyword arguments passed to the parent StepGnss class. Common parameters include: - out_dir : str - The output directory where the downloaded files will be stored. - tmp_dir : str - The temporary directory used during the download process. - log_dir : str - The directory where log files will be stored. - inp_dir : str - The input directory path (remote directory). - inp_file_regex : str - Regular expression pattern for input files. - epoch_range : EpochRange - The range of epochs for which data will be downloaded. - site : dict - The site information. Default is None. - session : dict - The session information. Default is None. - options : dict - Additional options for the download process. Default is None. - metadata : str or list - The metadata to be included in the converted RINEX files.

    Possible inputs are:
    • list of string (sitelog file paths),

    • single string (single sitelog file path)

    • single string (directory containing the sitelogs)

    • list of MetaData objects

    • single MetaData object.

    Defaults to None.

ask_remote_raw()[source]

Retrieve the list of remote files from the server.

This method guesses the remote directories and then lists the files in those directories based on the protocol specified in the access information.

Returns:

A list of remote file paths.

Return type:

list

clear_cache_remot()[source]

Clear the cache of remote file listings.

This method clears all cached remote file listings stored in memory. Use this when you need to force a fresh listing of remote files.

download(verbose=False, force=False, reverse_order=False, remote_find_method='ask', invalidate_small_local_files=True, timeout=60, max_try=4, sleep_time=5, ping_max_try=4, ping_timeout=20, ping_disable=False, clear_cache=False, check_out_bis=False)[source]

Frontend method to download files from a GNSS receiver

Parameters:
  • verbose (bool, optional) – If True, prints detailed information during the download process. Default is False.

  • force (bool, optional) – If True, forces the download even if the files already exist locally. Default is False.

  • reverse_order (bool, optional) – If True, processes the files in reverse order (anti-chronological, newer first). Default is False.

  • remote_find_method (str, optional) – Method to find remote files. Can be ‘ask’ to list files from the server (for FTP only) or ‘guess’ to guess file paths. Default is ‘ask’.

  • invalidate_small_local_files (bool, optional) – If True, invalidates small local files to ensure they are re-downloaded. Default is True.

  • timeout (int, optional) – Timeout in seconds for the download operations. Default is 60.

  • max_try (int, optional) – Maximum number of retry attempts for the download operations. Default is 4.

  • sleep_time (int, optional) – Sleep time in seconds between retry attempts. Default is 5.

  • ping_max_try (int, optional) – Maximum number of retry attempts for pinging the remote server. Default is 4.

  • ping_timeout (int, optional) – Timeout in seconds for pinging the remote server. Default is 20.

  • ping_disable (bool, optional) – If True, skips the pinging of the remote server. Default is False.

  • clear_cache (bool, optional) – If True, clears the remote listing cache before starting the download. Default is False.

  • check_out_bis (bool, optional) – If True, performs an additional check on the second output destination (out_bis) if it is defined, and skip the download if the file is already there and valid. Default is False.

Return type:

None

fetch_remote_files(force=False, timeout=60, max_try=4, sleep_time=5)[source]

Download locally the files which have been identified by remote file discovery methods.

Parameters:
  • force (bool, optional) – If True, forces download even if the file already exists locally. Default is False.

  • timeout (int, optional) – Timeout in seconds for each download operation. Default is 60.

  • max_try (int, optional) – Maximum number of retry attempts for each download operation. Default is 4.

  • sleep_time (int, optional) – Sleep time in seconds between retry attempts. Default is 5.

Returns:

A list of file paths for successfully downloaded files. Empty list if no files were successfully downloaded.

Return type:

list of str

get_cache_remot(remote_dir)[source]

Get cached remote file listing for a given directory.

Parameters:

remote_dir (str) – The remote directory path.

Returns:

The cached file listing if available, None otherwise.

Return type:

list or None

guess_remot_raw()[source]

Guess the paths and name of the remote files based on the Session and EpochRange attributes of the DownloadGnss

see also method guess_local_raw()

guess_remote_dirs()[source]

this method is specific for ask_remote_raw guessing the directories is different from guessing the files: * no hostname * no filename (obviously)

property inp_basename
property inp_dirname
mono_fetch(irow, force=False, timeout=60, max_try=4, sleep_time=5)[source]

Download a single remote file and store it locally.

This method downloads a single remote file identified by its row index in the download table. It performs validation checks, creates necessary directories, downloads the file (via HTTP or FTP), verifies file size, and stores the result in the download table.

Parameters:
  • irow (int) – The row index in the download table (self.table) identifying the file to download.

  • force (bool, optional) – If True, forces download even if the file already exists locally. Default is False.

  • timeout (int, optional) – Timeout in seconds for the download operation. Default is 60.

  • max_try (int, optional) – Maximum number of retry attempts for the download operation. Default is 4.

  • sleep_time (int, optional) – Sleep time in seconds between retry attempts. Default is 5.

Returns:

The local file path if the download was successful, None otherwise. On success, the file is moved from the temporary directory to the output directory and the row in the download table is updated with ok_out=True and fpath_out set to the downloaded file path.

Return type:

str or None

ping_remote(ping_max_try=4, ping_timeout=20)[source]

Ping the remote server to verify it is reachable before attempting downloads.

This method attempts to ping the remote hostname specified in the access dictionary. If the initial ping fails, it will retry up to the maximum number of attempts. The method sets the exit_code attribute to 7 if the server is unreachable after all retry attempts.

Parameters:
  • ping_max_try (int, optional) – Maximum number of ping attempts before giving up. Default is 4.

  • ping_timeout (int, optional) – Timeout in seconds for each ping attempt. Default is 20.

Returns:

The round-trip time in seconds if the ping succeeds (float), False if the ping fails after all attempts, or None if no response was received. When successful, the value represents the latency to the remote server.

Return type:

float or bool or None

set_cache_remot(remote_dir, file_list)[source]

Store a remote file listing in the cache.

Parameters:
  • remote_dir (str) – The remote directory path.

  • file_list (list) – The list of files to cache.

set_ftp_obj(timeout=15, max_try=4, sleep_time=5)[source]

Initialize and configure an FTP object for remote file transfers.

Parameters:
  • timeout (int, optional) – Timeout in seconds for FTP connection operations. Default is 15.

  • max_try (int, optional) – Maximum number of retry attempts for FTP operations. Default is 4.

  • sleep_time (int, optional) – Sleep time in seconds between retry attempts. Default is 5.

Returns:

The FTP object is stored in the instance attribute self.ftp_obj.

Return type:

None

autorino.download.dwl_fcts module

Created on Mon Mar 27 09:16:34 2023

@author: psakic

exception autorino.download.dwl_fcts.AutorinoDownloadError[source]

Bases: AutorinoError

exception autorino.download.dwl_fcts.AutorinoError[source]

Bases: Exception

class autorino.download.dwl_fcts.TqdmToLogger(logger_inp, level=None)[source]

Bases: StringIO

Output stream for TQDM which will output to logger module instead of the StdOut.

buf = ''
flush()[source]

Flush write buffers, if applicable.

This is not implemented for read-only and non-blocking streams.

level = None
logger = None
write(buf)[source]

Write string to file.

Returns the number of characters written, which is always equal to the length of the string.

autorino.download.dwl_fcts.check_file_size(file_path, min_size=1000)[source]

Check the size of a file and log a warning if it is too small to be useful.

Parameters:
  • file_path (str) – The path to the file to check.

  • min_size (int, optional) – The minimum file size in bytes. Default is 1000 bytes.

Returns:

  • ok_size (bool) – True if the file size is acceptable, otherwise False.

  • file_size (int) – The size of the file in bytes

autorino.download.dwl_fcts.download_ftp(url, output_dir, username=None, password=None, timeout=30, max_try=4, sleep_time=5, ftp_obj_inp=None)[source]

Download a file from an FTP server with retry logic and progress bar.

Parameters:
  • url (str) – The URL of the file to download.

  • output_dir (str) – The directory where the downloaded file will be saved.

  • username (str) – The username for FTP login. Overrided by the ftp_obj_inp parameter.

  • password (str) – The password for FTP login. Overrided by the ftp_obj_inp parameter.

  • timeout (int, optional) – The timeout for FTP connection in seconds. Default is 15 seconds.

  • max_try (int, optional) – The maximum number of retry attempts in case of failure. Default is 3.

  • sleep_time (int, optional) – The sleep time between retry attempts in seconds. Default is 5 seconds.

  • ftp_obj_inp (ftplib.FTP, optional) – An existing FTP object to use for the connection. Overrides the username and password parameters. Default is None.

Returns:

The path to the downloaded file, or an empty string if the download failed. If something goes wrong, the function will raise an AutorinoDownloadError (no empty string or None).

Return type:

str

Raises:

AutorinoDownloadError – If the download fails after the maximum number of retry attempts.

autorino.download.dwl_fcts.download_http(url, output_dir, timeout=120, max_try=4, sleep_time=5)[source]

Download a file from an HTTP server with retry logic and progress bar.

Parameters:
  • url (str) – The URL of the file to download.

  • output_dir (str) – The directory where the downloaded file will be saved.

  • timeout (int, optional) – The timeout for the HTTP connection in seconds. Default is 120 seconds.

  • max_try (int, optional) – The maximum number of retry attempts in case of failure. Default is 4.

  • sleep_time (int, optional) – The sleep time between retry attempts in seconds. Default is 5 seconds.

Returns:

The path to the downloaded file, or an empty string if the download failed.

Return type:

str

Raises:

AutorinoDownloadError – If the download fails after the maximum number of retry attempts.

autorino.download.dwl_fcts.ftp_create_obj(hostname_inp, username=None, password=None, timeout=15, max_try=3, sleep_time=5)[source]

Create an FTP object, and retry in case of a timeout.

Parameters:
  • hostname_inp (str) – The hostname of the FTP server.

  • username (str, optional) – The username for FTP login. Default is None.

  • password (str, optional) – The password for FTP login. Default is None.

  • timeout (int, optional) – The timeout for FTP connection in seconds. Default is 15 seconds.

  • max_try (int, optional) – The maximum number of retry attempts in case of failure. Default is 3.

  • sleep_time (int, optional) – The sleep time between retry attempts in seconds. Default is 5 seconds.

Returns:

The FTP object if the connection is successful, otherwise None.

Return type:

ftplib.FTP or None

Raises:

TimeoutError – If the connection fails after the maximum number of retry attempts.

autorino.download.dwl_fcts.join_url(protocol_inp, hostname_inp, dir_inp, fname_inp)[source]

a wrapper to classical join to format correctly the URL

autorino.download.dwl_fcts.list_remote_ftp(hostname, remote_dir, username=None, password=None, timeout=15, max_try=3, ftp_obj_inp=None)[source]

List files in a remote FTP directory.

Parameters:
  • hostname (str) – The hostname of the FTP server.

  • remote_dir (str) – The remote directory to list files from.

  • username (str, optional) – The username for FTP login. Default is None.

  • password (str, optional) – The password for FTP login. Default is None.

  • timeout (int, optional) – The timeout for FTP connection in seconds. Default is 15 seconds.

  • max_try (int, optional) – The maximum number of retry attempts in case of failure. Default is 3.

  • ftp_obj_inp (ftplib.FTP, optional) – An existing FTP object to use for the connection. Default is None.

Returns:

A list of file paths in the remote directory.

Return type:

list

Raises:

AutorinoDownloadError – If the FTP connection fails or if username/password are missing.

autorino.download.dwl_fcts.list_remote_http(hostname, remote_dir)[source]
autorino.download.dwl_fcts.ping(host, ping_timeout=20)[source]

Executes the ping command and captures the output.

This function sends a single ICMP echo request to the specified host and captures the round-trip time (RTT) from the output.

Parameters:
  • host (str) – The hostname or IP address to ping.

  • ping_timeout (int, optional) – The timeout for the ping command in seconds. Default is 10 seconds.

Returns:

The round-trip time (RTT) in seconds if the ping is successful, otherwise None.

Return type:

float or None

autorino.download.dwl_fcts.size_remote_file_http(url)[source]