setiastrosuitepro 1.6.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of setiastrosuitepro might be problematic. Click here for more details.
- setiastro/__init__.py +2 -0
- setiastro/data/SASP_data.fits +0 -0
- setiastro/data/catalogs/List_of_Galaxies_with_Distances_Gly.csv +488 -0
- setiastro/data/catalogs/astrobin_filters.csv +890 -0
- setiastro/data/catalogs/astrobin_filters_page1_local.csv +51 -0
- setiastro/data/catalogs/cali2.csv +63 -0
- setiastro/data/catalogs/cali2color.csv +65 -0
- setiastro/data/catalogs/celestial_catalog - original.csv +16471 -0
- setiastro/data/catalogs/celestial_catalog.csv +24031 -0
- setiastro/data/catalogs/detected_stars.csv +24784 -0
- setiastro/data/catalogs/fits_header_data.csv +46 -0
- setiastro/data/catalogs/test.csv +8 -0
- setiastro/data/catalogs/updated_celestial_catalog.csv +16471 -0
- setiastro/images/Astro_Spikes.png +0 -0
- setiastro/images/Background_startup.jpg +0 -0
- setiastro/images/HRDiagram.png +0 -0
- setiastro/images/LExtract.png +0 -0
- setiastro/images/LInsert.png +0 -0
- setiastro/images/Oxygenation-atm-2.svg.png +0 -0
- setiastro/images/RGB080604.png +0 -0
- setiastro/images/abeicon.png +0 -0
- setiastro/images/aberration.png +0 -0
- setiastro/images/acv_icon.png +0 -0
- setiastro/images/andromedatry.png +0 -0
- setiastro/images/andromedatry_satellited.png +0 -0
- setiastro/images/annotated.png +0 -0
- setiastro/images/aperture.png +0 -0
- setiastro/images/astrosuite.ico +0 -0
- setiastro/images/astrosuite.png +0 -0
- setiastro/images/astrosuitepro.icns +0 -0
- setiastro/images/astrosuitepro.ico +0 -0
- setiastro/images/astrosuitepro.png +0 -0
- setiastro/images/background.png +0 -0
- setiastro/images/background2.png +0 -0
- setiastro/images/benchmark.png +0 -0
- setiastro/images/big_moon_stabilizer_timeline.png +0 -0
- setiastro/images/big_moon_stabilizer_timeline_clean.png +0 -0
- setiastro/images/blaster.png +0 -0
- setiastro/images/blink.png +0 -0
- setiastro/images/clahe.png +0 -0
- setiastro/images/collage.png +0 -0
- setiastro/images/colorwheel.png +0 -0
- setiastro/images/contsub.png +0 -0
- setiastro/images/convo.png +0 -0
- setiastro/images/copyslot.png +0 -0
- setiastro/images/cosmic.png +0 -0
- setiastro/images/cosmicsat.png +0 -0
- setiastro/images/crop1.png +0 -0
- setiastro/images/cropicon.png +0 -0
- setiastro/images/curves.png +0 -0
- setiastro/images/cvs.png +0 -0
- setiastro/images/debayer.png +0 -0
- setiastro/images/denoise_cnn_custom.png +0 -0
- setiastro/images/denoise_cnn_graph.png +0 -0
- setiastro/images/disk.png +0 -0
- setiastro/images/dse.png +0 -0
- setiastro/images/exoicon.png +0 -0
- setiastro/images/eye.png +0 -0
- setiastro/images/first_quarter.png +0 -0
- setiastro/images/fliphorizontal.png +0 -0
- setiastro/images/flipvertical.png +0 -0
- setiastro/images/font.png +0 -0
- setiastro/images/freqsep.png +0 -0
- setiastro/images/full_moon.png +0 -0
- setiastro/images/functionbundle.png +0 -0
- setiastro/images/graxpert.png +0 -0
- setiastro/images/green.png +0 -0
- setiastro/images/gridicon.png +0 -0
- setiastro/images/halo.png +0 -0
- setiastro/images/hdr.png +0 -0
- setiastro/images/histogram.png +0 -0
- setiastro/images/hubble.png +0 -0
- setiastro/images/imagecombine.png +0 -0
- setiastro/images/invert.png +0 -0
- setiastro/images/isophote.png +0 -0
- setiastro/images/isophote_demo_figure.png +0 -0
- setiastro/images/isophote_demo_image.png +0 -0
- setiastro/images/isophote_demo_model.png +0 -0
- setiastro/images/isophote_demo_residual.png +0 -0
- setiastro/images/jwstpupil.png +0 -0
- setiastro/images/last_quarter.png +0 -0
- setiastro/images/linearfit.png +0 -0
- setiastro/images/livestacking.png +0 -0
- setiastro/images/mask.png +0 -0
- setiastro/images/maskapply.png +0 -0
- setiastro/images/maskcreate.png +0 -0
- setiastro/images/maskremove.png +0 -0
- setiastro/images/morpho.png +0 -0
- setiastro/images/mosaic.png +0 -0
- setiastro/images/multiscale_decomp.png +0 -0
- setiastro/images/nbtorgb.png +0 -0
- setiastro/images/neutral.png +0 -0
- setiastro/images/new_moon.png +0 -0
- setiastro/images/nuke.png +0 -0
- setiastro/images/openfile.png +0 -0
- setiastro/images/pedestal.png +0 -0
- setiastro/images/pen.png +0 -0
- setiastro/images/pixelmath.png +0 -0
- setiastro/images/platesolve.png +0 -0
- setiastro/images/ppp.png +0 -0
- setiastro/images/pro.png +0 -0
- setiastro/images/project.png +0 -0
- setiastro/images/psf.png +0 -0
- setiastro/images/redo.png +0 -0
- setiastro/images/redoicon.png +0 -0
- setiastro/images/rescale.png +0 -0
- setiastro/images/rgbalign.png +0 -0
- setiastro/images/rgbcombo.png +0 -0
- setiastro/images/rgbextract.png +0 -0
- setiastro/images/rotate180.png +0 -0
- setiastro/images/rotatearbitrary.png +0 -0
- setiastro/images/rotateclockwise.png +0 -0
- setiastro/images/rotatecounterclockwise.png +0 -0
- setiastro/images/satellite.png +0 -0
- setiastro/images/script.png +0 -0
- setiastro/images/selectivecolor.png +0 -0
- setiastro/images/simbad.png +0 -0
- setiastro/images/slot0.png +0 -0
- setiastro/images/slot1.png +0 -0
- setiastro/images/slot2.png +0 -0
- setiastro/images/slot3.png +0 -0
- setiastro/images/slot4.png +0 -0
- setiastro/images/slot5.png +0 -0
- setiastro/images/slot6.png +0 -0
- setiastro/images/slot7.png +0 -0
- setiastro/images/slot8.png +0 -0
- setiastro/images/slot9.png +0 -0
- setiastro/images/spcc.png +0 -0
- setiastro/images/spin_precession_vs_lunar_distance.png +0 -0
- setiastro/images/spinner.gif +0 -0
- setiastro/images/stacking.png +0 -0
- setiastro/images/staradd.png +0 -0
- setiastro/images/staralign.png +0 -0
- setiastro/images/starnet.png +0 -0
- setiastro/images/starregistration.png +0 -0
- setiastro/images/starspike.png +0 -0
- setiastro/images/starstretch.png +0 -0
- setiastro/images/statstretch.png +0 -0
- setiastro/images/supernova.png +0 -0
- setiastro/images/uhs.png +0 -0
- setiastro/images/undoicon.png +0 -0
- setiastro/images/upscale.png +0 -0
- setiastro/images/viewbundle.png +0 -0
- setiastro/images/waning_crescent_1.png +0 -0
- setiastro/images/waning_crescent_2.png +0 -0
- setiastro/images/waning_crescent_3.png +0 -0
- setiastro/images/waning_crescent_4.png +0 -0
- setiastro/images/waning_crescent_5.png +0 -0
- setiastro/images/waning_gibbous_1.png +0 -0
- setiastro/images/waning_gibbous_2.png +0 -0
- setiastro/images/waning_gibbous_3.png +0 -0
- setiastro/images/waning_gibbous_4.png +0 -0
- setiastro/images/waning_gibbous_5.png +0 -0
- setiastro/images/waxing_crescent_1.png +0 -0
- setiastro/images/waxing_crescent_2.png +0 -0
- setiastro/images/waxing_crescent_3.png +0 -0
- setiastro/images/waxing_crescent_4.png +0 -0
- setiastro/images/waxing_crescent_5.png +0 -0
- setiastro/images/waxing_gibbous_1.png +0 -0
- setiastro/images/waxing_gibbous_2.png +0 -0
- setiastro/images/waxing_gibbous_3.png +0 -0
- setiastro/images/waxing_gibbous_4.png +0 -0
- setiastro/images/waxing_gibbous_5.png +0 -0
- setiastro/images/whitebalance.png +0 -0
- setiastro/images/wimi_icon_256x256.png +0 -0
- setiastro/images/wimilogo.png +0 -0
- setiastro/images/wims.png +0 -0
- setiastro/images/wrench_icon.png +0 -0
- setiastro/images/xisfliberator.png +0 -0
- setiastro/qml/ResourceMonitor.qml +128 -0
- setiastro/saspro/__init__.py +20 -0
- setiastro/saspro/__main__.py +964 -0
- setiastro/saspro/_generated/__init__.py +7 -0
- setiastro/saspro/_generated/build_info.py +3 -0
- setiastro/saspro/abe.py +1379 -0
- setiastro/saspro/abe_preset.py +196 -0
- setiastro/saspro/aberration_ai.py +910 -0
- setiastro/saspro/aberration_ai_preset.py +224 -0
- setiastro/saspro/accel_installer.py +218 -0
- setiastro/saspro/accel_workers.py +30 -0
- setiastro/saspro/acv_exporter.py +379 -0
- setiastro/saspro/add_stars.py +627 -0
- setiastro/saspro/astrobin_exporter.py +1010 -0
- setiastro/saspro/astrospike.py +153 -0
- setiastro/saspro/astrospike_python.py +1841 -0
- setiastro/saspro/autostretch.py +198 -0
- setiastro/saspro/backgroundneutral.py +639 -0
- setiastro/saspro/batch_convert.py +328 -0
- setiastro/saspro/batch_renamer.py +522 -0
- setiastro/saspro/blemish_blaster.py +494 -0
- setiastro/saspro/blink_comparator_pro.py +3149 -0
- setiastro/saspro/bundles.py +61 -0
- setiastro/saspro/bundles_dock.py +114 -0
- setiastro/saspro/cheat_sheet.py +213 -0
- setiastro/saspro/clahe.py +371 -0
- setiastro/saspro/comet_stacking.py +1442 -0
- setiastro/saspro/common_tr.py +107 -0
- setiastro/saspro/config.py +38 -0
- setiastro/saspro/config_bootstrap.py +40 -0
- setiastro/saspro/config_manager.py +316 -0
- setiastro/saspro/continuum_subtract.py +1620 -0
- setiastro/saspro/convo.py +1403 -0
- setiastro/saspro/convo_preset.py +414 -0
- setiastro/saspro/copyastro.py +190 -0
- setiastro/saspro/cosmicclarity.py +1593 -0
- setiastro/saspro/cosmicclarity_preset.py +407 -0
- setiastro/saspro/crop_dialog_pro.py +1005 -0
- setiastro/saspro/crop_preset.py +189 -0
- setiastro/saspro/curve_editor_pro.py +2608 -0
- setiastro/saspro/curves_preset.py +375 -0
- setiastro/saspro/debayer.py +673 -0
- setiastro/saspro/debug_utils.py +29 -0
- setiastro/saspro/dnd_mime.py +35 -0
- setiastro/saspro/doc_manager.py +2727 -0
- setiastro/saspro/exoplanet_detector.py +2258 -0
- setiastro/saspro/file_utils.py +284 -0
- setiastro/saspro/fitsmodifier.py +748 -0
- setiastro/saspro/fix_bom.py +32 -0
- setiastro/saspro/free_torch_memory.py +48 -0
- setiastro/saspro/frequency_separation.py +1352 -0
- setiastro/saspro/function_bundle.py +1596 -0
- setiastro/saspro/generate_translations.py +3092 -0
- setiastro/saspro/ghs_dialog_pro.py +728 -0
- setiastro/saspro/ghs_preset.py +284 -0
- setiastro/saspro/graxpert.py +638 -0
- setiastro/saspro/graxpert_preset.py +287 -0
- setiastro/saspro/gui/__init__.py +0 -0
- setiastro/saspro/gui/main_window.py +8928 -0
- setiastro/saspro/gui/mixins/__init__.py +33 -0
- setiastro/saspro/gui/mixins/dock_mixin.py +375 -0
- setiastro/saspro/gui/mixins/file_mixin.py +450 -0
- setiastro/saspro/gui/mixins/geometry_mixin.py +503 -0
- setiastro/saspro/gui/mixins/header_mixin.py +441 -0
- setiastro/saspro/gui/mixins/mask_mixin.py +421 -0
- setiastro/saspro/gui/mixins/menu_mixin.py +391 -0
- setiastro/saspro/gui/mixins/theme_mixin.py +367 -0
- setiastro/saspro/gui/mixins/toolbar_mixin.py +1824 -0
- setiastro/saspro/gui/mixins/update_mixin.py +323 -0
- setiastro/saspro/gui/mixins/view_mixin.py +477 -0
- setiastro/saspro/gui/statistics_dialog.py +47 -0
- setiastro/saspro/halobgon.py +492 -0
- setiastro/saspro/header_viewer.py +448 -0
- setiastro/saspro/headless_utils.py +88 -0
- setiastro/saspro/histogram.py +760 -0
- setiastro/saspro/history_explorer.py +941 -0
- setiastro/saspro/i18n.py +168 -0
- setiastro/saspro/image_combine.py +421 -0
- setiastro/saspro/image_peeker_pro.py +1608 -0
- setiastro/saspro/imageops/__init__.py +37 -0
- setiastro/saspro/imageops/mdi_snap.py +292 -0
- setiastro/saspro/imageops/scnr.py +36 -0
- setiastro/saspro/imageops/starbasedwhitebalance.py +210 -0
- setiastro/saspro/imageops/stretch.py +236 -0
- setiastro/saspro/isophote.py +1186 -0
- setiastro/saspro/layers.py +208 -0
- setiastro/saspro/layers_dock.py +714 -0
- setiastro/saspro/lazy_imports.py +193 -0
- setiastro/saspro/legacy/__init__.py +2 -0
- setiastro/saspro/legacy/image_manager.py +2360 -0
- setiastro/saspro/legacy/numba_utils.py +3676 -0
- setiastro/saspro/legacy/xisf.py +1213 -0
- setiastro/saspro/linear_fit.py +537 -0
- setiastro/saspro/live_stacking.py +1854 -0
- setiastro/saspro/log_bus.py +5 -0
- setiastro/saspro/logging_config.py +460 -0
- setiastro/saspro/luminancerecombine.py +510 -0
- setiastro/saspro/main_helpers.py +201 -0
- setiastro/saspro/mask_creation.py +1090 -0
- setiastro/saspro/masks_core.py +56 -0
- setiastro/saspro/mdi_widgets.py +353 -0
- setiastro/saspro/memory_utils.py +666 -0
- setiastro/saspro/metadata_patcher.py +75 -0
- setiastro/saspro/mfdeconv.py +3909 -0
- setiastro/saspro/mfdeconv_earlystop.py +71 -0
- setiastro/saspro/mfdeconvcudnn.py +3312 -0
- setiastro/saspro/mfdeconvsport.py +2459 -0
- setiastro/saspro/minorbodycatalog.py +567 -0
- setiastro/saspro/morphology.py +411 -0
- setiastro/saspro/multiscale_decomp.py +1751 -0
- setiastro/saspro/nbtorgb_stars.py +541 -0
- setiastro/saspro/numba_utils.py +3145 -0
- setiastro/saspro/numba_warmup.py +141 -0
- setiastro/saspro/ops/__init__.py +9 -0
- setiastro/saspro/ops/command_help_dialog.py +623 -0
- setiastro/saspro/ops/command_runner.py +217 -0
- setiastro/saspro/ops/commands.py +1594 -0
- setiastro/saspro/ops/script_editor.py +1105 -0
- setiastro/saspro/ops/scripts.py +1476 -0
- setiastro/saspro/ops/settings.py +637 -0
- setiastro/saspro/parallel_utils.py +554 -0
- setiastro/saspro/pedestal.py +121 -0
- setiastro/saspro/perfect_palette_picker.py +1105 -0
- setiastro/saspro/pipeline.py +110 -0
- setiastro/saspro/pixelmath.py +1604 -0
- setiastro/saspro/plate_solver.py +2480 -0
- setiastro/saspro/project_io.py +797 -0
- setiastro/saspro/psf_utils.py +136 -0
- setiastro/saspro/psf_viewer.py +631 -0
- setiastro/saspro/pyi_rthook_astroquery.py +95 -0
- setiastro/saspro/remove_green.py +331 -0
- setiastro/saspro/remove_stars.py +1599 -0
- setiastro/saspro/remove_stars_preset.py +446 -0
- setiastro/saspro/resources.py +570 -0
- setiastro/saspro/rgb_combination.py +208 -0
- setiastro/saspro/rgb_extract.py +19 -0
- setiastro/saspro/rgbalign.py +727 -0
- setiastro/saspro/runtime_imports.py +7 -0
- setiastro/saspro/runtime_torch.py +754 -0
- setiastro/saspro/save_options.py +73 -0
- setiastro/saspro/selective_color.py +1614 -0
- setiastro/saspro/sfcc.py +1530 -0
- setiastro/saspro/shortcuts.py +3125 -0
- setiastro/saspro/signature_insert.py +1106 -0
- setiastro/saspro/stacking_suite.py +19069 -0
- setiastro/saspro/star_alignment.py +7383 -0
- setiastro/saspro/star_alignment_preset.py +329 -0
- setiastro/saspro/star_metrics.py +49 -0
- setiastro/saspro/star_spikes.py +769 -0
- setiastro/saspro/star_stretch.py +542 -0
- setiastro/saspro/stat_stretch.py +554 -0
- setiastro/saspro/status_log_dock.py +78 -0
- setiastro/saspro/subwindow.py +3523 -0
- setiastro/saspro/supernovaasteroidhunter.py +1719 -0
- setiastro/saspro/swap_manager.py +134 -0
- setiastro/saspro/torch_backend.py +89 -0
- setiastro/saspro/torch_rejection.py +434 -0
- setiastro/saspro/translations/all_source_strings.json +4726 -0
- setiastro/saspro/translations/ar_translations.py +4096 -0
- setiastro/saspro/translations/de_translations.py +3728 -0
- setiastro/saspro/translations/es_translations.py +4169 -0
- setiastro/saspro/translations/fr_translations.py +4090 -0
- setiastro/saspro/translations/hi_translations.py +3803 -0
- setiastro/saspro/translations/integrate_translations.py +271 -0
- setiastro/saspro/translations/it_translations.py +4728 -0
- setiastro/saspro/translations/ja_translations.py +3834 -0
- setiastro/saspro/translations/pt_translations.py +3847 -0
- setiastro/saspro/translations/ru_translations.py +3082 -0
- setiastro/saspro/translations/saspro_ar.qm +0 -0
- setiastro/saspro/translations/saspro_ar.ts +16019 -0
- setiastro/saspro/translations/saspro_de.qm +0 -0
- setiastro/saspro/translations/saspro_de.ts +14548 -0
- setiastro/saspro/translations/saspro_es.qm +0 -0
- setiastro/saspro/translations/saspro_es.ts +16202 -0
- setiastro/saspro/translations/saspro_fr.qm +0 -0
- setiastro/saspro/translations/saspro_fr.ts +15870 -0
- setiastro/saspro/translations/saspro_hi.qm +0 -0
- setiastro/saspro/translations/saspro_hi.ts +14855 -0
- setiastro/saspro/translations/saspro_it.qm +0 -0
- setiastro/saspro/translations/saspro_it.ts +19046 -0
- setiastro/saspro/translations/saspro_ja.qm +0 -0
- setiastro/saspro/translations/saspro_ja.ts +14980 -0
- setiastro/saspro/translations/saspro_pt.qm +0 -0
- setiastro/saspro/translations/saspro_pt.ts +15024 -0
- setiastro/saspro/translations/saspro_ru.qm +0 -0
- setiastro/saspro/translations/saspro_ru.ts +11835 -0
- setiastro/saspro/translations/saspro_sw.qm +0 -0
- setiastro/saspro/translations/saspro_sw.ts +15237 -0
- setiastro/saspro/translations/saspro_uk.qm +0 -0
- setiastro/saspro/translations/saspro_uk.ts +15248 -0
- setiastro/saspro/translations/saspro_zh.qm +0 -0
- setiastro/saspro/translations/saspro_zh.ts +15289 -0
- setiastro/saspro/translations/sw_translations.py +3897 -0
- setiastro/saspro/translations/uk_translations.py +3929 -0
- setiastro/saspro/translations/zh_translations.py +3910 -0
- setiastro/saspro/versioning.py +77 -0
- setiastro/saspro/view_bundle.py +1558 -0
- setiastro/saspro/wavescale_hdr.py +648 -0
- setiastro/saspro/wavescale_hdr_preset.py +101 -0
- setiastro/saspro/wavescalede.py +683 -0
- setiastro/saspro/wavescalede_preset.py +230 -0
- setiastro/saspro/wcs_update.py +374 -0
- setiastro/saspro/whitebalance.py +540 -0
- setiastro/saspro/widgets/__init__.py +48 -0
- setiastro/saspro/widgets/common_utilities.py +306 -0
- setiastro/saspro/widgets/graphics_views.py +122 -0
- setiastro/saspro/widgets/image_utils.py +518 -0
- setiastro/saspro/widgets/minigame/game.js +991 -0
- setiastro/saspro/widgets/minigame/index.html +53 -0
- setiastro/saspro/widgets/minigame/style.css +241 -0
- setiastro/saspro/widgets/preview_dialogs.py +280 -0
- setiastro/saspro/widgets/resource_monitor.py +313 -0
- setiastro/saspro/widgets/spinboxes.py +290 -0
- setiastro/saspro/widgets/themed_buttons.py +13 -0
- setiastro/saspro/widgets/wavelet_utils.py +331 -0
- setiastro/saspro/wimi.py +7367 -0
- setiastro/saspro/wims.py +588 -0
- setiastro/saspro/window_shelf.py +185 -0
- setiastro/saspro/xisf.py +1213 -0
- setiastrosuitepro-1.6.7.dist-info/METADATA +279 -0
- setiastrosuitepro-1.6.7.dist-info/RECORD +394 -0
- setiastrosuitepro-1.6.7.dist-info/WHEEL +4 -0
- setiastrosuitepro-1.6.7.dist-info/entry_points.txt +6 -0
- setiastrosuitepro-1.6.7.dist-info/licenses/LICENSE +674 -0
- setiastrosuitepro-1.6.7.dist-info/licenses/license.txt +2580 -0
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
# pro/batch_renamer.py
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
import shutil
|
|
7
|
+
from typing import List
|
|
8
|
+
from collections import defaultdict
|
|
9
|
+
from datetime import datetime, timezone
|
|
10
|
+
|
|
11
|
+
from astropy.io import fits
|
|
12
|
+
|
|
13
|
+
from PyQt6.QtCore import Qt, QTimer
|
|
14
|
+
from PyQt6.QtGui import QFontMetrics
|
|
15
|
+
from PyQt6.QtWidgets import (
|
|
16
|
+
QDialog, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton, QGroupBox,
|
|
17
|
+
QSplitter, QWidget, QListWidget, QListWidgetItem,
|
|
18
|
+
QTableWidget, QTableWidgetItem, QHeaderView, QAbstractItemView,
|
|
19
|
+
QDialogButtonBox, QComboBox, QSpinBox, QCheckBox, QFileDialog, QListWidget, QMessageBox
|
|
20
|
+
)
|
|
21
|
+
from PyQt6.QtCore import QSettings
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class BatchRenamerDialog(QDialog):
|
|
25
|
+
r"""
|
|
26
|
+
Batch rename files using a template like:
|
|
27
|
+
LIGHT_{FILTER}_{EXPOSURE:.0f}s_{DATE-OBS:%Y%m%d}_{#03}.{ext}
|
|
28
|
+
|
|
29
|
+
Supports:
|
|
30
|
+
- Any FITS keyword in braces: {FILTER}, {EXPOSURE}, {OBJECT}, …
|
|
31
|
+
- Optional format spec: {EXPOSURE:.1f}, {DATE-OBS:%Y%m%d}
|
|
32
|
+
- Counter: {#} or {#03} (zero-padded width)
|
|
33
|
+
- Extension placeholder: {ext} (original extension, no dot)
|
|
34
|
+
- Filters with pipes, e.g. {OBJECT|re:(\w+)|upper}
|
|
35
|
+
"""
|
|
36
|
+
def __init__(self, parent=None):
|
|
37
|
+
super().__init__(parent)
|
|
38
|
+
self.setWindowTitle(self.tr("Batch Rename from FITS"))
|
|
39
|
+
self.settings = QSettings()
|
|
40
|
+
self.files: list[str] = []
|
|
41
|
+
self.headers: dict[str, fits.Header] = {}
|
|
42
|
+
self.union_keys: list[str] = []
|
|
43
|
+
|
|
44
|
+
# PyQt6-safe window flags
|
|
45
|
+
self.setWindowFlag(Qt.WindowType.WindowSystemMenuHint, True)
|
|
46
|
+
self.setWindowFlag(Qt.WindowType.WindowTitleHint, True)
|
|
47
|
+
self.setWindowFlag(Qt.WindowType.WindowMinMaxButtonsHint, True)
|
|
48
|
+
self.setWindowFlag(Qt.WindowType.WindowContextHelpButtonHint, False)
|
|
49
|
+
self.setWindowFlag(Qt.WindowType.Window, True)
|
|
50
|
+
self.setWindowModality(Qt.WindowModality.NonModal)
|
|
51
|
+
self.setModal(False)
|
|
52
|
+
self.setSizeGripEnabled(True)
|
|
53
|
+
|
|
54
|
+
self._build_ui()
|
|
55
|
+
self._load_settings()
|
|
56
|
+
|
|
57
|
+
# ---------- UI ----------
|
|
58
|
+
def _build_ui(self):
|
|
59
|
+
root = QVBoxLayout(self)
|
|
60
|
+
|
|
61
|
+
# Top: source and destination
|
|
62
|
+
io_row = QHBoxLayout()
|
|
63
|
+
self.src_edit = QLineEdit(self)
|
|
64
|
+
self.src_edit.setPlaceholderText(self.tr("Select a folder or add files…"))
|
|
65
|
+
btn_scan = QPushButton(self.tr("Scan Folder…"), self); btn_scan.clicked.connect(self._scan_folder)
|
|
66
|
+
btn_add = QPushButton(self.tr("Add Files…"), self); btn_add.clicked.connect(self._add_files)
|
|
67
|
+
btn_clear = QPushButton(self.tr("Clear Selections"), self); btn_clear.clicked.connect(self._clear_selection)
|
|
68
|
+
io_row.addWidget(QLabel(self.tr("Source:")))
|
|
69
|
+
io_row.addWidget(self.src_edit, 1)
|
|
70
|
+
io_row.addWidget(btn_scan)
|
|
71
|
+
io_row.addWidget(btn_add)
|
|
72
|
+
io_row.addWidget(btn_clear)
|
|
73
|
+
|
|
74
|
+
self.dest_edit = QLineEdit(self)
|
|
75
|
+
self.dest_edit.setPlaceholderText(self.tr("(optional) Rename into this folder; leave empty to rename in place"))
|
|
76
|
+
btn_dest = QPushButton(self.tr("Browse…"), self); btn_dest.clicked.connect(self._pick_dest)
|
|
77
|
+
io_row2 = QHBoxLayout()
|
|
78
|
+
io_row2.addWidget(QLabel(self.tr("Destination:")))
|
|
79
|
+
io_row2.addWidget(self.dest_edit, 1)
|
|
80
|
+
io_row2.addWidget(btn_dest)
|
|
81
|
+
|
|
82
|
+
root.addLayout(io_row); root.addLayout(io_row2)
|
|
83
|
+
|
|
84
|
+
# Middle: template & options
|
|
85
|
+
pat_box = QGroupBox(self.tr("Filename pattern"))
|
|
86
|
+
pat_lay = QHBoxLayout(pat_box)
|
|
87
|
+
|
|
88
|
+
self.pattern_edit = QLineEdit(self)
|
|
89
|
+
self.pattern_edit.setPlaceholderText(self.tr("e.g. LIGHT_{FILTER}_{EXPOSURE:.0f}s_{DATE-OBS:%Y%m%d}_{#03}.{ext}"))
|
|
90
|
+
self.pattern_edit.textChanged.connect(self._refresh_preview)
|
|
91
|
+
|
|
92
|
+
self.lower_cb = QCheckBox(self.tr("lowercase"), self); self.lower_cb.toggled.connect(self._refresh_preview)
|
|
93
|
+
self.slug_cb = QCheckBox(self.tr("spaces→_"), self); self.slug_cb.toggled.connect(self._refresh_preview)
|
|
94
|
+
self.keep_ext_cb = QCheckBox(self.tr("append .{ext} if missing"), self); self.keep_ext_cb.setChecked(True)
|
|
95
|
+
self.index_start = QSpinBox(self); self.index_start.setRange(0, 999999); self.index_start.setValue(1)
|
|
96
|
+
self.index_start.valueChanged.connect(self._refresh_preview)
|
|
97
|
+
|
|
98
|
+
self.token_combo = QComboBox(self)
|
|
99
|
+
self.token_combo.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToContents)
|
|
100
|
+
self.token_combo.setMinimumContentsLength(12)
|
|
101
|
+
self.token_combo.setEditable(False)
|
|
102
|
+
self.token_combo.setToolTip(self.tr("Insert token"))
|
|
103
|
+
self.token_combo.activated.connect(
|
|
104
|
+
lambda idx: self._insert_token(self.token_combo.itemText(idx))
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
insert_btn = QPushButton(self.tr("Insert"), self)
|
|
108
|
+
insert_btn.clicked.connect(lambda: self._insert_token(self.token_combo.currentText()))
|
|
109
|
+
|
|
110
|
+
pat_lay.addWidget(QLabel(self.tr("Template:"))); pat_lay.addWidget(self.pattern_edit, 1)
|
|
111
|
+
pat_lay.addWidget(self.token_combo); pat_lay.addWidget(insert_btn)
|
|
112
|
+
pat_lay.addWidget(self.lower_cb); pat_lay.addWidget(self.slug_cb)
|
|
113
|
+
pat_lay.addWidget(QLabel(self.tr("Index start:"))); pat_lay.addWidget(self.index_start)
|
|
114
|
+
pat_lay.addWidget(self.keep_ext_cb)
|
|
115
|
+
|
|
116
|
+
root.addWidget(pat_box)
|
|
117
|
+
|
|
118
|
+
# Splitter: keys list | table
|
|
119
|
+
split = QSplitter(Qt.Orientation.Horizontal, self)
|
|
120
|
+
|
|
121
|
+
# Keys list
|
|
122
|
+
left = QWidget(self); lyt = QVBoxLayout(left)
|
|
123
|
+
left.setFixedWidth(180)
|
|
124
|
+
self.keys_list = QListWidget(self)
|
|
125
|
+
self.keys_list.itemDoubleClicked.connect(self._insert_key_from_list)
|
|
126
|
+
lyt.addWidget(QLabel(self.tr("Available FITS keywords (double-click to insert):")))
|
|
127
|
+
lyt.addWidget(self.keys_list, 1)
|
|
128
|
+
split.addWidget(left)
|
|
129
|
+
|
|
130
|
+
# Table
|
|
131
|
+
right = QWidget(self); rlyt = QVBoxLayout(right)
|
|
132
|
+
self.table = QTableWidget(self); self.table.setColumnCount(4)
|
|
133
|
+
self.table.setHorizontalHeaderLabels([self.tr("Old path"), "→", self.tr("New name"), self.tr("Status")])
|
|
134
|
+
self.table.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
|
|
135
|
+
self.table.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.ResizeToContents)
|
|
136
|
+
self.table.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.Stretch)
|
|
137
|
+
self.table.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeMode.ResizeToContents)
|
|
138
|
+
self.table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
|
|
139
|
+
self.table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
|
|
140
|
+
try:
|
|
141
|
+
self.table.setTextElideMode(Qt.TextElideMode.ElideMiddle) # PyQt6
|
|
142
|
+
except AttributeError:
|
|
143
|
+
pass
|
|
144
|
+
rlyt.addWidget(QLabel(self.tr("Preview")))
|
|
145
|
+
rlyt.addWidget(self.table, 1)
|
|
146
|
+
split.addWidget(right)
|
|
147
|
+
split.setSizes([250, 700])
|
|
148
|
+
|
|
149
|
+
root.addWidget(split, 1)
|
|
150
|
+
split.setStretchFactor(0, 0)
|
|
151
|
+
split.setStretchFactor(1, 1)
|
|
152
|
+
split.setCollapsible(0, False)
|
|
153
|
+
|
|
154
|
+
# Buttons
|
|
155
|
+
btns = QDialogButtonBox(self)
|
|
156
|
+
self.btn_preview = btns.addButton(self.tr("Preview"), QDialogButtonBox.ButtonRole.ActionRole)
|
|
157
|
+
self.btn_rename = btns.addButton(self.tr("Rename"), QDialogButtonBox.ButtonRole.AcceptRole)
|
|
158
|
+
self.btn_close = btns.addButton(QDialogButtonBox.StandardButton.Close)
|
|
159
|
+
self.btn_preview.clicked.connect(self._refresh_preview)
|
|
160
|
+
self.btn_rename.clicked.connect(self._do_rename)
|
|
161
|
+
self.btn_close.clicked.connect(self.close)
|
|
162
|
+
root.addWidget(btns)
|
|
163
|
+
|
|
164
|
+
self._populate_token_keywords()
|
|
165
|
+
|
|
166
|
+
# ---------- settings ----------
|
|
167
|
+
def _load_settings(self):
|
|
168
|
+
self.settings.beginGroup("batchrename")
|
|
169
|
+
self.src_edit.setText(self.settings.value("last_dir", "", type=str) or "")
|
|
170
|
+
self.dest_edit.setText(self.settings.value("dest_dir", "", type=str) or "")
|
|
171
|
+
self.pattern_edit.setText(self.settings.value(
|
|
172
|
+
"pattern", "LIGHT_{FILTER}_{EXPOSURE:.0f}s_{DATE-OBS:%Y%m%d}_{#03}.{ext}", type=str))
|
|
173
|
+
self.lower_cb.setChecked(self.settings.value("lower", False, type=bool))
|
|
174
|
+
self.slug_cb.setChecked(self.settings.value("slug", True, type=bool))
|
|
175
|
+
self.keep_ext_cb.setChecked(self.settings.value("keep_ext", True, type=bool))
|
|
176
|
+
self.index_start.setValue(self.settings.value("index_start", 1, type=int))
|
|
177
|
+
self.settings.endGroup()
|
|
178
|
+
if self.src_edit.text():
|
|
179
|
+
self._scan_existing(self.src_edit.text())
|
|
180
|
+
|
|
181
|
+
def _save_settings(self):
|
|
182
|
+
self.settings.beginGroup("batchrename")
|
|
183
|
+
self.settings.setValue("last_dir", self.src_edit.text().strip())
|
|
184
|
+
self.settings.setValue("dest_dir", self.dest_edit.text().strip())
|
|
185
|
+
self.settings.setValue("pattern", self.pattern_edit.text().strip())
|
|
186
|
+
self.settings.setValue("lower", self.lower_cb.isChecked())
|
|
187
|
+
self.settings.setValue("slug", self.slug_cb.isChecked())
|
|
188
|
+
self.settings.setValue("keep_ext", self.keep_ext_cb.isChecked())
|
|
189
|
+
self.settings.setValue("index_start", self.index_start.value())
|
|
190
|
+
self.settings.endGroup()
|
|
191
|
+
|
|
192
|
+
# ---------- file loading ----------
|
|
193
|
+
def _scan_folder(self):
|
|
194
|
+
start = self.src_edit.text().strip()
|
|
195
|
+
path = QFileDialog.getExistingDirectory(self, self.tr("Select Folder"), start or "")
|
|
196
|
+
if not path: return
|
|
197
|
+
self.src_edit.setText(path)
|
|
198
|
+
self._scan_existing(path)
|
|
199
|
+
self._save_settings()
|
|
200
|
+
|
|
201
|
+
def _scan_existing(self, path: str):
|
|
202
|
+
paths = []
|
|
203
|
+
for root, _, files in os.walk(path):
|
|
204
|
+
for f in files:
|
|
205
|
+
if f.lower().endswith((".fits", ".fit", ".fts", ".fz")):
|
|
206
|
+
paths.append(os.path.join(root, f))
|
|
207
|
+
paths.sort()
|
|
208
|
+
self._set_files(paths)
|
|
209
|
+
|
|
210
|
+
def _add_files(self):
|
|
211
|
+
start = self.src_edit.text().strip() or ""
|
|
212
|
+
files, _ = QFileDialog.getOpenFileNames(
|
|
213
|
+
self, self.tr("Add FITS files"), start, self.tr("FITS files (*.fit *.fits *.fts *.fz);;All files (*)")
|
|
214
|
+
)
|
|
215
|
+
if not files: return
|
|
216
|
+
new = sorted(set(self.files) | set(files))
|
|
217
|
+
self._set_files(new)
|
|
218
|
+
if not self.src_edit.text() and files:
|
|
219
|
+
self.src_edit.setText(os.path.dirname(files[0]))
|
|
220
|
+
self._save_settings()
|
|
221
|
+
|
|
222
|
+
def _set_files(self, paths: List[str]):
|
|
223
|
+
self.files = paths
|
|
224
|
+
self.headers.clear()
|
|
225
|
+
union = set()
|
|
226
|
+
ok, bad = 0, 0
|
|
227
|
+
for p in self.files:
|
|
228
|
+
try:
|
|
229
|
+
with fits.open(p, memmap=False) as hdul:
|
|
230
|
+
h = hdul[0].header
|
|
231
|
+
self.headers[p] = h
|
|
232
|
+
union.update([str(k) for k in h.keys()])
|
|
233
|
+
ok += 1
|
|
234
|
+
except Exception:
|
|
235
|
+
bad += 1
|
|
236
|
+
self.union_keys = sorted(union)
|
|
237
|
+
self._rebuild_keys_list()
|
|
238
|
+
self._fill_table_rows()
|
|
239
|
+
self._refresh_preview()
|
|
240
|
+
|
|
241
|
+
def _pick_dest(self):
|
|
242
|
+
start = self.dest_edit.text().strip() or self.src_edit.text().strip()
|
|
243
|
+
d = QFileDialog.getExistingDirectory(self, self.tr("Choose Destination Folder"), start or "")
|
|
244
|
+
if not d: return
|
|
245
|
+
self.dest_edit.setText(d)
|
|
246
|
+
self._save_settings()
|
|
247
|
+
|
|
248
|
+
def _autosize_combo(self, combo: QComboBox, base_padding: int = 36):
|
|
249
|
+
if combo.count() == 0:
|
|
250
|
+
combo.setMinimumWidth(160)
|
|
251
|
+
return
|
|
252
|
+
fm = QFontMetrics(combo.font())
|
|
253
|
+
maxw = 0
|
|
254
|
+
for i in range(combo.count()):
|
|
255
|
+
w = fm.horizontalAdvance(combo.itemText(i))
|
|
256
|
+
if not combo.itemIcon(i).isNull():
|
|
257
|
+
w += combo.iconSize().width() + 8
|
|
258
|
+
maxw = max(maxw, w)
|
|
259
|
+
width = maxw + base_padding
|
|
260
|
+
combo.setMinimumWidth(width)
|
|
261
|
+
if combo.view() is not None:
|
|
262
|
+
combo.view().setMinimumWidth(width)
|
|
263
|
+
combo.updateGeometry()
|
|
264
|
+
|
|
265
|
+
# ---------- keys & template insertion ----------
|
|
266
|
+
def _rebuild_keys_list(self):
|
|
267
|
+
self.keys_list.clear()
|
|
268
|
+
for k in self.union_keys:
|
|
269
|
+
self.keys_list.addItem(QListWidgetItem(k))
|
|
270
|
+
self._populate_token_keywords()
|
|
271
|
+
|
|
272
|
+
def _insert_key_from_list(self, item: QListWidgetItem):
|
|
273
|
+
if not item: return
|
|
274
|
+
self._insert_text("{"+item.text()+"}")
|
|
275
|
+
|
|
276
|
+
def _insert_token(self, token: str):
|
|
277
|
+
if not token: return
|
|
278
|
+
self._insert_text(token)
|
|
279
|
+
|
|
280
|
+
def _populate_token_keywords(self):
|
|
281
|
+
tokens = ["{#}", "{#03}", "{ext}"] + [f"{{{k}}}" for k in self.union_keys]
|
|
282
|
+
self.token_combo.blockSignals(True)
|
|
283
|
+
self.token_combo.clear()
|
|
284
|
+
self.token_combo.addItems(sorted(tokens, key=str.lower))
|
|
285
|
+
self.token_combo.blockSignals(False)
|
|
286
|
+
QTimer.singleShot(0, lambda: self._autosize_combo(self.token_combo))
|
|
287
|
+
|
|
288
|
+
def _insert_text(self, text: str):
|
|
289
|
+
e = self.pattern_edit
|
|
290
|
+
pos = e.cursorPosition()
|
|
291
|
+
s = e.text()
|
|
292
|
+
e.setText(s[:pos] + text + s[pos:])
|
|
293
|
+
e.setCursorPosition(pos + len(text))
|
|
294
|
+
self._refresh_preview()
|
|
295
|
+
|
|
296
|
+
# ---------- preview/rename ----------
|
|
297
|
+
def _fill_table_rows(self):
|
|
298
|
+
self.table.setRowCount(len(self.files))
|
|
299
|
+
for r, p in enumerate(self.files):
|
|
300
|
+
self.table.setItem(r, 0, QTableWidgetItem(p))
|
|
301
|
+
self.table.setItem(r, 1, QTableWidgetItem("→"))
|
|
302
|
+
self.table.setItem(r, 2, QTableWidgetItem(""))
|
|
303
|
+
self.table.setItem(r, 3, QTableWidgetItem(""))
|
|
304
|
+
|
|
305
|
+
def _clear_selection(self):
|
|
306
|
+
self.files = []
|
|
307
|
+
self.headers.clear()
|
|
308
|
+
self.union_keys = []
|
|
309
|
+
self._rebuild_keys_list()
|
|
310
|
+
self.table.setRowCount(0)
|
|
311
|
+
self._refresh_preview()
|
|
312
|
+
|
|
313
|
+
def _refresh_preview(self):
|
|
314
|
+
pat = self.pattern_edit.text().strip()
|
|
315
|
+
if not pat: return
|
|
316
|
+
dest = (self.dest_edit.text().strip() or None)
|
|
317
|
+
start_idx = self.index_start.value()
|
|
318
|
+
lower = self.lower_cb.isChecked()
|
|
319
|
+
slug = self.slug_cb.isChecked()
|
|
320
|
+
keep_ext = self.keep_ext_cb.isChecked()
|
|
321
|
+
|
|
322
|
+
names = []
|
|
323
|
+
for i, p in enumerate(self.files):
|
|
324
|
+
hdr = self.headers.get(p, fits.Header())
|
|
325
|
+
base = self._render_pattern(pat, hdr, i, start_idx, p)
|
|
326
|
+
if keep_ext and "{ext}" not in pat:
|
|
327
|
+
ext = os.path.splitext(p)[1]
|
|
328
|
+
if ext:
|
|
329
|
+
base = f"{base}{ext}"
|
|
330
|
+
if lower: base = base.lower()
|
|
331
|
+
if slug: base = self._slugify(base)
|
|
332
|
+
folder = dest if dest else os.path.dirname(p)
|
|
333
|
+
target = os.path.join(folder, base)
|
|
334
|
+
names.append(target)
|
|
335
|
+
|
|
336
|
+
seen = defaultdict(int)
|
|
337
|
+
for t in names: seen[t] += 1
|
|
338
|
+
|
|
339
|
+
for r, p in enumerate(self.files):
|
|
340
|
+
newp = names[r]
|
|
341
|
+
self._set_table_preview_row(r, p, newp, seen[newp])
|
|
342
|
+
|
|
343
|
+
def _set_table_preview_row(self, r: int, old: str, new: str, count: int):
|
|
344
|
+
self.table.item(r, 0).setText(old)
|
|
345
|
+
self.table.item(r, 2).setText(new)
|
|
346
|
+
status = ""
|
|
347
|
+
conflict = (count > 1)
|
|
348
|
+
if conflict: status = self.tr("name collision")
|
|
349
|
+
elif os.path.exists(new): status = self.tr("will overwrite")
|
|
350
|
+
else: status = self.tr("ok")
|
|
351
|
+
it = QTableWidgetItem(status)
|
|
352
|
+
if conflict or status == "will overwrite":
|
|
353
|
+
it.setForeground(Qt.GlobalColor.red)
|
|
354
|
+
self.table.setItem(r, 3, it)
|
|
355
|
+
it_old = self.table.item(r, 0)
|
|
356
|
+
it_new = self.table.item(r, 2)
|
|
357
|
+
if it_old: it_old.setToolTip(old)
|
|
358
|
+
if it_new: it_new.setToolTip(new)
|
|
359
|
+
|
|
360
|
+
def _do_rename(self):
|
|
361
|
+
n = self.table.rowCount()
|
|
362
|
+
targets = [self.table.item(r, 2).text() for r in range(n)]
|
|
363
|
+
counts = defaultdict(int)
|
|
364
|
+
for t in targets: counts[t] += 1
|
|
365
|
+
collisions = [t for t,c in counts.items() if c > 1]
|
|
366
|
+
if collisions:
|
|
367
|
+
QMessageBox.warning(self, self.tr("Collisions"),
|
|
368
|
+
self.tr("Two or more files would map to the same name. Adjust your pattern."))
|
|
369
|
+
return
|
|
370
|
+
|
|
371
|
+
failures = []
|
|
372
|
+
for r in range(n):
|
|
373
|
+
oldp = self.table.item(r, 0).text()
|
|
374
|
+
newp = self.table.item(r, 2).text()
|
|
375
|
+
if oldp == newp:
|
|
376
|
+
continue
|
|
377
|
+
os.makedirs(os.path.dirname(newp), exist_ok=True)
|
|
378
|
+
try:
|
|
379
|
+
shutil.move(oldp, newp)
|
|
380
|
+
self.table.item(r, 3).setText(self.tr("renamed"))
|
|
381
|
+
except Exception as e:
|
|
382
|
+
self.table.item(r, 3).setText(self.tr("ERROR: {0}").format(e))
|
|
383
|
+
self.table.item(r, 3).setForeground(Qt.GlobalColor.red)
|
|
384
|
+
failures.append((oldp, str(e)))
|
|
385
|
+
|
|
386
|
+
if failures:
|
|
387
|
+
QMessageBox.warning(self, self.tr("Done with errors"),
|
|
388
|
+
self.tr("Some files could not be renamed ({0} errors).").format(len(failures)))
|
|
389
|
+
else:
|
|
390
|
+
QMessageBox.information(self, self.tr("Done"), self.tr("All files renamed."))
|
|
391
|
+
self._save_settings()
|
|
392
|
+
src = self.src_edit.text().strip()
|
|
393
|
+
if src and not self.dest_edit.text().strip():
|
|
394
|
+
self._scan_existing(src)
|
|
395
|
+
|
|
396
|
+
# ---------- helpers ----------
|
|
397
|
+
@staticmethod
|
|
398
|
+
def _slugify(s: str) -> str:
|
|
399
|
+
s = s.replace(" ", "_")
|
|
400
|
+
return re.sub(r"[^A-Za-z0-9._-]+", "", s)
|
|
401
|
+
|
|
402
|
+
def _render_pattern(self, pat: str, hdr: fits.Header, i: int, start_idx: int, file_path: str) -> str:
|
|
403
|
+
def apply_filters(text: str, filters: list[str]) -> str:
|
|
404
|
+
out = str(text)
|
|
405
|
+
for f in filters:
|
|
406
|
+
f = f.strip()
|
|
407
|
+
if f.startswith("re:"):
|
|
408
|
+
pattern = f[3:]
|
|
409
|
+
m = re.search(pattern, out)
|
|
410
|
+
if not m:
|
|
411
|
+
out = ""
|
|
412
|
+
else:
|
|
413
|
+
out = m.group(1) if m.lastindex else m.group(0)
|
|
414
|
+
elif f == "lower":
|
|
415
|
+
out = out.lower()
|
|
416
|
+
elif f == "upper":
|
|
417
|
+
out = out.upper()
|
|
418
|
+
elif f.startswith("slice:"):
|
|
419
|
+
try:
|
|
420
|
+
_, a, b = f.split(":", 2)
|
|
421
|
+
a = int(a) if a else None
|
|
422
|
+
b = int(b) if b else None
|
|
423
|
+
out = out[a:b]
|
|
424
|
+
except Exception:
|
|
425
|
+
pass
|
|
426
|
+
elif f == "strip":
|
|
427
|
+
out = out.strip()
|
|
428
|
+
return out
|
|
429
|
+
|
|
430
|
+
def _split_top_level_pipes(s: str) -> List[str]:
|
|
431
|
+
parts, buf = [], []
|
|
432
|
+
depth = 0
|
|
433
|
+
esc = False
|
|
434
|
+
for ch in s:
|
|
435
|
+
if esc:
|
|
436
|
+
buf.append(ch); esc = False; continue
|
|
437
|
+
if ch == '\\':
|
|
438
|
+
buf.append(ch); esc = True; continue
|
|
439
|
+
if ch in '([{':
|
|
440
|
+
depth += 1
|
|
441
|
+
elif ch in ')]}':
|
|
442
|
+
depth = max(0, depth-1)
|
|
443
|
+
if ch == '|' and depth == 0:
|
|
444
|
+
parts.append(''.join(buf)); buf = []
|
|
445
|
+
else:
|
|
446
|
+
buf.append(ch)
|
|
447
|
+
parts.append(''.join(buf))
|
|
448
|
+
return parts
|
|
449
|
+
|
|
450
|
+
token_re = re.compile(r"\{((?:[^{}]|\{[^{}]*\})+)\}")
|
|
451
|
+
|
|
452
|
+
def repl(m):
|
|
453
|
+
body = m.group(1)
|
|
454
|
+
parts = _split_top_level_pipes(body)
|
|
455
|
+
key_fmt = parts[0]
|
|
456
|
+
filters = parts[1:] if len(parts) > 1 else []
|
|
457
|
+
|
|
458
|
+
# counter?
|
|
459
|
+
if key_fmt.startswith("#"):
|
|
460
|
+
w = key_fmt[1:]
|
|
461
|
+
try:
|
|
462
|
+
pad = int(w) if w else 0
|
|
463
|
+
except Exception:
|
|
464
|
+
pad = 0
|
|
465
|
+
num = i + start_idx
|
|
466
|
+
return f"{num:0{pad}d}" if pad else str(num)
|
|
467
|
+
|
|
468
|
+
# extension?
|
|
469
|
+
if key_fmt.lower() == "ext":
|
|
470
|
+
ext = os.path.splitext(file_path)[1]
|
|
471
|
+
return ext.lstrip(".")
|
|
472
|
+
|
|
473
|
+
# key[:fmt]
|
|
474
|
+
if ":" in key_fmt:
|
|
475
|
+
key, fmt = key_fmt.split(":", 1)
|
|
476
|
+
else:
|
|
477
|
+
key, fmt = key_fmt, ""
|
|
478
|
+
key_up = key.upper()
|
|
479
|
+
val = hdr.get(key_up, "")
|
|
480
|
+
if val is None:
|
|
481
|
+
val = ""
|
|
482
|
+
|
|
483
|
+
# DATE-like with datetime fmt
|
|
484
|
+
if fmt and key_up in ("DATE-OBS", "DATE"):
|
|
485
|
+
s = str(val).strip().replace("Z", "+00:00")
|
|
486
|
+
try:
|
|
487
|
+
dt = datetime.fromisoformat(s)
|
|
488
|
+
if dt.tzinfo is None:
|
|
489
|
+
dt = dt.replace(tzinfo=timezone.utc)
|
|
490
|
+
out = dt.strftime(fmt)
|
|
491
|
+
except Exception:
|
|
492
|
+
out = str(val)
|
|
493
|
+
return apply_filters(out, filters)
|
|
494
|
+
|
|
495
|
+
# TIME-only keys with time fmt
|
|
496
|
+
if fmt and key_up in ("TIME-OBS", "UTSTART", "UTC-START"):
|
|
497
|
+
s = str(val).strip()
|
|
498
|
+
try:
|
|
499
|
+
if s.count(":") == 2:
|
|
500
|
+
tt = datetime.strptime(s, "%H:%M:%S").time()
|
|
501
|
+
else:
|
|
502
|
+
tt = datetime.strptime(s, "%H:%M").time()
|
|
503
|
+
out = tt.strftime(fmt)
|
|
504
|
+
except Exception:
|
|
505
|
+
try:
|
|
506
|
+
tt = datetime.fromisoformat(f"1970-01-01T{s}").time()
|
|
507
|
+
out = tt.strftime(fmt)
|
|
508
|
+
except Exception:
|
|
509
|
+
out = str(val)
|
|
510
|
+
return apply_filters(out, filters)
|
|
511
|
+
|
|
512
|
+
# numeric with fmt
|
|
513
|
+
if fmt:
|
|
514
|
+
try:
|
|
515
|
+
out = format(float(val), fmt)
|
|
516
|
+
return apply_filters(out, filters)
|
|
517
|
+
except Exception:
|
|
518
|
+
pass
|
|
519
|
+
|
|
520
|
+
return apply_filters(str(val), filters)
|
|
521
|
+
|
|
522
|
+
return token_re.sub(repl, pat)
|