replaces the suffix on a filename or list of filenames
    example: replace_suffix("/path/to/test.sam", ".bam") ->
    "/path/to/test.bam"
510015
def replace_suffix(to_transform, suffix):
    
    if is_sequence(to_transform):
        transformed = []
        for f in to_transform:
            (base, _) = os.path.splitext(f)
            transformed.append(base + suffix)
        return transformed
    elif is_string(to_transform):
        (base, _) = os.path.splitext(to_transform)
        return base + suffix
    else:
        raise ValueError("replace_suffix takes a single filename as a string or "
                         "a list of filenames to transform.")
1314250
def sharded_filenames(filename_prefix, num_shards):
  """"""
  shard_suffix = "%05d-of-%05d"
  return [
      "%s-%s" % (filename_prefix, shard_suffix % (i, num_shards))
      for i in range(num_shards)
  ]
323282
def __filename(self, id):
        """"""
        suffix = self.fnsuffix()
        filename = "%s-%s.%s" % (self.fnprefix, id, suffix)
        return os.path.join(self.location, filename)
856631
function replaceFilenameTokens(pattern, next) {
        if (pattern.match(/%[bf]/)) {
          if (typeof source !== 'string') {
            return next(new Error('Cannot replace %f or %b when using an input stream'));
          }

          pattern = pattern
            .replace(/%f/g, path.basename(source))
            .replace(/%b/g, path.basename(source, path.extname(source)));
        }

        next(null, pattern);
      }
930486
def filename(self, prefix='', suffix='', extension='.py'):
        """"""
        return BASE_NAME.format(prefix, self.num, suffix, extension)
897352
def replace_types(strings, suffix=':')
      if configuration[:solr_fields]
        configuration[:solr_fields].each do |name, options|
          solr_name = (options[:as] || name).to_s
          solr_type = get_solr_field_type(options[:type])
          field = "#{solr_name}_#{solr_type}#{suffix}"
          strings.each_with_index {|s,i| strings[i] = s.gsub(/\b#{solr_name}\b#{suffix}/,field) }
        end
      end
      if configuration[:solr_includes]
        configuration[:solr_includes].each do |association, options|
          solr_name = options[:as] || association.to_s.singularize
          solr_type = get_solr_field_type(options[:type])
          field = "#{solr_name}_#{solr_type}#{suffix}"
          strings.each_with_index {|s,i| strings[i] = s.gsub(/\b#{solr_name}\b#{suffix}/,field) }
        end
      end
      strings
    end
1030202
def greedy_replace(self, seq):
        '''
        
        '''
        if not self._suffix_links_set:
            self._set_suffix_links()
        # start at the root
        current = self.root
        buffered = ''
        outstr = ''
        for char in seq:
            while char not in current:
                if current.has_dict_suffix:
                    current = current.dict_suffix
                    outstr += buffered[:-current.depth]
                    outstr += current.value
                    buffered = ''
                    current = self.root
                    break
                elif current.has_suffix:
                    current = current.suffix
                    if current.depth:
                        outstr += buffered[:-current.depth]
                        buffered = buffered[-current.depth:]
                    else:
                        outstr += buffered
                        buffered = ''
                        break
                else:
                    current = self.root
                    outstr += buffered
                    buffered = ''
                    break
            if char in current:
                buffered += char
                current = current[char]
                if current.has_value:
                    outstr += buffered[:-current.depth]
                    outstr += current.value
                    buffered = ''
                    current = self.root
            else:
                assert current is self.root
                outstr += buffered + char
                buffered = ''
        if current.has_dict_suffix:
            current = current.dict_suffix
            outstr += buffered[:-current.depth]
            outstr += current.value
        else:
            outstr += buffered
        return outstr
1213948
def get_hashed_filename(name, file, suffix=None):
    
    basename, hash, ext = split_filename(name)
    file.seek(0)
    new_hash = '.%s' % md5(file.read()).hexdigest()[:12]
    if suffix is not None:
        basename = '%s_%s' % (basename, suffix)
    return '%s%s%s' % (basename, new_hash, ext)
349599
def archive_basename(filename):
    ''''''
    for archive in archive_formats:
        if filename.endswith(archive_formats[archive]['suffix']):
            return filename.rstrip('.' + archive_formats[archive]['suffix'])
    return False
727649
def _module_name(filename):
        

        absfile = os.path.abspath(filename)
        match = filename

        for base in [''] + sys.path:
            base = os.path.abspath(base)
            if absfile.startswith(base):
                match = absfile[len(base):]
                break

        return SUFFIX_RE.sub('', match).lstrip('/').replace('/', '.')
1357334
def setup_prefix_suffix(self):
        

        self.compile_prefix = 'compile_'
        self.sourcepath_suffix = '_sourcepath'
        self.modpath_suffix = '_modpaths'
        self.targetpath_suffix = '_targetpaths'
1289459
def filename_fix_existing(filename, dirname):
    
    name, ext = filename.rsplit('.', 1)
    names = [x for x in os.listdir(dirname) if x.startswith(name)]
    names = [x.rsplit('.', 1)[0] for x in names]
    suffixes = [x.replace(name, '') for x in names]
    # filter suffixes that match ' (x)' pattern
    suffixes = [x[2:-1] for x in suffixes
                if x.startswith(' (') and x.endswith(')')]
    indexes = [int(x) for x in suffixes
               if set(x) <= set('0123456789')]
    idx = 1
    if indexes:
        idx += sorted(indexes)[-1]
    return '{0}({1}).{2}'.format(name, idx, ext)
98844
def get_file_suffix(self, path, prefix):
        
        try:
            number_of_files = len(glob.glob(os.path.join(path, prefix) + '*'))
        except:
            number_of_files = 0
        return '{0:04}'.format(number_of_files)
246763
def _get_suffix(path):
    
    suffix = os.path.basename(path).split(".")[-1]

    if "/" in suffix:
        raise UserWarning("Filename can't contain '/' in suffix (%s)!" % path)

    return suffix
1268577
def _expand_filename(self, line):
        """"""
        # expand .
        newline = line
        path = os.getcwd()
        if newline.startswith("."):
            newline = newline.replace(".", path, 1)
        # expand ~
        newline = os.path.expanduser(newline)
        return newline
1334889
def buildNewRootname(filename, extn=None, extlist=None):
    

    # Search known suffixes to replace ('_crj.fits',...)
    _extlist = copy.deepcopy(EXTLIST)
    # Also, add a default where '_dth.fits' replaces
    # whatever extension was there ('.fits','.c1h',...)
    #_extlist.append('.')
    # Also append any user-specified extensions...
    if extlist:
        _extlist += extlist

    if isinstance(filename, fits.HDUList):
        try:
            filename = filename.filename()
        except:
            raise ValueError("Can't determine the filename of an waivered HDUList object.")
    for suffix in _extlist:
        _indx = filename.find(suffix)
        if _indx > 0: break

    if _indx < 0:
         # default to entire rootname
        _indx = len(filename)

    if extn is None:
        extn = ''

    return filename[:_indx] + extn
1095629
def _remove_compression_suffix_if_present(self, filename):
        
        for ext in [".gz", ".gzip", ".zip"]:
            if filename.endswith(ext):
                return filename[:-len(ext)]
        return filename