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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added management command #912
Conversation
@jrief 👍 |
@jrief I'd just an option to only output filenames instead of "Found orphaned file...", to be able to pipe the output somewhere (I'd use verbosity to control the output form) |
Then the command should be renamed to, say |
I'd use multiple options: the first two can be combined together to scan both |
@jrief would you have a look at my comment above? |
Nice idea but it did not work for me because I changed the filer urls in the django settings. I fixed it with the django settings import:
|
@wiesson thanks for the hint, but your approach only works if FILER_STORAGES has been configured explicitly in the project settings. I therefore will wrap it into a try/except-block to fallback to the defaults. |
@jrief any progress on this? |
for filename in files: | ||
relfilename = os.path.join(reldir, filename) | ||
try: | ||
File.objects.get(file=relfilename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not if not File.objects.filter(file=relfilename).exists()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@yakky thanks for reminding me and sorry for not proceeding on this. I'm stuck with far too many other issues. |
just curious, does this work if for example S3 storage is configured? Also, does it respect private/public flag on files? Methinks not, as it just uses DefaultStorage() ? |
@yakky
@czpython added unit tests for all command options and entry in CHANGELOG. sorry for the long delay |
Could someone please explain me, what's wrong with this failing test? My local |
docs/management_commands.rst
Outdated
|
||
Invoking:: | ||
|
||
./manage.py filer_check --orphanes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
docs/management_commands.rst
Outdated
|
||
Invoking:: | ||
|
||
./manage.py filer_check --delete-orphanes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
from filer.settings import DEFAULT_FILER_STORAGES | ||
|
||
|
||
class Command(BaseCommand): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
management commands shouldn't mark strings for translation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
msg = _("\nThis will delete entries from your database. Are you sure you want to do this?\n\n" | ||
"Type 'yes' to continue, or 'no' to cancel: ") | ||
if input(msg) != 'yes': | ||
raise CommandError("Aborted: Delete missing file entries from database.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why raise an exception, no is a valid option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
msg = _("\nThis will delete orphaned files from your storage. Are you sure you want to do this?\n\n" | ||
"Type 'yes' to continue, or 'no' to cancel: ") | ||
if input(msg) != 'yes': | ||
raise CommandError("Aborted: Delete orphaned files from storage.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Unit test job 2196.35 is failing for throttling reasons:
Please restart the job. |
Ping @czpython |
@yakky assigned to you for merge |
thanks! @jrief |
@yakky is there anything I can do to help get this merged and released? |
Today I had to check the consistency of files in one of my projects. Unfortunately I was quite disappointed that django-filer still lacks this feature, although this pull request is pending and waiting to be merged for one year now. |
# Conflicts: # CHANGELOG.txt
…r into feature/orphaned_files # Conflicts: # CHANGELOG.txt
# Conflicts: # CHANGELOG.rst # filer/tests/__init__.py
Codecov Report
@@ Coverage Diff @@
## develop #912 +/- ##
===========================================
+ Coverage 71% 71.19% +0.18%
===========================================
Files 62 63 +1
Lines 3032 3100 +68
Branches 424 443 +19
===========================================
+ Hits 2153 2207 +54
- Misses 731 741 +10
- Partials 148 152 +4
Continue to review full report at Codecov.
|
Now I rebased this pull request upon the current I really would appreciate, if in version 1.6 this useful feature finally would be available, almost 3 years after starting to work on it. |
@jrief I am at the point where I'm debating forking the project with this feature and releasing it on PyPi. I know I'm not the only person with the need for this functionality. I do not want to be forced to take that option because it's fragmentation, however the time is approaching quickly. |
Today this pull requests celebrates its 🎂3rd birthday 🎂and is still unmerged! Dear maintainers of django-filer: If you need help with maintenance, please consider to add me to the list of core maintainer of this project. |
@jrief thanks for the PR and changes requested from various reviewers. It gets merged today :) I also added you to the collaborators, I appreciate the help on Filer 🙏 |
Can this command be useful?
It sometimes happens, that I have orphaned files in my folder
filer_public
, which do not have any associated meta data. With./manage.py orphaned_files
we can list them, and with./manage.py orphaned_files --delete
we can delete them.