mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Do not overwrite files without -f given.
This commit is contained in:
parent
ff940a16b6
commit
853cfbf7b6
@ -269,11 +269,14 @@ Note: By default this script will not overwrite already created files.""")
|
||||
parser.error('An output directory is required.')
|
||||
if opts.header is None:
|
||||
opts.header = rootpath
|
||||
if opts.suffix.startswith('.'):
|
||||
opts.suffix = opts.suffix[1:]
|
||||
if not path.isdir(rootpath):
|
||||
print >>sys.stderr, '%s is not a directory.' % rootpath
|
||||
sys.exit(1)
|
||||
if not path.isdir(opts.destdir):
|
||||
os.makedirs(opts.destdir)
|
||||
if not opts.dryrun:
|
||||
os.makedirs(opts.destdir)
|
||||
excludes = normalize_excludes(rootpath, excludes)
|
||||
modules = recurse_tree(rootpath, excludes, opts)
|
||||
if opts.full:
|
||||
@ -295,7 +298,7 @@ Note: By default this script will not overwrite already created files.""")
|
||||
version = opts.version or '',
|
||||
release = opts.release or opts.version or '',
|
||||
suffix = '.' + opts.suffix,
|
||||
master = 'modules',
|
||||
master = 'index',
|
||||
epub = True,
|
||||
ext_autodoc = True,
|
||||
makefile = True,
|
||||
@ -303,9 +306,7 @@ Note: By default this script will not overwrite already created files.""")
|
||||
mastertocmaxdepth = opts.maxdepth,
|
||||
mastertoctree = text,
|
||||
)
|
||||
# XXX overwrites even without --force
|
||||
if not opts.dryrun:
|
||||
qs.generate(d, silent=True)
|
||||
print 'Creating quickstart project and Makefile.'
|
||||
qs.generate(d, silent=True, overwrite=opts.force)
|
||||
elif not opts.notoc:
|
||||
create_modules_toc_file(modules, opts)
|
||||
|
@ -946,9 +946,10 @@ directly.'''
|
||||
if 'batchfile' not in d:
|
||||
do_prompt(d, 'batchfile', 'Create Windows command file? (Y/n)',
|
||||
'y', boolean)
|
||||
print
|
||||
|
||||
|
||||
def generate(d, silent=False):
|
||||
def generate(d, overwrite=True, silent=False):
|
||||
"""Generate project based on values in *d*."""
|
||||
|
||||
texescape.init()
|
||||
@ -997,35 +998,38 @@ def generate(d, silent=False):
|
||||
mkdir_p(path.join(srcdir, d['dot'] + 'templates'))
|
||||
mkdir_p(path.join(srcdir, d['dot'] + 'static'))
|
||||
|
||||
def write_file(fpath, mode, content):
|
||||
if overwrite or not path.isfile(fpath):
|
||||
print 'Creating file %s.' % fpath
|
||||
f = open(fpath, mode, encoding='utf-8')
|
||||
try:
|
||||
f.write(content)
|
||||
finally:
|
||||
f.close()
|
||||
else:
|
||||
print 'File %s already exists, skipping.' % fpath
|
||||
|
||||
conf_text = QUICKSTART_CONF % d
|
||||
if d['epub']:
|
||||
conf_text += EPUB_CONFIG % d
|
||||
if d.get('ext_intersphinx'):
|
||||
conf_text += INTERSPHINX_CONFIG
|
||||
|
||||
f = open(path.join(srcdir, 'conf.py'), 'w', encoding='utf-8')
|
||||
f.write(conf_text)
|
||||
f.close()
|
||||
write_file(path.join(srcdir, 'conf.py'), 'w', conf_text)
|
||||
|
||||
masterfile = path.join(srcdir, d['master'] + d['suffix'])
|
||||
f = open(masterfile, 'w', encoding='utf-8')
|
||||
f.write(MASTER_FILE % d)
|
||||
f.close()
|
||||
write_file(masterfile, 'w', MASTER_FILE % d)
|
||||
|
||||
if d['makefile']:
|
||||
d['rsrcdir'] = d['sep'] and 'source' or '.'
|
||||
d['rbuilddir'] = d['sep'] and 'build' or d['dot'] + 'build'
|
||||
# use binary mode, to avoid writing \r\n on Windows
|
||||
f = open(path.join(d['path'], 'Makefile'), 'wb', encoding='utf-8')
|
||||
f.write(MAKEFILE % d)
|
||||
f.close()
|
||||
write_file(path.join(d['path'], 'Makefile'), 'wb', MAKEFILE % d)
|
||||
|
||||
if d['batchfile']:
|
||||
d['rsrcdir'] = d['sep'] and 'source' or '.'
|
||||
d['rbuilddir'] = d['sep'] and 'build' or d['dot'] + 'build'
|
||||
f = open(path.join(d['path'], 'make.bat'), 'w', encoding='utf-8')
|
||||
f.write(BATCHFILE % d)
|
||||
f.close()
|
||||
write_file(path.join(d['path'], 'make.bat'), 'w', BATCHFILE % d)
|
||||
|
||||
if silent:
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user