From 56c4701737dc3d554604d5f1b2c976bd1cf613c5 Mon Sep 17 00:00:00 2001 From: leidel Date: Tue, 2 Sep 2008 13:21:46 +0000 Subject: [PATCH] actually implemented the --force option of sync_templates command, thanks Martin Mahner git-svn-id: https://django-dbtemplates.googlecode.com/svn/trunk@49 cfb8ba98-e953-0410-9cff-959ffddf5974 committer: leidel --HG-- extra : convert_revision : 249d1af3375b0be74f37e5190475733898545ef5 --- .../management/commands/sync_templates.py | 21 ++++++++++--------- setup.py | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/dbtemplates/management/commands/sync_templates.py b/dbtemplates/management/commands/sync_templates.py index 66deafb..09f6f0e 100644 --- a/dbtemplates/management/commands/sync_templates.py +++ b/dbtemplates/management/commands/sync_templates.py @@ -21,10 +21,10 @@ class Command(NoArgsCommand): def handle_noargs(self, **options): extension = options.get('ext') force = options.get('force') - + if not extension.startswith("."): extension = ".%s" % extension - + try: site = Site.objects.get_current() except: @@ -38,23 +38,24 @@ class Command(NoArgsCommand): raise CommandError("Please make sure settings.TEMPLATE_DIRS is a " "list or tuple.") - templatedirs = [d for d in + templatedirs = [d for d in settings.TEMPLATE_DIRS + app_template_dirs if os.path.isdir(d)] for templatedir in templatedirs: for dirpath, subdirs, filenames in os.walk(templatedir): - for f in [f for f in filenames if f.endswith(extension) + for f in [f for f in filenames if f.endswith(extension) and not f.startswith(".")]: path = os.path.join(dirpath, f) name = path.split(templatedir)[1][1:] try: t = Template.objects.get(name__exact=name) except Template.DoesNotExist: - confirm = raw_input( - "\nA '%s' template doesn't exist in the database.\n" - "Create it with '%s'?" - " (y/[n]): """ % (name, path)) - if confirm.lower().startswith('y'): + if force == False: + confirm = raw_input( + "\nA '%s' template doesn't exist in the database.\n" + "Create it with '%s'?" + " (y/[n]): """ % (name, path)) + if confirm.lower().startswith('y') or force: t = Template(name=name, content=open(path, "r").read()) t.save() @@ -66,7 +67,7 @@ class Command(NoArgsCommand): "(1) Overwrite %s with '%s'\n" "(2) Overwrite '%s' with %s\n" "Type 1 or 2 or press to skip: " - % (t.__repr__(), + % (t.__repr__(), t.__repr__(), path, path, t.__repr__())) if confirm == '' or confirm in ('1', '2'): diff --git a/setup.py b/setup.py index 65c4f29..8631b04 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from distutils.core import setup setup( name='dbtemplates', - version='0.4.4', + version='0.4.5', description='Template loader for database stored templates', author='Jannis Leidel', author_email='jannis@leidel.info',