Replace .py extension in filename by .ipynb
764021
def replace_py_ipynb(fname):
    """"""
    fname_prefix, extension = os.path.splitext(fname)
    allowed_extension = '.py'
    if extension != allowed_extension:
        raise ValueError(
            "Unrecognized file extension, expected %s, got %s"
            % (allowed_extension, extension))
    new_extension = '.ipynb'
    return '{}{}'.format(fname_prefix, new_extension)
171087
def _py_ftype(parameter, tab):
    
    splice = ', '.join(["{0}_{1:d}".format(parameter.lname, i)
                        for i in range(parameter.D)])       
    return "{2}{0}_ft = Ftype({0}_o, [{1}], libpath)".format(parameter.lname, splice, tab)
930486
def filename(self, prefix='', suffix='', extension='.py'):
        """"""
        return BASE_NAME.format(prefix, self.num, suffix, extension)
68106
def prefix(filename):
    '''  '''
    return os.path.split(re.sub(_afni_suffix_regex,"",str(filename)))[1]
1112318
def punify_filename(filename):
    
    path, extension = splitext(filename)
    return path.encode('punycode').decode('utf8') + extension
576472
def replace_ext(filename, ext):
    
    if ext.startswith('.'):
        ext = ext[1:]
    stem, _ = os.path.splitext(filename)
    return (stem + '.' + ext)
339577
def ext_from_filename(filename):
    
    try:
        base, ext = filename.lower().rsplit(".", 1)
    except ValueError:
        return ''
    ext = ".{0}".format(ext)
    all_exts = [x.extension for x in chain(magic_header_array,
                                           magic_footer_array)]

    if base[-4:].startswith("."):
        # For double extensions like like .tar.gz
        long_ext = base[-4:] + ext
        if long_ext in all_exts:
            return long_ext
    return ext
601617
def modify_filename_id(filename):
    """"""
    split_filename = os.path.splitext(filename)
    id_num_re = re.compile('(\(\d\))')
    id_num = re.findall(id_num_re, split_filename[-2])
    if id_num:
        new_id_num = int(id_num[-1].lstrip('(').rstrip(')')) + 1

        # Reconstruct filename with incremented id and its extension
        filename = ''.join((re.sub(id_num_re, '({0})'.format(new_id_num),
                                   split_filename[-2]), split_filename[-1]))
    else:
        split_filename = os.path.splitext(filename)

        # Reconstruct filename with new id and its extension
        filename = ''.join(('{0} (2)'.format(split_filename[-2]),
                            split_filename[-1]))
    return filename
669837
def load_ipython_extension(ip, **kwargs):
    """"""
    global _loaded
    if not _loaded:
        ip.register_magics(MatlabMagics(ip, **kwargs))
        _loaded = True
947750
def libname_from_dir(dirname):
    """"""
    parts = []
    for part in dirname.split('-'):
        if part[0].isdigit():
            break
        parts.append(part)
    return '-'.join(parts)
94110
def filename(out_dir, name, undefine=False):
    """"""
    if undefine:
        prefix = 'undef_'
    else:
        prefix = ''
    return os.path.join(out_dir, '{0}{1}.hpp'.format(prefix, name.lower()))
59383
def file_extension(path):
    
    if path is None:
        return None
    ext = os.path.splitext(os.path.basename(path))[1]
    if ext.startswith("."):
        ext = ext[1:]
    return ext
572799
def extend_path(pth, name):
  '''
  
  '''

  def zip_isfile(z, name):
    name.rstrip('/')
    return name in z.namelist()

  pname = os.path.join(*name.split('.'))
  zname = '/'.join(name.split('.'))
  init_py = '__init__' + os.extsep + 'py'
  init_pyc = '__init__' + os.extsep + 'pyc'
  init_pyo = '__init__' + os.extsep + 'pyo'

  mod_path = list(pth)
  for path in sys.path:
    if zipfile.is_zipfile(path):
      try:
        egg = zipfile.ZipFile(path, 'r')
        addpath = (
          zip_isfile(egg, zname + '/__init__.py') or
          zip_isfile(egg, zname + '/__init__.pyc') or
          zip_isfile(egg, zname + '/__init__.pyo'))
        fpath = os.path.join(path, path, zname)
        if addpath and fpath not in mod_path:
          mod_path.append(fpath)
      except (zipfile.BadZipfile, zipfile.LargeZipFile):
        pass  # xxx: Show a warning at least?
    else:
      path = os.path.join(path, pname)
      if os.path.isdir(path) and path not in mod_path:
        addpath = (
          os.path.isfile(os.path.join(path, init_py)) or
          os.path.isfile(os.path.join(path, init_pyc)) or
          os.path.isfile(os.path.join(path, init_pyo)))
        if addpath and path not in mod_path:
          mod_path.append(path)

  return [os.path.normpath(x) for x in mod_path]
571586
def template_from_filename(filename):
    """"""
    ext = filename.split(os.path.extsep)[-1]
    if not ext in TEMPLATES_MAP:
        raise ValueError("No template for file extension {}".format(ext))
    return TEMPLATES_MAP[ext]
166623
def lower_extension(filename):
    '''
    
    '''
    if '.' in filename:
        main, ext = os.path.splitext(filename)
        return main + ext.lower()
    # For consistency with os.path.splitext,
    # do not treat a filename without an extension as an extension.
    # That is, do not return filename.lower().
    return filename
733465
def file_basename(self, file):
        '''
        
        '''
        valid_extensions = set(".tree",
                               ".tre")
        split_file = os.path.basename(file).split('.')
        base, suffix = '.'.join(split_file[:-1]), split_file[-1]

        if suffix in valid_extensions:
            return base
        else:
            logging.error("Invalid file extension found on file: %s" % file)
            logging.error("For trees, please provide a file with one of the \
following extensions: %s" % ' '.join(valid_extensions.keys()))
            raise InvalidFileExtensionError
370141
def change_filename(filehandle, meta):
    
    filename = secure_filename(meta.get('filename', filehandle.filename))
    basename, _ = os.path.splitext(filename)
    meta['original_filename'] = filehandle.filename
    filehandle.filename = filename + '.jpg'
    return filehandle