Skip to content

Set solar flare fetch code to use copyfile not copy when updating the file#93

Merged
jeanconn merged 1 commit intomasterfrom
copyfile
Apr 9, 2025
Merged

Set solar flare fetch code to use copyfile not copy when updating the file#93
jeanconn merged 1 commit intomasterfrom
copyfile

Conversation

@jeanconn
Copy link
Contributor

@jeanconn jeanconn commented Mar 18, 2025

Description

Use copyfile not copy

The update script is run by multiple users, so copy() runs into issues with chmod and spits these into the log:

<<2025-Mar-24 06:11>> Traceback (most recent call last):
<<2025-Mar-24 06:11>> File "/proj/sot/ska3/flight/share/arc3/get_solar_flare_png.py", line 116, in
<<2025-Mar-24 06:11>> main()
<<2025-Mar-24 06:11>> File "/proj/sot/ska3/flight/share/arc3/get_solar_flare_png.py", line 111, in main
<<2025-Mar-24 06:11>> shutil.copy(img_file, standard_image_path)
<<2025-Mar-24 06:11>> File "/proj/sot/ska3/flight/lib/python3.12/shutil.py", line 436, in copy
<<2025-Mar-24 06:11>> copymode(src, dst, follow_symlinks=follow_symlinks)
<<2025-Mar-24 06:11>> File "/proj/sot/ska3/flight/lib/python3.12/shutil.py", line 317, in copymode
<<2025-Mar-24 06:11>> chmod_func(dst, stat.S_IMODE(st.st_mode))
<<2025-Mar-24 06:11>> PermissionError: [Errno 1] Operation not permitted: '/proj/sot/ska3/flight/www/ASPECT/arc3/solar_flare.png'

Interface impacts

Functional testing

On my mac I made a new tester user.

As jean user I did this

python get_solar_flare_png.py --image-cache-dir image_cache --out-file my_solar_flare.png
(ska3) flame:arc jean$ chmod g+w my_solar_flare.png 
(ska3) flame:arc jean$ chmod g+w image_cache/
(ska3) flame:arc jean$ chmod g+w image_cache/AR_CH_20250324.png 

And confirmed from master the error we get about chmod_func as a tester user in the staff group.

(ska3) tester@flame arc % python get_solar_flare_png.py --image-cache-dir image_cache --out-file my_solar_flare.png
Traceback (most recent call last):
  File "/Users/jean/git/arc/get_solar_flare_png.py", line 116, in <module>
    main()
  File "/Users/jean/git/arc/get_solar_flare_png.py", line 111, in main
    shutil.copy(img_file, standard_image_path)
  File "/Users/jean/miniforge3/envs/ska3/lib/python3.12/shutil.py", line 436, in copy
    copymode(src, dst, follow_symlinks=follow_symlinks)
  File "/Users/jean/miniforge3/envs/ska3/lib/python3.12/shutil.py", line 317, in copymode
    chmod_func(dst, stat.S_IMODE(st.st_mode))
PermissionError: [Errno 1] Operation not permitted: 'my_solar_flare.png'

And then checked out this PR code

(ska3) tester@flame arc % python get_solar_flare_png.py --image-cache-dir image_cache --out-file my_solar_flare.png

with no error.

The update script is run by multiple users, so copy() runs into issues
with chmod.
@jeanconn jeanconn marked this pull request as ready for review March 25, 2025 18:38
@jeanconn jeanconn requested review from Copilot and taldcroft March 25, 2025 18:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces the use of shutil.copy with shutil.copyfile to work around permission issues when copying files, ensuring the update script runs without errors across different user environments.

  • Replace shutil.copy with shutil.copyfile to avoid unwanted chmod operations.
  • Maintain file content copying while intentionally skipping file metadata.
Comments suppressed due to low confidence (1)

get_solar_flare_png.py:111

  • [nitpick] Using shutil.copyfile prevents copying file metadata (e.g., permissions). If preserving metadata is required elsewhere, consider handling this explicitly.
shutil.copyfile(img_file, standard_image_path)

@jeanconn jeanconn changed the title Use copyfile not copy Set solar flare fetch code to use copyfile not copy when updating the file Mar 25, 2025
@jeanconn jeanconn merged commit 6409b3d into master Apr 9, 2025
2 checks passed
@jeanconn jeanconn deleted the copyfile branch April 9, 2025 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants