Commits

Georg Brandl committed a4d35a2

Do not overwrite files without -f given.

Comments (0)

Files changed (2)

         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:
             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,
             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)

sphinx/quickstart.py

     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()
     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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.