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.')
|
parser.error('An output directory is required.')
|
||||||
if opts.header is None:
|
if opts.header is None:
|
||||||
opts.header = rootpath
|
opts.header = rootpath
|
||||||
|
if opts.suffix.startswith('.'):
|
||||||
|
opts.suffix = opts.suffix[1:]
|
||||||
if not path.isdir(rootpath):
|
if not path.isdir(rootpath):
|
||||||
print >>sys.stderr, '%s is not a directory.' % rootpath
|
print >>sys.stderr, '%s is not a directory.' % rootpath
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if not path.isdir(opts.destdir):
|
if not path.isdir(opts.destdir):
|
||||||
os.makedirs(opts.destdir)
|
if not opts.dryrun:
|
||||||
|
os.makedirs(opts.destdir)
|
||||||
excludes = normalize_excludes(rootpath, excludes)
|
excludes = normalize_excludes(rootpath, excludes)
|
||||||
modules = recurse_tree(rootpath, excludes, opts)
|
modules = recurse_tree(rootpath, excludes, opts)
|
||||||
if opts.full:
|
if opts.full:
|
||||||
@ -295,7 +298,7 @@ Note: By default this script will not overwrite already created files.""")
|
|||||||
version = opts.version or '',
|
version = opts.version or '',
|
||||||
release = opts.release or opts.version or '',
|
release = opts.release or opts.version or '',
|
||||||
suffix = '.' + opts.suffix,
|
suffix = '.' + opts.suffix,
|
||||||
master = 'modules',
|
master = 'index',
|
||||||
epub = True,
|
epub = True,
|
||||||
ext_autodoc = True,
|
ext_autodoc = True,
|
||||||
makefile = True,
|
makefile = True,
|
||||||
@ -303,9 +306,7 @@ Note: By default this script will not overwrite already created files.""")
|
|||||||
mastertocmaxdepth = opts.maxdepth,
|
mastertocmaxdepth = opts.maxdepth,
|
||||||
mastertoctree = text,
|
mastertoctree = text,
|
||||||
)
|
)
|
||||||
# XXX overwrites even without --force
|
|
||||||
if not opts.dryrun:
|
if not opts.dryrun:
|
||||||
qs.generate(d, silent=True)
|
qs.generate(d, silent=True, overwrite=opts.force)
|
||||||
print 'Creating quickstart project and Makefile.'
|
|
||||||
elif not opts.notoc:
|
elif not opts.notoc:
|
||||||
create_modules_toc_file(modules, opts)
|
create_modules_toc_file(modules, opts)
|
||||||
|
@ -946,9 +946,10 @@ directly.'''
|
|||||||
if 'batchfile' not in d:
|
if 'batchfile' not in d:
|
||||||
do_prompt(d, 'batchfile', 'Create Windows command file? (Y/n)',
|
do_prompt(d, 'batchfile', 'Create Windows command file? (Y/n)',
|
||||||
'y', boolean)
|
'y', boolean)
|
||||||
|
print
|
||||||
|
|
||||||
|
|
||||||
def generate(d, silent=False):
|
def generate(d, overwrite=True, silent=False):
|
||||||
"""Generate project based on values in *d*."""
|
"""Generate project based on values in *d*."""
|
||||||
|
|
||||||
texescape.init()
|
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'] + 'templates'))
|
||||||
mkdir_p(path.join(srcdir, d['dot'] + 'static'))
|
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
|
conf_text = QUICKSTART_CONF % d
|
||||||
if d['epub']:
|
if d['epub']:
|
||||||
conf_text += EPUB_CONFIG % d
|
conf_text += EPUB_CONFIG % d
|
||||||
if d.get('ext_intersphinx'):
|
if d.get('ext_intersphinx'):
|
||||||
conf_text += INTERSPHINX_CONFIG
|
conf_text += INTERSPHINX_CONFIG
|
||||||
|
|
||||||
f = open(path.join(srcdir, 'conf.py'), 'w', encoding='utf-8')
|
write_file(path.join(srcdir, 'conf.py'), 'w', conf_text)
|
||||||
f.write(conf_text)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
masterfile = path.join(srcdir, d['master'] + d['suffix'])
|
masterfile = path.join(srcdir, d['master'] + d['suffix'])
|
||||||
f = open(masterfile, 'w', encoding='utf-8')
|
write_file(masterfile, 'w', MASTER_FILE % d)
|
||||||
f.write(MASTER_FILE % d)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
if d['makefile']:
|
if d['makefile']:
|
||||||
d['rsrcdir'] = d['sep'] and 'source' or '.'
|
d['rsrcdir'] = d['sep'] and 'source' or '.'
|
||||||
d['rbuilddir'] = d['sep'] and 'build' or d['dot'] + 'build'
|
d['rbuilddir'] = d['sep'] and 'build' or d['dot'] + 'build'
|
||||||
# use binary mode, to avoid writing \r\n on Windows
|
# use binary mode, to avoid writing \r\n on Windows
|
||||||
f = open(path.join(d['path'], 'Makefile'), 'wb', encoding='utf-8')
|
write_file(path.join(d['path'], 'Makefile'), 'wb', MAKEFILE % d)
|
||||||
f.write(MAKEFILE % d)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
if d['batchfile']:
|
if d['batchfile']:
|
||||||
d['rsrcdir'] = d['sep'] and 'source' or '.'
|
d['rsrcdir'] = d['sep'] and 'source' or '.'
|
||||||
d['rbuilddir'] = d['sep'] and 'build' or d['dot'] + 'build'
|
d['rbuilddir'] = d['sep'] and 'build' or d['dot'] + 'build'
|
||||||
f = open(path.join(d['path'], 'make.bat'), 'w', encoding='utf-8')
|
write_file(path.join(d['path'], 'make.bat'), 'w', BATCHFILE % d)
|
||||||
f.write(BATCHFILE % d)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
if silent:
|
if silent:
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user