Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

RF/ENH: remove file prior writing in to_filename#466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
yarikoptic wants to merge2 commits intonipy:master
base:master
Choose a base branch
Loading
fromyarikoptic:enh-remove-before-to_filename
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletionnibabel/filebasedimages.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
''' Common interface for any image format--volume or surface, binary or xml.'''

import os
import warnings

from .externals.six import string_types
Expand All@@ -16,6 +17,14 @@
splitext_addext)
from .openers import ImageOpener

# OS-specific path
_GIT_ANNEX_OBJECTS_PATH = os.path.join('.git', 'annex', 'objects')


def _is_annex_symlink(path):
"""Return True if file is a symlink to the git-annex objects"""
return os.path.islink(path) and _GIT_ANNEX_OBJECTS_PATH in os.path.realpath(path)


class ImageFileError(Exception):
pass
Expand DownExpand Up@@ -347,7 +356,16 @@ def to_filename(self, filename):
-------
None
'''
self.file_map = self.filespec_to_file_map(filename)
self.file_map = file_map = self.filespec_to_file_map(filename)
remove_env = os.environ.get('NIBABEL_REMOVE_BEFORE_TO_FILENAME', None)
for _, fh in file_map.items():
if not isinstance(fh, FileHolder):
continue
if os.path.lexists(fh.filename) and (remove_env or _is_annex_symlink(fh.filename)):
# Remove previous file where new file would be saved
# Necessary e.g. for cases where file is a symlink pointing
# to some non-writable file (e.g. under git annex control)
os.unlink(fh.filename)
self.to_file_map()
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

or@matthew-brett do you think it would remain kosher to shift this functionality even deeper into to_file_map? ;)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, to do this properly would mean going down intoto_file_map, because it's possible to save images with filenames that way, but then, at the moment, you'd have to go into the implementation for each file type (to_file_map not implemented by default).


def to_filespec(self, filename):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp