Skip to content

Commit

Permalink
Added replace or pass on generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuluPro committed May 11, 2016
1 parent 2f7ada3 commit bcf6ffd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion favicon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- Put in a storage backend
- Include HTML tags for use favicon
"""
VERSION = (0, 5, 1)
VERSION = (0, 6, 0)
__version__ = '.'.join([str(i) for i in VERSION])
__author__ = 'Anthony Monthe (ZuluPro)'
__email__ = 'anthony.monthe@gmail.com'
Expand Down
4 changes: 3 additions & 1 deletion favicon/management/commands/generate_favicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def add_arguments(self, parser):
help="Do NOT prompt the user for input of any kind.")
parser.add_argument('--post-process', action='store_true', default=False,
help="Do post process collected files.")
parser.add_argument('--replace', '-r', action='store_true', default=False,
help="Delete file if already existing.")
parser.add_argument('--dry-run', '-n', action='store_true', default=False,
help="Do everything except modify the filesystem.")

Expand Down Expand Up @@ -62,7 +64,7 @@ def handle(self, *args, **options):
if options['dry_run']:
self.stdout.write('No operation launched')
else:
generate(source_file, storage, prefix)
generate(source_file, storage, prefix, options['replace'])

if options['post_process']:
self.stdout.write('Launch post process')
Expand Down
11 changes: 9 additions & 2 deletions favicon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)


def generate(source_file, storage, prefix=None):
def generate(source_file, storage, prefix=None, replace=False):
"""
Creates favicons from a source file and upload into storage.
This also create the ieconfig.xml file.
Expand All @@ -26,12 +26,19 @@ def generate(source_file, storage, prefix=None):
:type storage: :class:`django.core.files.storage.Storage`
:param prefix: Prefix included in new files' names
:type prefix: str
:param replace: Delete file is already existing.
:type replace: bool
"""
prefix = prefix or ''

def write_file(output_file, name):
def write_file(output_file, name, replace=False):
"""Upload to storage."""
name = prefix + name
if storage.exists(name):
if replace:
storage.delete(name)
else:
return
content = File(output_file, name)
storage._save(name, content)
# Save ICO
Expand Down

0 comments on commit bcf6ffd

Please sign in to comment.