toolsutils.py
changeset 2615 1ea41b7c0836
parent 2476 1294a6bdf3bf
child 2790 968108e16066
child 3115 29262ba01464
equal deleted inserted replaced
2614:351f1fcfa53c 2615:1ea41b7c0836
    14 from os.path import exists, join, abspath, normpath
    14 from os.path import exists, join, abspath, normpath
    15 
    15 
    16 from logilab.common.clcommands import Command as BaseCommand, \
    16 from logilab.common.clcommands import Command as BaseCommand, \
    17      main_run as base_main_run
    17      main_run as base_main_run
    18 from logilab.common.compat import any
    18 from logilab.common.compat import any
    19 from logilab.common.shellutils import confirm
    19 from logilab.common.shellutils import ASK
    20 
    20 
    21 from cubicweb import warning
    21 from cubicweb import warning
    22 from cubicweb import ConfigurationError, ExecutionError
    22 from cubicweb import ConfigurationError, ExecutionError
    23 
    23 
    24 def iter_dir(directory, condition_file=None, ignore=()):
    24 def iter_dir(directory, condition_file=None, ignore=()):
    70     diffs = p_output.read()
    70     diffs = p_output.read()
    71     if diffs:
    71     if diffs:
    72         if askconfirm:
    72         if askconfirm:
    73             print
    73             print
    74             print diffs
    74             print diffs
    75             action = raw_input('replace (N/y/q) ? ').lower()
    75             action = ASK.ask('Replace ?', ('N','y','q'), 'N')
    76         else:
    76         else:
    77             action = 'y'
    77             action = 'y'
    78         if action == 'y':
    78         if action == 'y':
    79             try:
    79             try:
    80                 shutil.copyfile(ref_file, appl_file)
    80                 shutil.copyfile(ref_file, appl_file)
   115             else:
   115             else:
   116                 tfpath = join(tdirpath, fname)
   116                 tfpath = join(tdirpath, fname)
   117             if fname.endswith('.tmpl'):
   117             if fname.endswith('.tmpl'):
   118                 tfpath = tfpath[:-5]
   118                 tfpath = tfpath[:-5]
   119                 if not askconfirm or not exists(tfpath) or \
   119                 if not askconfirm or not exists(tfpath) or \
   120                        confirm('%s exists, overwrite?' % tfpath):
   120                        ASK.confirm('%s exists, overwrite?' % tfpath):
   121                     fill_templated_file(fpath, tfpath, context)
   121                     fill_templated_file(fpath, tfpath, context)
   122                     print '[generate] %s <-- %s' % (tfpath, fpath)
   122                     print '[generate] %s <-- %s' % (tfpath, fpath)
   123             elif exists(tfpath):
   123             elif exists(tfpath):
   124                 show_diffs(tfpath, fpath, askconfirm)
   124                 show_diffs(tfpath, fpath, askconfirm)
   125             else:
   125             else: