[cwctl] do only clean static data dir content (closes #17069762)

deleting the directory itself is useless and may be a problem in automated deployment environments (user may not have permissions to delete or create that directory).

authorDavid Douard <david.douard@logilab.fr>
changeset7c7d58cc5c1f
branch3.24
phasedraft
hiddenno
parent revision#e3779004e987 [cwctl] upgrade: do delete the static data dir if verbosity is 0 (closes #17069749)
child revision#0669e8661439 [rqlrewrite/schema] Avoid parsing computed relations for each query
files modified by this revision
cubicweb/web/webctl.py
# HG changeset patch
# User David Douard <david.douard@logilab.fr>
# Date 1491298883 -7200
# Tue Apr 04 11:41:23 2017 +0200
# Branch 3.24
# Node ID 7c7d58cc5c1f2f18eac46f37c6f831a1d0d33162
# Parent e3779004e987e9b9d8cd5e8b6f45de30280eeeab
[cwctl] do only clean static data dir content (closes #17069762)

deleting the directory itself is useless and may be a problem in automated
deployment environments (user may not have permissions to delete or create
that directory).

diff --git a/cubicweb/web/webctl.py b/cubicweb/web/webctl.py
@@ -37,10 +37,21 @@
1      from os import symlink as linkdir
2  except ImportError:
3      from shutil import copytree as linkdir
4 
5 
6 +def rmtreecontent(dst):
7 +    """Delete the content of the dst directory (but NOT the directory
8 +       itself)"""
9 +    for fname in os.listdir(dst):
10 +        fpath = osp.join(dst, fname)
11 +        if osp.isfile(fpath) or osp.islink(fpath):
12 +            os.unlink(fpath)
13 +        else:
14 +            rmtree(fpath)
15 +
16 +
17  class WebCreateHandler(CommandHandler):
18      cmdname = 'create'
19 
20      def bootstrap(self, cubes, automatic=False, inputlevel=0):
21          """bootstrap this configuration"""
@@ -68,11 +79,11 @@
22              if config.verbosity and (not ask_clean or
23                  not (config.verbosity and
24                       ASK.confirm('Remove existing data directory %s?' % dest))):
25                  raise ExecutionError('Directory %s already exists. '
26                                       'Remove it first.' % dest)
27 -            rmtree(dest)
28 +            rmtreecontent(dest)
29          config.quick_start = True # notify this is not a regular start
30          # list all resources (no matter their order)
31          resources = set()
32          for datadir in self._datadirs(config, repo=repo):
33              for dirpath, dirnames, filenames in os.walk(datadir):