Coder Social home page Coder Social logo

django-orphaned's People

Contributors

artscoop avatar joerick avatar ledil avatar slamora avatar tilley avatar zlorf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

django-orphaned's Issues

exclude specific files

Similar to the exclude path feature, the app can provide a setting for excluding files that are stored at the 'root' too.
For example, I have a .gitignore for avoid including this files into the git repository. When I run python manage.py deleteorphaned --info I get as output:

/var/someuser/private/.gitignore
/var/someuser/private/orphan_file.tar.gz 

Maybe adding a new subsetting: exclude and using a similiar concept than in should_skip method:

# deleteorphaned.py:28
skip_files = ORPHANED_APPS_MEDIABASE_DIRS[app].get('exclude', ())
# deleteorphaned.py:55
    if basename not in exclude:
        all_files.append(os.path.join(root, basename))

Settings example:

ORPHANED_APPS_MEDIABASE_DIRS = { 
    'myapp': {
        'root': '/var/someuser/private/',
        'exclude': ('.gitignore') 
    }   
}

Crash when having stale content types

Sometypes a db has contenttypes for old models (i.e. models which were deleted or renamed). This apps tries to iterate overmodels going through ContentType objects and calling ct.model_class(), which returns None for stale content types.

That produces the following crash:

Traceback (most recent call last):
  File "./manage.py", line 20, in <module>
    execute_from_command_line()
  File "/home/admin/venv-dev/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/home/admin/venv-dev/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/admin/venv-dev/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)

  File "/home/admin/venv-dev/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/home/admin/venv-dev/local/lib/python2.7/site-packages/django_orphaned/management/commands/deleteorphaned.py", line 32, in handle
    for field in mc._meta.fields:
AttributeError: 'NoneType' object has no attribute '_meta'

Probably this can be fixed by adding a

if mc is None: continue

inside the

for field in mc._meta.fields:

loop

Skipped directories can be deleted because django_orphaned sees the parent as empty

Here's my structure:

media/
media/squarei/
media/squarei/defaults
media/squarei/defaults/example1.png
media/squarei/defaults/example2.png
media/squarei/user_upload.png

My config looks like this

ORPHANED_APPS_MEDIABASE_DIRS = {
    'squarei': {
        'root': MEDIA_ROOT,
        'skip': (
            os.path.join(MEDIA_ROOT, 'squarei/defaults'),
        ),
    }
}

django_orphaned looks at the media/squarei directory and decides it's empty, because no FileFields refer to it. But the skipped directory is in there, and is deleted when django_orphaned deletes media/squarei

TypeError: 'flat' is not valid when values_list is called with more than one field.

$ python manage.py deleteorphaned --info
Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    execute_from_command_line(sys.argv)
  File "/home/foo/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/home/foo/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/foo/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/foo/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/home/foo/local/lib/python2.7/site-packages/django_orphaned/management/commands/deleteorphaned.py", line 38, in handle
    files = mc.objects.all().values_list(*fields,flat=True)
  File "/home/foo/local/lib/python2.7/site-packages/django/db/models/query.py", line 533, in values_list
    raise TypeError("'flat' is not valid when values_list is called with more than one field.")
TypeError: 'flat' is not valid when values_list is called with more than one field.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.