Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Problem with moving images files - Using the shutil method to copy folders#548

Closed
rpatureau wants to merge 1 commit intomasterfrom
copy_shutil
Closed

Problem with moving images files - Using the shutil method to copy folders#548
rpatureau wants to merge 1 commit intomasterfrom
copy_shutil

Conversation

@rpatureau
Copy link
Contributor

It is possible to change the directory of DHC from Buildings.Experimental.DHC to Buildings.DHC thanks to the function move_class. During the process, the images are moved recursively via the function _move_class_directory that calls for each folder the function _move_images_directory. To move the folders, the command line git mv is used.

For example, the package Buildings. Experimental .DHC.EnergyTransferStations.Combined has 2 images, PartialParallel and ChillerBorefield.
During the first iteration, for BaseClasses.PartialParallel, Resources\Images\Experimental\DHC\EnergyTransferStations\Combined\BaseClasses is moved to Resources\Images\DHC\EnergyTransferStations\Combined\BaseClasses, which is the expected behavior.
BUT during the second iteration for ChillerBorefield, instead of moving to Resources\Images\DHC\EnergyTransferStations\Combined, the image goes to Resources\Images\DHC\EnergyTransferStations\Combined\Combined because of the behavior of
git mv (Resources\Images\DHC\EnergyTransferStations\Combined already exists).

The proposed alternative is to use shutil package (part of the standard Python distribution, OS agnostic) instead of git mv.
At the moment the function _git_move is only used with the variable _shutil=True within the function _move_images_directory, but it may fully replace the git mv method.

The downside is that it is not considered in git as a "rename" but as a new file (new folder)/deleted file (old folder).

Also, the function used may be refined to adapt to every context.

Finally, for git use, the following could be used:

_sh(cmd=['git', 'rm', '-r', source], directory=os.path.curdir)
_sh(cmd=['git', 'add', target], directory=os.path.curdir)

Instead of shutil.rmtree(source)

@rpatureau rpatureau requested a review from mwetter April 24, 2024 17:43
@rpatureau rpatureau self-assigned this Apr 24, 2024
@rpatureau rpatureau closed this Apr 25, 2024
@rpatureau rpatureau deleted the copy_shutil branch April 25, 2024 00:43
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.

1 participant