Merge pull request 'fix_checked_file' (#43) from fix_checked_file into main
ogrepository/pipeline/head This commit looks good
Details
ogrepository/pipeline/head This commit looks good
Details
Reviewed-on: #43pull/44/head
commit
49f72febf8
|
@ -1,5 +1,13 @@
|
|||
# Changelog
|
||||
|
||||
## [0.10.2] - 2025-09-01
|
||||
|
||||
## Fixed
|
||||
|
||||
- Corregida la logica en el endpoint create torrent sum
|
||||
- Mejoras en los mensajes de logs
|
||||
- Mejoras en la validación de los archivos info e info.checked
|
||||
|
||||
## [0.10.1] - 2025-08-25
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -1350,14 +1350,28 @@ def create_torrent_sum():
|
|||
}), 400
|
||||
|
||||
# Chequeamos que el archivo checked.info existe y si no existe devolvemos error y salimos del endpoint:
|
||||
if not check_file_exists(f"{repo_path}{image_name}.info.checked"):
|
||||
|
||||
missed_files = []
|
||||
if not check_file_exists(f"{repo_path}{image_name}.info.checked") and not check_file_exists(f"{repo_path}{image_name}.info"):
|
||||
if not check_file_exists(f"{repo_path}{image_name}.info.checked"):
|
||||
missed_files.append(f"{repo_path}{image_name}.info.checked")
|
||||
if not check_file_exists(f"{repo_path}{image_name}.info"):
|
||||
missed_files.append(f"{repo_path}{image_name}.info")
|
||||
journal.send("Checked info file not found", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
journal.send(f"{{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint create_torrent_sum', 'desc':'Warning: Checked info file for image: {image_name}.info.checked not found'}}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api")
|
||||
journal.send(f"{{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint create_torrent_sum nico', 'desc':'Warning: Checked info file for image: {missed_files} not found'}}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api")
|
||||
return jsonify({
|
||||
"success": False,
|
||||
"details": f"{repo_path}{image_name}.info.checked file not found"
|
||||
"details": f"{missed_files} not found"
|
||||
}), 400
|
||||
|
||||
else:
|
||||
if check_file_exists(f"{repo_path}{image_name}.info.checked"):
|
||||
journal.send(f"Checked info file found for image: {image_name}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
journal.send(f"{{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run endpoint create_torrent_sum nico', 'desc':'Checked info file for image: {image_name} found'}}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api")
|
||||
if check_file_exists(f"{repo_path}{image_name}.info"):
|
||||
journal.send(f"Info file found for image: {image_name}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
journal.send(f"{{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run endpoint create_torrent_sum nico', 'desc':'Info file for image: {image_name} found'}}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api")
|
||||
|
||||
# Construimos la ruta de la imagen (relativa a "repo_path"):
|
||||
image_file_path = image_name
|
||||
|
||||
|
|
|
@ -185,13 +185,13 @@ def main():
|
|||
file_path = build_file_path()
|
||||
|
||||
# Si no existe el archivo de imagen o el .info, imprimimos un mensaje de error y salimos del script:
|
||||
if not os.path.exists(file_path) or not os.path.exists(f"{file_path}.info.checked"):
|
||||
if not os.path.exists(file_path) or not (os.path.exists(f"{file_path}.info.checked") or os.path.exists(f"{file_path}.info")):
|
||||
if not os.path.exists(file_path):
|
||||
journal.send(f"createTorrentSum.py: Image file '{file_path}' not found", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
print(f"Image file '{file_path}' doesn't exist")
|
||||
if not os.path.exists(f"{file_path}.info.checked"):
|
||||
journal.send(f"createTorrentSum.py: Info file '{file_path}.info.checked' not found", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
print(f"Info file '{file_path}.info.checked' doesn't exist")
|
||||
if not os.path.exists(f"{file_path}.info.checked") and not os.path.exists(f"{file_path}.info"):
|
||||
journal.send(f"createTorrentSum.py: Neither '{file_path}.info.checked' nor '{file_path}.info' found", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
print(f"Neither info file '{file_path}.info.checked' nor '{file_path}.info' exists")
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
|
@ -262,7 +262,8 @@ def main():
|
|||
# Actualizamos la información del repositorio, ejecutando el script "updateRepoInfo.py":
|
||||
journal.send("createTorrentSum.py: Updating repository info...", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
print("Updating Repository Info...")
|
||||
update_repo_info()
|
||||
if os.path.exists(f"{file_path}.info"):
|
||||
update_repo_info()
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -67,33 +67,50 @@ def check_files():
|
|||
continue
|
||||
# Comprobamos si existe un archivo ".info" asociado a la imagen actual:
|
||||
info_file = f"{img_path}.info"
|
||||
if os.path.exists(info_file):
|
||||
# Si la fecha de modificación del archivo ".info" es anterior a la de la imagen, lo eliminamos (porque estará desactualizado):
|
||||
if os.path.getmtime(info_file) < os.path.getmtime(img_path):
|
||||
os.remove(info_file)
|
||||
print(f"Warning: Deleted outdated file {info_file}")
|
||||
try:
|
||||
if os.path.exists(info_file):
|
||||
# Si la fecha de modificación del archivo ".info" es anterior a la de la imagen, lo eliminamos (porque estará desactualizado):
|
||||
if os.path.getmtime(info_file) < os.path.getmtime(img_path):
|
||||
os.remove(info_file)
|
||||
print(f"Warning: Deleted outdated file {info_file}")
|
||||
# En caso contrario, almacenamos el contenido del archivo ".info" (del tipo "PARTCLONE:LZOP:EXTFS:8500000:Ubuntu_20") en la variable "data":
|
||||
else:
|
||||
with open(info_file, 'r') as file:
|
||||
info_data = file.read()
|
||||
# Almacenamos el contenido de los archivos ".size", ".sum" y ".full.sum":
|
||||
with open(f"{img_path}.size", 'r') as file:
|
||||
size = file.read().strip('\n')
|
||||
with open(f"{img_path}.sum", 'r') as file:
|
||||
_sum = file.read().strip('\n')
|
||||
with open(f"{img_path}.full.sum", 'r') as file:
|
||||
fullsum = file.read().strip('\n')
|
||||
# Llamamos a la función "add_to_json", para que inserte la información de la imagen en el archivo json
|
||||
# (pasándole el nombre de la imagen, la extensión, y los datos extraídos del archivo ".info"):
|
||||
img_name = os.path.relpath(img_path, repo_path)
|
||||
add_to_json(os.path.splitext(img_name)[0], os.path.splitext(img_name)[1][1:], info_data, size, _sum, fullsum)
|
||||
else:
|
||||
with open(info_file, 'r') as file:
|
||||
info_data = file.read()
|
||||
# Almacenamos el contenido de los archivos ".size", ".sum" y ".full.sum":
|
||||
with open(f"{img_path}.size", 'r') as file:
|
||||
size = file.read().strip('\n')
|
||||
with open(f"{img_path}.sum", 'r') as file:
|
||||
sum = file.read().strip('\n')
|
||||
with open(f"{img_path}.full.sum", 'r') as file:
|
||||
fullsum = file.read().strip('\n')
|
||||
|
||||
# Renombramos el archivo ".info" a ".info.checked", para que ya no se añada la información que contiene
|
||||
# (originalmente se eliminaba el archivo, pero creo que es mejor mantenerlo):
|
||||
os.rename(info_file, f"{info_file}.checked")
|
||||
# Renombramos el archivo ".info" a ".info.checked", para que ya no se añada la información que contiene
|
||||
# (originalmente se eliminaba el archivo, pero creo que es mejor mantenerlo):
|
||||
os.rename(info_file, f"{info_file}.checked")
|
||||
|
||||
# Llamamos a la función "add_to_json", para que inserte la información de la imagen en el archivo json
|
||||
# (pasándole el nombre de la imagen, la extensión, y los datos extraídos del archivo ".info"):
|
||||
img_name = os.path.relpath(img_path, repo_path)
|
||||
add_to_json(os.path.splitext(img_name)[0], os.path.splitext(img_name)[1][1:], info_data, size, sum, fullsum)
|
||||
|
||||
|
||||
def add_to_json(image_name, image_type, data, size, _sum, fullsum):
|
||||
except (IOError, OSError, PermissionError) as e:
|
||||
# Si hay algún error leyendo los archivos, registramos el error y continuamos con la siguiente imagen
|
||||
journal.send(f"updateRepoInfo.py: Error processing files for {img_path}: {str(e)}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
print(f"Warning: Could not process files for {item}: {str(e)}")
|
||||
continue
|
||||
except ValueError as e:
|
||||
# Si hay algún error con el formato de los datos en los archivos
|
||||
journal.send(f"updateRepoInfo.py: Data format error for {img_path}: {str(e)}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
print(f"Warning: Data format error for {item}: {str(e)}")
|
||||
continue
|
||||
except Exception as e:
|
||||
# Para cualquier otra excepción inesperada
|
||||
journal.send(f"updateRepoInfo.py: Unexpected error processing {img_path}: {str(e)}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
print(f"Error: Unexpected error processing {item}: {str(e)}")
|
||||
continue
|
||||
|
||||
def add_to_json(image_name, image_type, data, size, sum, fullsum):
|
||||
""" Esta función añade al archivo "repoinfo.json" la información de las imágenes que aun no ha sido introducida en él (imágenes nuevas, básicamente).
|
||||
"""
|
||||
# Almacenamos el contenido de la variable "data" (del tipo "PARTCLONE:LZOP:EXTFS:8500000:Ubuntu_20") en variables separadas:
|
||||
|
@ -109,7 +126,7 @@ def add_to_json(image_name, image_type, data, size, _sum, fullsum):
|
|||
"filesystem": fstype.upper(),
|
||||
"datasize": int(datasize) * 1024, # Convertimos el valor a bytes (desde KB)
|
||||
"size": int(size),
|
||||
"sum": _sum,
|
||||
"sum": sum,
|
||||
"fullsum": fullsum
|
||||
}
|
||||
# Almacenamos el contenido del archivo "repoinfo.json" en la variable "info_data"
|
||||
|
|
Loading…
Reference in New Issue