1"""Collection of utilities for command-line interfaces and console scripts.""" 2from __future__ import print_function, division, absolute_import 3from fontTools.misc.py23 import * 4import os 5import re 6 7 8numberAddedRE = re.compile("#\d+$") 9 10 11def makeOutputFileName(input, outputDir=None, extension=None, overWrite=False): 12 dirName, fileName = os.path.split(input) 13 fileName, ext = os.path.splitext(fileName) 14 if outputDir: 15 dirName = outputDir 16 fileName = numberAddedRE.split(fileName)[0] 17 if extension is None: 18 extension = os.path.splitext(input)[1] 19 output = os.path.join(dirName, fileName + extension) 20 n = 1 21 if not overWrite: 22 while os.path.exists(output): 23 output = os.path.join( 24 dirName, fileName + "#" + repr(n) + extension) 25 n += 1 26 return output 27